
145Chapter 6: Microcontrollers
void setup() {
// initialize serial communication at 9600 bps
Serial.begin(9600);
}
void loop() {
// read pin and store value in a variable:
lightSensorValue = analogRead(lightSensorPin);
// print the light sensor value:
Serial.println(lightSensorValue);
// delay between readings:
delay(100);
}
Check your board type and serial port, and upload the code. Open your
Serial Monitor and make sure your baud rate is set to 9600, and you should
see sensor values on the screen!
Notice how as you cover and uncover the sensor, the values on screen
change. Try moving the circuit toward a very bright light and try covering it
compl ...