Home > Projects > Home Automation Projects > Laser Pointer Switch using arduino

Laser Pointer Switch using arduino

Summary of Laser Pointer Switch using arduino


This article details building a light-activated switch using an Arduino. The project samples ambient light with a photoresistor; when readings exceed a set threshold, it triggers a relay to control small appliances like lights or fans. The build involves modifying a USB cable for power, soldering components directly to the Arduino board, and uploading custom code to manage the switching logic based on light intensity.

Parts used in the Laser Pointer Switch:

  • Arduino board
  • Relay module
  • Photo cell (photoresistor)
  • Resistor
  • Right angle header
  • USB cable
  • FTDI device
  • Soldering equipment and tape

This instructable will detail how to make a switch that uses an arduino to sample light. When the light sample reaches a threshold it will trigger a relay that can be used to turn on/off a small appliance (light, radio, fan, etc…) The parts for this instructable can be ordered as a kit:

Jameco Kit

http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2209967_-1

Laser Pointer Switch using arduino

Step 1: Review relay and prep wire

unpackage the relay and stretch out the cable. this cable is used to activate the relay but will also be used to power the arduino. cut the wire in about two equal parts. the part with the white clip end will plug into the relay and be soldered into the arduino. the wire with the black clip end will be spliced into the usb cable to supply power to the arduino. this is also a good time to review the relay tutorial for safety information: http://www.dfrobot.com/wiki/index.php?title=Tutorial:_DFR0017_V2_Relay

Step 2: Modify USB cable

cut the USB cable about 6 inches from the end with the rectangle end.  strip the wires and you will find a red, black, green and white wire.  splice the red and black wires from the relay cable (with the black end) to the red and black wires of the USB cable.  solder the connections and tape the wires.  this new USB cable will be used to power the arduino.

Step 3: Identify Arduino

find the arduino in the kit of parts and familiarize yourself with the pin holes and orientation of the package.

Step 4: Component Layout

the components that are soldered onto the arduino need to be placed in specific places.  the right angle header goes into the right side of the arduino.  the photo cell needs to have one leg in the A5 hole and one leg int the Vcc hole.  the resister needs to have one leg in the GND hole and one leg in the A5 hole (with the photo cell) .  the wire from the relay (with the white end) needs to be soldered into the arduino also.  the green wire in the 5 hole, the black wire in the GND hole (with one leg of the resistor) and the red wire in the Vcc hole with one leg of the photo cell).  on some arduinos, the resistor leg and the photo cell leg will not fit in the same hole.  if this happens to you, you can put the resistor in from the back of the arduino and connect the photo cell leg to the resistor leg behind the arduino.

Step 5: Solder Arduino

for the holes that have a wire and a component leg in the same hole, make sure to put the wire in the hole first then push the component leg in.  after all the components are in the proper place, solder them.

Step 6: Program Arduino

connect your arduino to the FTDI device that you use to program it then upload this code to your arduino:
Laser Pointer Switch using arduino circuit

//adjust the lTrigger number for your light values
int lTrigger = 610;

int photoPin = A5;  //define a pin for Photo cell
int ledPin=5;     //define a pin for relay activator
boolean bLatch = false;
int lLaser = 0;

void setup() {
Serial.begin(9600);  //Begin serial communcation
pinMode( photoPin, INPUT );
pinMode( ledPin, OUTPUT );
}

void loop()  {
lLaser = analogRead(photoPin);
if (lLaser > lTrigger)   {
bLatch = !bLatch;
digitalWrite(ledPin,bLatch);
delay(1000);
}
Serial.println(lLaser); //display photocell value to serial monitor.
delay(10); //short delay for switch bounce
}

test your arduino with the serial monitor open to see the light reading values.  adjust the trigger value to a range that works best with your laser pointer.

Quick Solutions to Questions related to Laser Pointer Switch:

  • How is the Arduino powered in this project?
    The Arduino is powered by splicing the red and black wires from the relay cable into a modified USB cable.
  • Where does the photo cell connect on the Arduino?
    One leg of the photo cell goes into the A5 hole and the other leg goes into the Vcc hole.
  • What happens when the light sample reaches a threshold?
    Reaching the threshold triggers a relay that can turn on or off a small appliance.
  • Can I adjust the sensitivity of the light sensor?
    Yes, you can adjust the lTrigger number in the code to match your specific light values.
  • What should be done if component legs do not fit in the same hole?
    You can put the resistor in from the back of the Arduino and connect the photo cell leg to the resistor leg behind the board.
  • Which pin is defined for the relay activator in the code?
    Pin 5 is defined as the ledPin for the relay activator.
  • How do you test the Arduino after programming?
    You test it by opening the serial monitor to view the light reading values and adjusting the trigger range.
  • What is the purpose of the white clip end on the relay cable?
    The white clip end plugs into the relay and is soldered into the Arduino.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top