Remote control a Relay with a Laser

This guide allows you to control any electronic device with a Laser using an Arduino, a light dependent resistor, and a relay module. This will work for any device that can be plugged directly into the wall outlet. All Links to buy parts are in this guide.

photosensorlaserpowerswitch

Requirements

– LDR (Light Dependent Resistor) : Dealextreme
– Relay Module : Detailed Guide Here
– A laser for testing.

Arduino Wiring

First connect your Relay Module to an arduino :

The relay module has following connectors, these connections should be the same for any Arduino Relay Module :

The relays can be closed by applying a “high” to any of the Channel pins.

Now we also need the LDR to receive our laser beam:

Arduino wiring diagram ldr

for the Analog In, I will be using pin 4 but you can use any Analog Input you want.

Wiring Relay

A relay is just an electrical switch, a relay would be connected the same way you would add a switch to a electric device.

3051_1_Relay_Diagram

A Relay usually has 3 connectors :

C Usually the wire that comes from your power supply
NO Normal Open : Device is OFF when sending a 0 (low)
NC Normal Closed : Device is ON when sending a 0 (low)

Wiring a light bulb :

– From your wall socket, go to the C on your relay.
– Then from the NO connector go to your Light bulb
– From the light bulb, go back to your wall socket:

relaylampsheme

Arduino Code

Program following code in your Arduino, change the relay pin to your wiring setup.

int value=0;
int led=13;
int relay=8;

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

void loop()
{
   value = analogRead(light);
   if(value == 950){
     digitalWrite(led,!digitalRead(led));
     digitalWrite(relay,!digitalRead(relay));

     delay(2000);
   }else{
      Serial.println(analogRead(light));
      delay(50);
   }
}

Leave a Reply