| programming the
LilyPad Arduino: sensing (sensors) |
|||
|
1. If you haven't yet, make a coaster for your LilyPad and light sensor. See this tutorial for instructions. This will prevent the alligator clips that we'll be using from sliding around on the LilyPad. Trust me, it's worth it to do this! 2. Use alligator clips to attach the light sensor module to the LilyPad Attach the + petal of the light sensor module to the +5V on the LilyPad, the - petal to - on the LilyPad, and the S petal to a0 on the LilyPad like this:
3. Attach the LilyPad to your computer and start the Arduino software 4. Copy this sample code into an Arduino window Click here for sensor sample code. Copy and paste this code into an empty Arduino window. 5. Format the code Under the Tools menu, select Auto Format. After you do this, align all of your comments (the statements in grey-brown following "//" on each line) so that they are in readable columns on the right hand side of the screen. This will help you read through the code. Here's what my Arduino window looked like after I formatted everything:
6. Load the code onto the LilyPad Compile the code and load it onto the LilyPad. Do this by hitting the upload button in the Arduino window (that's the right pointing arrow at the top of the Arduino window) and then quickly pressing the reset switch on the LilyPad. If you're new to this process, or if you have any problems uploading, see the previous LilyPad tutorial: 4. light (LEDs). 7. Open the Arduino Serial Moniter to see your sensor data Click on the icon at the top right of the Arduino window. When you move your mouse over this icon, you will see text saying "Serial Monitor" at the top of the window:
As soon as the light on the LilyPad comes on, you should start seeing sensor data appear in the bottom half of the Arduino window. Here's what my window looks like. ![]() If your numbers aren't changing in response to light changes, check your alligator clip connections. 8. Play with modifying the code to get different behavior
|
|||