Go Down

Topic: Hobby Servo with Photo Resistor (Read 1 time) previous topic - next topic

LinktheInventor

Feb 23, 2013, 02:46 pm Last Edit: Feb 23, 2013, 06:27 pm by LinktheInventor Reason: 1
Hello, I am LinktheInventor, and I would like to know if there is code out there to make a Hobby Servo run by the Photo Resistor ( I hope that makes sense).
I am using the Arduino Uno (which I got with the Adafruit ARDX - v1.3 Experimentation Kit for Arduino (Uno R3) - v1.3), and I don't know much code. I wan't this combination to do this:
1.The light gets below a certain level.
2. The photo resistor "reads" the light and sends a "signal" to the Hobby Servo, which closes a door. ( Pet cages is what I am mostly thinking of)

If you have any questions, ask them below! :)

Thanks!

drewdavis

I assume that you want the value of the photo resistor to determine the position of the servo arm.

If that is the case their is some code.  I will work up an example for you.

JimboZA

Not sure exactly what you mean, no.... But here's what I did a while ago: I mounted an LDR on the horn of a servo, and coded it so that if the LDR was in the dark, the servo would start sweeping until it was in the light and then it would stop. Is that the kind of thing you mean?

You won't get full code for a school project supplied here, since you're supposed to be learning, but here's a couple of links to save you searching. Here is how to read an LDR, and here is how to run a servo.

Leave it to you figure out how to combine the two....
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

JimboZA

Quote
I will work up an example for you.


You sure you should be doing that for a someone's school project, Drew?
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

drewdavis

#4
Feb 23, 2013, 03:11 pm Last Edit: Feb 23, 2013, 03:14 pm by Drew Davis Reason: 1
This code might work. I don't have time to test it. This will at least give you a place to start. As for his school project this code is PART of it. I'm sure he will add to it.

Code: [Select]
#include <Servo.h>

Servo myservo;  
int sensorValue = 0;
int sensorPin = A0;

void setup()
{

myservo.attach(9);

}

void loop()
{
 
 sensorValue = analogRead(sensorPin);
 
 sensorValue = sensorValue / 5.7;

myservo.write(sensorValue);

delay(1200);

}

LinktheInventor


Quote
I will work up an example for you.


You sure you should be doing that for a someone's school project, Drew?


I understand that it is my project, but I just have some questions that me (and my family) can't answer (we have basic understanding of it,but we are willing to learn). Thanks for the link though!


drewdavis

Make sure to tell me if the code works!

Thanks,
Drew Davis

drewdavis

How did the code work?

Also after rereading your post it appears that you want to make the door close after a certain level of light is reached. If that is the case tell us and I (or you) can adapt the code.

JimboZA

The door closing is a good project, since it will be interesting mechanically too- the angles of linkages etc to get it close smoothly etc etc.

One question.... how will you make sure the inhabitants are on the right side of the door?... or even more important, not getting jammed in the closing door?
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

drewdavis

He could use a motion sensor… If movement is detected & light is right shut the door.

This would work….
https://www.sparkfun.com/products/8630


Good luck LinktheInventor!


Go Up