Arduino switch with photoresistor

Arduino Mega 2560, LDR and relay to create automated light switch

Arduino and 230V (or 110V) do not match…
Yet, there is a way to build an arduino switch that can handle 230V AC which can turn on light bulbs, start pumps, even the electric garage door. In this video we have a presentation about the build of a double switch 230V AC with the use of arduino which will change state with the help of a photo resistor.

Available sensors

We are goind to build a 230V AC (10Amps) switch with the help of arduino and a photorestor. This is an automated switch. Automated switches are always handy.
We can use several types of sensors to create automated switches.
For exampleQ

  1. Temperature Sensors
  2. Motion Sensors
  3. Light Sensors
  4. Gas Sensors
  5. Humidity Sensors
  6. Distance Sensors

As you see there are many alternatives and options that we can utilize and create automations. For this video we are goid to use a photoresistor to build a light switch. (natural or artificial light)

Materials needed:

  1. Arduino Mega 2560
  2. LDR (Light Dependant Resistor)
  3. Relay NO-NC 10A 230V (relay)
  4. Resistor 100K
Arduino διακόπτης

The circuit that you see was created in Fritzing (it’s free you can download it).

Light resistor and properties (LDR)

What is a Light Dependand Resistor;

A photoresistor( LDR) is a variable resistor controlled by ligh (natural or artificial).
It’s value decreases(Ω) when the light increases(Lux).

It is build from a durable semiconductor material. In darkness the LDR may be up to several ΜΩ (extremly large resistor), while in light the resistor can be at several hundreds of ohms.

Φωτοαντίσταση
Light resistor

If the light that falls to a photoresistor, exceeds a certain frequency, photons are absorbed from the semiconductor and the attached electrons give enough energy to transit at conductivity zone.

The free electrons conduct the electric current, reducing the resistance. Between LDRs we can find differences in range or sensitivity. The basic principle is the same.

Όταν υπάρχει φως η αντίσταση είναι μικρή. Όταν υπάρχει σκοτάδι η αντίσταση είναι μεγάλη.

Voltage divider

Voltage divider is a simple curcuit that has two resistors connected in series. At their free ends an input voltage is applied.

As output voltage we have the potential difference between one of the two resistors. Values can be from 0V to Vin.

We use a voltage divider in our circuit becase we want to receive to our analog input a value between 0 and 5 volts.

Check the image below to see how a voltage divider looks like.

διαιρέτης τάσης

Vin(Input voltage) = 5v

R1 = 100Κω

R2= LDR (Light resistor)

The calble Vout is beeing led to arduino A0 (analog input)

The current is equal: (does not really matter for our video but it’s good to know 🙂 )

I = Vin / (R1+R2)

Output Voltage

Vout=I*R2 = R2/(R1+R1)*Vin

Based on what we have writer for far, while the light is reduced the bigger will become the LDR value, therefore the Vout will be less. This is why when we have low lighting the Vout is low

Circuit 230V
Danger! do not try this if you are not authorized electrician.
Your risk your life.

To light a bulb we need a circuit of AC current from the electric network. Check the schematic below to see how the bulb can be lit when darkness falls.

διακόπτης με φωτοαντίσταση

Code arduino

int timiFotos = 0; 
int pinAisthitira = A0; 
int ledPin = 3; 

void setup() {
 Serial.begin(9600); 
 pinMode(ledPin, OUTPUT);
}

void loop() {
timiFotos = analogRead(pinAisthitira); 
Serial.println(timiFotos); 

if (timiFotos<400)
{
 digitalWrite(ledPin, LOW);
}
if (timiFotos>=400)
{
 digitalWrite(ledPin,HIGH);
}
}

0 responses on "Arduino switch with photoresistor"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Σχεδιασμός © GetCert. Με επιφύλαξη παντός δικαιώματος.