Loading...
Pages: [1]   Go Down
Author Topic: Hobby Servo with Photo Resistor  (Read 426 times)
0 Members and 1 Guest are viewing this topic.
United States of America
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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! smiley

Thanks!
« Last Edit: February 23, 2013, 12:27:22 pm by LinktheInventor » Logged

(USA)
Offline Offline
Full Member
***
Karma: 0
Posts: 191
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Johannesburg UTC+2
Offline Offline
Edison Member
*
Karma: 34
Posts: 1705
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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....
Logged

IT Crowd:
Roy... "Have you tried turning it off and on again?"
Moss.. "Have you tried forcing an unexpected reboot?"

Johannesburg UTC+2
Offline Offline
Edison Member
*
Karma: 34
Posts: 1705
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I will work up an example for you.

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

IT Crowd:
Roy... "Have you tried turning it off and on again?"
Moss.. "Have you tried forcing an unexpected reboot?"

(USA)
Offline Offline
Full Member
***
Karma: 0
Posts: 191
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);

}
« Last Edit: February 23, 2013, 09:14:27 am by Drew Davis » Logged

United States of America
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

Logged

(USA)
Offline Offline
Full Member
***
Karma: 0
Posts: 191
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Make sure to tell me if the code works!

Thanks,
Drew Davis
Logged

(USA)
Offline Offline
Full Member
***
Karma: 0
Posts: 191
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Johannesburg UTC+2
Offline Offline
Edison Member
*
Karma: 34
Posts: 1705
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

IT Crowd:
Roy... "Have you tried turning it off and on again?"
Moss.. "Have you tried forcing an unexpected reboot?"

(USA)
Offline Offline
Full Member
***
Karma: 0
Posts: 191
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

Logged

Pages: [1]   Go Up
Print
 
Jump to: