/**************************************************************************************************************** * Program for reading two LDRs * created by: Anuj * (c)copyright * * * Physical setup: * Two LDRs connected to ground and Analog pin 1(Right) and Analog pin 2(left) * * ******************************************************************************************************************/ // Using Arduino Duemilinove // Pin definitions - attaches a variable to a pin. const int RightSensor = 1; // This pin is used to read the value of the Right Sensor. const int LeftSensor = 2; // This pin is used to read the value of the Left Sensor. // Variable definitions int SensorLeft; // This stores the value of the Left Sensor pin to use later on in the sketch int SensorRight; // This stores the value of the Right Sensor pin to use later on in the sketch // the setup() method runs once when the program is run. When the // Arduino is reset, the setup() will be executed once again. void setup() { pinMode(LeftSensor, INPUT); // Defines this pin as an input. The Arduino will read values from this pin. pinMode(RightSensor, INPUT); // Defines this pin as an input. The Arduino will read values from this pin. digitalWrite(A1, HIGH); // Enables an internal pullup resistor digitalWrite(A2, HIGH); // Enables an internal pullup resistor Serial.begin(9600); // Enables a serial connection through the Arduino to either USB or UART (pins 0&1). Note that the baud rate is set to 9600 Serial.println(" \nReading Light sensors."); // Placed at the very end of void Setup() so that it is runs once, right before the void Loop() } // the loop() method runs over and over again, // as long as the Arduino has power void loop() { SensorLeft = analogRead(LeftSensor); // This reads the value of the sensor, then saves it to the corresponding integer. delay(1); // the delay allows the Analog to Digital converter IC to recover for the next reading. SensorRight = analogRead(RightSensor); // This reads the value of the sensor, then saves it to the corresponding integer. delay(1); // the delay allows the Analog to Digital converter IC to recover for the next reading. // This section of the sketch is used to print the values of the // sensors through Serial to the computer. Useful for determining // if the sensors are working and if the code is also functioning properly. // This is known as debugging. Serial.print("Left Sensor = "); // Prints the text inside the quotes. Serial.print(SensorLeft); // Prints the value of the Left Sensor. Serial.print("\t"); // Prints a tab (space). Serial.print("Right Sensor = "); // Prints the text inside the quotes. Serial.print(SensorRight); // Prints the value of the Right Sensor. Serial.print("\n"); // Prints a new line after all the necessary data is displayed. }