Arduino‎ > ‎

First Project

Now that we know that the Arduino is working, we can start to play with it.

Hardware required
  • Arduino
  • Extender shield (I prefer the double tall)
    • with breadboards stuck to it.
  • 10k resistor  (BROWN, BLACK, ORANGE)
  • A photoresistor . I got mine from Radio Shack (5 pack 276-1657, $2.99)
  • A few jumper wires

As I wrote in the main page, you really should have a breadboard for prototyping. I have the Liquidware doubletall extender shield with three small bread boards stuck to it. In this photo I have some circuits installed, but you can see the breadboards on the shield.

The shield needs to be placed on the Arduino and it can only go on one way, so its super easy. Just line up the pins and gently press them together. In these two photos you can see the pins lined up, and the extender installed. Ignore all the wires on my breadboard. :)

Now we will wire up a photocell to measure the ambient light, for this project I find a flashlight to be pretty useful. :)
We will wire up this circuit on our bread board.

Look at your combined Arduino/double tall shield, with the USB port facing you, the pins on the left, farthest away from you are the power pins, next are the analog I/O pins, then the digital I/O pins. The pins on the right or identical, BUT reversed top to bottom. The breadboard has a series of holes in it with a trench down the middle. The holes are connected horizontally on each side of the trench, but NOT across the trench. So if you set your multimeter to check continuity, and put the probes on two holes next to each other, you would register a connection, lets call that a "row". With that in mind, we begin...
  1. Plug a RED jumper wire into the header labeled "5V", that is the third one down on the left (or third up from the bottom on the right).
  2. Plug the other end of the red jumper into a row of your bread bread, like so:

  3. Plug on. end of your resistor (either end) into a hole in the same row as the red wire.
  4. Plug the other end of the resistor into a hole a few rows away, like so:

  5. In the same row that you plugged the second end of the resistor into, we are going to plug in TWO things:
    1. A GREEN jumper wire to ADC 5
    2. One end of the photoresistor
  6. The other end of the photoresistor goes to a hole in the row opposite the trench.
  7. Plug a YELLOW wire into the same row as the second end of the photoresistor and the other end into the G (Ground) terminal, it is directly under the 5v terminal.
SO, your bread board/shield extender should look something like this:

The photo shows the green line plugged into ADC 0, sorry. It should be 5 down (to the left in the photo) in ADC5.

See the wire, resistor and LED on the left? Ignore them, they are for a different project. :)

Now plug your Arduino into the USB port on your computer and fire up the Arduino IDE. In the IDE set you baud rate to 57600, the setting is a drop down above the serial monitor.
Paste the following code into the Arduino IDE.

Arduino Code

 * reads photoresistor
 * sends value to serial monitor
int photoPin = 5; // this is the analog pin that the photoresistor is attached to.
int intensity = 0; // this variable will hold the value from the photoresistor
void setup()                
  Serial.println("Starting photoresistor tutorial...");

void loop()                     // run over and over again
 intensity = analogRead(photoPin); // read ADC 5 value
 Serial.println(intensity);        // print the ADC value to the console
 delay(2000);                      // pause 2 seconds

Click the "Upload to I/O Board" button to compile the code and upload it to the Arduino. The compile and upload will take several seconds. When its done, click the button to the the far right of the toolbar, "Serial Monitor". The console should say
"Starting photoresistor tutorial..."
and then start streaming lines of numbers in the range of 0 - 1024, 0 being the brightest and 1024 the darkest. Does that seem backwards? It does to me, so to reverse (or correct) the mapping (0 is darkest, 1024 is brightest) swap the resistor and the photocell. Turn lights on and off, shine the flashlight on the photoresistor and you will see the numbers change.

In this configuration we are using a voltage divider to measure the voltage. As we get more light on photoresistor, its resistance increases, so the measured voltage goes DOWN (or up, depending on if you swapped the photoresistor and the resistor)

It doesn't work!
Well, check all your connections, compare them to the photo. If you did a copy and paste of the code, then the problem almost certainly has to be in the wiring.