Arduino – AnalogRead with Light-Sensor

Continuing from my previous post on sensors, in this post, I will write about how to do analog-read from Arduino. We will use a photo-cell (also called photo-resistor, LDR etc) for our demo purposes.

The photo cell detects the light level, We will use it to measure light intensity using an Analog Input (Arduino) and suddenly our program knows the level of light in the room.

But lets first cover the basics.

What is a Resistor?

  • Passive Component.
  • Limit the Current.
  • I (amp) = V (voltage) / R (Ohms).

What is a PhotoCell (Photo Resistor / LDR)

  • It is a Resistor.
  • Its value varies depending on light (more brightness, less resistance in component).
  • It is a very cheap sensor.

The photo cell detects the light level, We will use it to measure light intensity using an Analog Input (Arduino) and suddenly our program knows the level of light in the room.
The photocell used is of a type called a light dependent resistor, sometimes called an LDR. As the name suggests, these components act just like a resistor, except that the resistance changes in response to how much light is falling on them.

Basic Demo

In this simple demo, we will see how to wire photcell with arduino and read its value.

Steps:

  • Connect one slide of LDR to 5V.
  • Other side of LDR connected to 1K ohm resistor.
  • & from there it goes to ground.

In order to read the value from Arduino, we connect an analog input (pin A0) between the two resistors. Something like below:

and here is the proper wiring:

Connecting with Arduino

Here are few pictures of my board based on above shown schematic and breadboard diagram.

Arduino Sketch and Reading LDR Values

Turning LED ON/OFF based on LDR Values

  • We can bring in an LED to our previous wiring.
  • This way we can turn ON/OFF LED base on values from PhotoCell (LDR).
  • So when its dark, LED will On, when its bright, LED will be off.

Arduino Code

Summary

Sensors play very important role in electronics projects. In this post we saw very basic demo of how to read sensor values and then react based on these values. Though this was a simple demo, concepts learned here will be used later in upcoming posts. Till next time, Happy coding.

References