Skip to main content

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 coding part

#include <LiquidCrystal.h>

const int LDR_PIN = 3;

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

void setup() {

  lcd.begin(16, 2);
}

void loop() {
  int ldrReading = analogRead(LDR_PIN);

  // LDR resistance is inversly proportional to the light

  ldrReading = 1023 - ldrReading;

  // Clear screen on LCD
  lcd.clear();

  // Print a message to LCD
  lcd.print("lux: ");
  lcd.print(ldrReading);

  delay(1000);
}

The code first sets up the LCD display. And in the loop(), keeps reading pin 3 every second, converts it to light intensity from 0 (completely dark) to 1023 (full light) and displays the value on the LCD display. Note that although I print the value as "Lux: X", the value is not really the luminance.

A few images of the setup under various lighting conditions

Under ambient light during day time

When the LDR is blocked with a paper

Under florescent lighting

Comments

Popular posts from this blog

Attesting General Power of Attorney in SF

Recently I had to go through the motions of getting a General Power of Attorney (GPA) document attested in San Francisco. I am an Indian by birth. My parents were trying to buy a house back in India for me. Since I did not want to travel to India they needed a GPA so that they can act on my behalf to sign all the documents required to buy the house. The problem however is that they needed it urgently because the seller lives in UK and wants to get all the things done quickly so he can go back. My parents send me a GPA document that they obtained from a lawyer. This is a document that will give the power to my parents to buy the said property in the document on my behalf. The lawyer said that I will have to get the document attested at an Indian Consulate in USA. The closest one for me is in SF and I can drive there in about an hour from where I live. So I though it will be like a day's work to get all the things done. I looked up at their  website  for the procedure to att

XBMC / Boxee remote control android app

I have been writing a few android apps over weekends at home and during 20% time at Google. However I never actually released any of them in the android market mainly because they were quick and dirty apps that fit my needs but perhaps would not be appealing to the general public. One such app that I quickly wrote over a couple of weekends is a XBMC remote. The media center that I use at home is XBMC and I have always wanted to have more control and faster access to my media. Using my remote to navigate through the menus is not as fast. Especially when I wanted to queue a lot of music it is very slow. So I wrote this nice little app called "XBMC remote" for my android phone to control XBMC from anywhere :). Give it a try. Search for "xbmc" in android market and install it if you use XBMC as your media center. When you first launch the app you will start with this screen. You will have to setup your web server address, username and password (if required) by

gtkdocize not found

If you are ever configuring an app and see the message "gtkdocize not found" in Gentoo, then you need to emerge gtk-doc. I had some hard time figuring this out so I am writing it in my blog for the next time. When I saw that error message I did an "emerge -s gtkdocize". Usually it is that simple in Gentoo. But not this time. The emerge command returned no results at all. Then I searched for gtkdoc and still no luck. After searching in Google, I still did not have a solution. After thinking for a while I decided to try to search for gtk-doc. Bingo! That worked! Interestingly, this is my first post from my Virtual machine :-)