I was trying to insert some images I posted to Flickr, but it’s not working. Here’s the link to flickr though.
I found the formula for linearizing the voltage output from the IR Range sensor here.
Video:
int servoPin = 2; // Control pin for servo motor
int minPulse = 500; // Minimum servo position
int maxPulse = 2500; // Maximum servo position
int pulse = 0; // Amount to pulse the servo
long lastPulse = 0; // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses
int val; // outgoing ADC value
int distance = 0; // linearized distance value
void setup()
{
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulse = minPulse; // Set the motor position value to the minimum
beginSerial(9600);
}
void loop()
{
val = analogRead(0); // read analog input:
distance = (2914 / (val + 5)) - 1; // linearize sensor readings
printString("distance = "); // print out distance readings for reference
printInteger(distance);
printString(" ");
delay(10);
pulse = distance*125; // convert distance to a value between minPulse
// and maxPulse
if (minPulse < pulse = refreshTime) { // pulse the servo again if rhe refresh time (20 ms) have passed:
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
} else {
pulse = minPulse;
}
}
}
Your first tag should use the word “sourcecode” instead of just “source”
Comment by jssmith44 — March 10, 2008 @ 2:03 pm |