/*############################################################################## Author: * Mirko Prosseda (06-2013) * email: mirko.prosseda@gmail.com Description: * Analog Reflectance Sensor test sketch v1.0 * Check periodically the OUT pin of the analog sensor, if it is encountered * an obstacle the LED connected to pin 13 of Arduino is turned on. Connections: * BOARD -> ARDUINO * Vcc -> 5V * GND -> GND * OUT -> PIN 2 ##############################################################################*/ // Define constants and variables const int LED = 13; // sets the LED on pin 13 const int STATE = 2; // sets pin 2 for sensor reading int r_state = 0; // reset to zero the variable used to read the state of the OUT pin of the sensor // Initialization void setup(){ pinMode (LED, OUTPUT); // sets pin 13 as digital output pinMode (STATE, INPUT); // sets pin 2 as digital input } // main loop void loop(){ r_state = digitalRead(STATE); // reads the status of the sensor if(r_state == 0) // if is there an obstacle (OUT = 0) digitalWrite (LED, HIGH); // turn on the led else digitalWrite (LED, LOW); // turn off the led }