Checkpoint 3:  Read someone else’s blinking light.

Goals: 

·        Learn how to use an Arduino to collect data from a sensor

 

In this Checkpoint we are going to use the Arduino to detect the intensity of light landing upon a light sensor.

 

First, disconnect your Arduino from the power source and/or the computer and take out any components that you put in during Checkpoint 2.

 

Next, re-create the circuit shown in the drawing.  A2 can be found in the “Analog” input pins found on the Arduino board.

 

After you have made the circuit, type in the below program and upload the program to the Arduino.

 

//* This program will collected data from a light sensor that is plugged into the Arduino board

 

int LS = 2;       // define LS as the variable that will tell the program from which pin to gather data

int LSvalue = 0;       // LSvalue will be the variable used to store the value coming from the sensor

 

void setup() {

// open serial port.

Serial.begin(9600);

pinMode(LS, INPUT);       // let the computer know that pin LS will be an INPUT pin

}

 

void loop() {

  LSvalue = analogRead(LS);       // set LSvalue equal to the value from the sensor plugged into pin LS.

  Serial.println(LSvalue);        // this will print the value of 'LSvalue' to the Serial Monitor

  delay(30);  // this slows things down a bit

}

 

When you run the program you will need to go to “Tools” and select “Serial Monitor” to see the data being sent to your computer via the Arduino

 

1. When you have uploaded the program to your Arduino, you should then try blocking light to the light sensor and then shine bright light at it and observe what happens.

2.  Try using the light sensor to detect light coming from someone else’s Arduino that is running the Blink program.

3.  Some physics:  Replace the light sensor with an LED.  Try detecting someone else’s LED using the same color LED as you – you might need to take note of the direction in which you have your LED-as-sensor plugged in vs. your LED-as-light.  After you get your LED-as-sensor working with the same color LED, try detecting a different color of LED.

4.  If time permits, explore the map function.  With a bright enough light, you should be able to get the serial output to read values as high as 1,023.  Such a bright light, however, might not be possible without setting the lab on fire.  In your Arduino program you can use the map function to scale the output of your variable.  For example percent = map(LS, 0,1023,0,100) would a value stored in LS and convert it so a percentage of the maximum value of 1023.