Control Servo With Light

54,221

48

13

Introduction: Control Servo With Light

Hello!
In this Instructable i will teach you how to control a servo using a Photocell.
This is very simple and good for beginners.

Step 1: Materials

1 x Photocell
1 x 10k Resistor
1 x Arduino
1x Breadboard
1x Servo
and some jumpers 

Step 2: Wiring It Up

Wire everything following the schematic below.

Step 3: The Code

The Code is very simple:

#include <Servo.h>

Servo myservo;
int val;

void setup()
{
myservo.attach(12);
}
void loop()
{
val = analogRead(0);
val = map(val, 0, 1023, 0, 179);
myservo.write(val);
delay(15);

3rd Epilog Challenge

Participated in the
3rd Epilog Challenge

Be the First to Share

    Recommendations

    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest

    13 Discussions

    0
    GaryK118
    GaryK118

    3 years ago

    hello can you tell me if this code will work on the arduino nano thanks for your time .

    0
    kutay.ozkeskin
    kutay.ozkeskin

    Reply 7 months ago

    Does it work ? Did you try ?

    0
    zoiss
    zoiss

    2 years ago

    Could please tell if this code will work on the Arduino nano?waiting for your reply

    0
    kutay.ozkeskin
    kutay.ozkeskin

    Reply 7 months ago

    Does it work ? Did you try ?

    0
    hrdkgjr
    hrdkgjr

    3 years ago

    can someone help me out for using two servo (dual axis) with this ?

    I tried with modifying this code but ended with horizontal axis motor not showing response! vertical axis worked fine

    0
    Bill Dawall
    Bill Dawall

    4 years ago

    Hello other coders. my name is Bill Dawall. I need help with the code. If any of you fine young men and women would like to help please reply.

    0
    zawminmin
    zawminmin

    4 years ago

    please give me advise.Now I research about dual axis solar tracker.Can anyone help me to give source code?

    0
    Global Ideas
    Global Ideas

    4 years ago

    pls i need assistance on my project, i am quite new on this stuff; using LDR to controlling a non continuos servo motor & print, 'welcome' when the motor rotate 180° left & 'goodbye' when the servo rotate otherwise

    0
    SardoC
    SardoC

    4 years ago

    Hi! I am new in all of this. I cannot get the wiring. Has anybody got a pics of this project? Thanks.

    0
    SardoC
    SardoC

    4 years ago

    Hi! I am new in all of this. I cannot get the wiring. Has anybody got a pics of this project? Thanks.

    0
    TomGee
    TomGee

    6 years ago on Introduction

    Hi, I am surprised that after 3 years that no one has had any problems with this project.

    The risk is that the 5V supply from the arduino is not able to supply enough current to a servo, if you want to drive anything with the servo you may have problems, such as jittering of the servo or resetting of the arduino.

    The servo should have its own power supply.

    This is a nice comment to those who are aiming to try this out, that you run risks of overloading the arduino 5V regulator.

    TomGeorge

    0
    meyer_lanski
    meyer_lanski

    9 years ago on Introduction

    Thank you for this informative post! I wanted to know what type of servo you used? Would it be possible to purchase an rc servo and control the spinning amount? For example, say I would like it to turn 1/4 of the way only instead of full revolution can this be done using your instructions or would there be some modifications that would need to be made?

    Thanks again!