Light-Controlled Servo




Introduction: Light-Controlled Servo

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.

Step 1: Tools and Materials

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

Step 2: Circuitry

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.

Step 3: Code

//include the servo library


//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); }

Step 4: 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.

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

2 People Made This Project!


  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

3 Discussions


1 day ago on Step 3

The text of the code is missing <Servo.h> on line 2


Question 7 months ago on Step 2

Hello can i change the power source to a 9 volt battery?


Question 1 year ago

I'm trying to increase the angle the motor turns even more. I want it to turn a whole lot more than the tiny amount it's doing atm. How do I change the code so it opens to a particular angle once the light read drops below a certain amount? but still open linearly so it still opens based on the amount of light?