Society of Robots - Robot Forum
Software => Software => Topic started by: Xyver on March 10, 2010, 06:27:50 PM
-
I've made my 50$ robot, and I am now trying to program it. I've been messing around with the light sensors I made and Arduino and servos and such, and i know how to make it that a different amount of light will turn the servo at different speeds. The problem is, I don't think its sensitive enough. It goes one speed in the light, but to make it slow down/stop, I have to entirely cover the sensor in my hand.
How can I make it more sensitive?
Before I modified the servo i tested the same thing, and by waving the sensor around the motor would twitch to different positions. So it does work, unless I screwed up on the modifying.
Another thing, I was reading through this post http://www.societyofrobots.com/robotforum/index.php?topic=2724.0 (http://www.societyofrobots.com/robotforum/index.php?topic=2724.0) and saw the numbers 23/.992*(time in milliseconds) = number of cycles . Where does the 23 and the .992 come from??? Would it be different for an Arduino?
-
Please post your code.
-
I've just been messing about with the practice codes on the Arduino website for potentiometers controlling servos. Here it is:
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(1.5); // waits for the servo to get there
}
-
You will have to mess around with the values. The example arduino code assumes that the input sensor will range from 0 to 5 volts, however the light sensors probably output a range smaller than that. In the map() method, increase the value of the 0 and decrease the value of the 1023 to shorten the range.