Photoresistor (with Arduino)

Photoresistor(With Arduino)

Introduction

The photoresistor is used in everyday life without you knowing it, it is widely used in home automation. It is very important to know for anyone who has an interest in electronics, and it is easy to program It is almost as easy as programming a LED blink program. Today I will provide you with the information you need to understand where the photoresistor comes from, where it is used in everyday life, and how to code it.

A quick history of the Photoresistor


The photoresistor is used in everyday life to automate things that otherwise require a human to do. It is used in alarm systems, streetlights, and light intensity meters. The idea of the photoresistor was invented back in 1873 by a man named Willoughby Smith when they discovered that Selenium is a photoconductor which means it changes its electrical conductivity depending on how much it is illuminated. The photoresistor only started becoming popular in the 1930s and 1940s almost 60 years after the idea of it came out. This changed the world of automation for humans especially with solar panels, because now we can track the sun with the Photoresistor and automatically turn and tilt the solar panel to get the highest possible power yield. The photoresistor resistance ranges between less than 1k ohm if the room is bright and, above 75K ohm if the room is dark. 

What you will need

  • 1x Arduino Uno
  • 3x Jumper wires
  • 1x Breadboard
  • 1x 10K ohm resistor
  • 1x Photoresistor

Steps

1. Wiring up the circuit is simple and easy as seen in the picture. The wires used are color-coded for convenience, Black is Ground, Red is 5 volts and Blue is for the analog pin A0. (NOTE: you need to use the correct resistor value, or else the  Photoresistor can get damaged. In this case, a 10K ohm resistor will work but to find out more, take a look at Ohm's law)

2. Code
int Photo = A0;

void setup()
{
  pinMode(Photo, INPUT);
  Serial.begin(9600);
}

void loop()
{
  //Photoresistor values range between 0 and 1023 
  int Value = analogRead(Photo);  
  Serial.println(Value);
  delay(100);
}

3. int Photo = A0;
Assign a Name Value to the analog pin used, in this case, it is pin A0

4. void setup(){
In the void setup, you give the code that will only run once when the Arduino starts up. The pinMode(pin, INPUT/OUTPUT); statement is used to tell the Arduino if that pin is an input or output to know if it should send or receive a signal. Serial.begin(9600); turns on the Serial Monitor on a specified baud rate, the default baud rate is set to 9600. The serial monitor allows you to send and receive data from the Arduino and it can be opened by clicking on the serial monitor icon.

5. void loop(){
In the void loop, you add the code that will continually repeat until it is stopped, the code runs line for line from top to bottom. int Value = analogRead(Photo); reads the analog pin that the photoresistor is connected to, and stores it in a variable. Serial.println(Value); writes the information stored in the variable to the serial monitor. Then the delay(100); pauses the code at that point for a specific amount of time in this case it is 100 milliseconds or a tenth of a second.

The photoresistor is very useful in everyday life and it is widely used all over the world. And because it is so easy to set up and use there is no reason why you shouldn't learn how to use it. So take this knowledge and try to automate something in your own home or office.  Below you can find and use my code to help you with this project.

Useful links

  1. GitHub - https://github.com/ITTechne/Photoresistor-Arduino-
  2. Items used (Amazon non-affiliate links)
    1. Arduino Uno
    2. Breadboard
    3. jumper wires
    4. 10K ohm resistor
    5. Photoresistor

Comments

Popular Posts