Skip to main content

Posts

Showing posts with the label ldr

InduinoX and wireless relays: Part II

In my last post , I played a bit with the wireless relays to turn on a light. In this post I will show how to use LDR to detect when to turn on the light depending on the ambient light. Lets dive into the code quickly #define TRUE  1 #define FALSE 0 int LIGHT_PIN = 7; int SLEEP_TIME = 100; int LDR_PIN = 3; int LDR_THRESHOLD_FOR_DARK = 350; int MAX_COUNT_BEFORE_TOGGLE = 10; int isLightOn = FALSE; int toggleCount = 0; void setup() {   turnOffDevice(LIGHT_PIN);   digitalWrite(LIGHT_PIN, LOW);   Serial.begin(115200); } void turnOffDevice(int pin) {   pinMode(pin, INPUT); } void turnOnDevice(int pin) {   pinMode(pin, OUTPUT); } void toggleLight() {   if (isLightOn) {     turnOffDevice(LIGHT_PIN);     isLightOn = FALSE;   } else {     turnOnDevice(LIGHT_PIN);     isLightOn = TRUE;   } } void toggleLightIfNecessary(int input, int t...

InduinoX: Interfacing with the LDR

Now that I got my LCD display to work with the arduino board , I wanted to use it to show something useful. Since I needed to detect the ambient light for my home automation project , I decided to display the amount of light coming into a room using the light dependent resistor (LDR) that comes with the InduinoX board. Later I will use the LDR reading to determine whether I have to turn on the lights in the room or not. Typical LDR (Source: http://www.induino.com/wiki/index.php?title=File:LDR.jpg) The LDR's output is connected to analog pin 3. The voltage as read from pin 3 is inversely proportional to the light incident on it. The analog input is connected to a 10 bit analog to digital converter (ADC). Hence the values range from 0 (at 0V) to 1023 (at 5V). The analog pins can be referenced in the code using A0 (for analog input 0) to A5. For more information on analog inputs, check out  http://www.arduino.cc/en/Tutorial/AnalogInputPins . Now to get to the codin...