Light-Controlled Servo

by TechMartian in Circuits > Arduino

63649 Views, 46 Favorites, 0 Comments

Light-Controlled Servo

IMG_0971.jpg

Servos are very versatile motors; they can be used in a wide range of mechanical applications. This project focuses on the control of a servo motor depending on the light levels in the current environment. This idea can be applied to applications such as control of lamps and light switches where the servo will manually actuate the light switches given a certain light condition to both turn it on or off. This allows many homes be semi-automated without having to a large expense. Servo motors can be used virtually anywhere and this technology can be further applied to other fields and use cases.

Tools and Materials

IMG_0969.JPG
  • Arduino 101 or Arduino Uno
  • Breadboard
  • Photresistor or LDR
  • 10k Ω resistor
  • Servo motor
  • Jumper Wires

Circuitry

Screen Shot 2017-07-19 at 12.45.38 PM.png
IMG_0970.jpg

Connecting the Arduino power to the breadboard and Servo motor. The LDR will be getting power from the 3.3V pin of the Arduino, while the servo will be getting power form the 5V pin of the Arduino and both are connected to a common.

  • Connect the 5V pin of the Arduino to the red pin of the servo with a male-to-male red jumper cable. Red pins will be used to indicate 5V.
  • Connect the GND pin of the Arduino to the black pin of the servo with a male-to-make black jumper cable.
  • Connect the 3.3V pin of the Arduino to the red power rail of the breadboard with an orange jumper wire.
  • Connect the GND pin of the Arduino to the ground power rail of the breadboard with a brown jumper wire.


Wiring the Servo to the Arduino

  • Connect the white pin of the servo moor to the digital pin 9 of the Arduino board.

Wiring the LDR to the Arduino. For this, we will need a voltage divider.

  • Connect one of the pins of the LDR onto the red power rail.
  • Connect the other pin to a 10kΩ resistor in series to ground.
  • Connect the remaining pin of the LDR connected to the 10kΩ resistor to the analog pin A0 of the Arduino.

Code

Screen Shot 2017-07-19 at 12.55.21 PM.png

//include the servo library

#include

//create a servo object called servo1 Servo servo1;

void setup() { // put your setup code here, to run once:

// set the servo pin, pin 9, as an servo output pin servo1.attach(9); }

void loop() { // put your main code here, to run repeatedly:

int lightValue = analogRead(A0);

// map the light readings to the angle possible by the servo motor lightValue = map (lightValue, 0, 1023, 0, 180);

// control the servo motor based on the light value read, adjust linearly by angles servo1.write (lightValue); }

Demo

LDR-controlled Servo Demo

As the light level goes up, the servo turns towards 180 degrees. While, the light level goes up the servo turns in the opposite direction towards zero degrees, and varying light levels will turn the servo in it's respective direction.