Society of Robots - Robot Forum
Software => Software => Topic started by: Aethur on August 18, 2011, 10:19:35 AM
-
I wasn't sure if this belonged in software or electronics but..
I don't have my servos setup yet, so I thought I would test my sensors by turning the LED on and off depending on which sensor had a higher value. I can't get the LED to do anything though, regardless of what I do with the sensors.. am I missing something here?
The connection to the microcontroller appears to be good, this is the $50 robot build just with an atmega328p
Heres the code I'm using, pretty simple.. thanks for any help!
//detects more light on left side of robot
if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold)
{//go left
servo_left(44);
servo_right(44);
LED_on();
}
//detects more light on right side of robot
else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold)
{//go right
servo_left(25);
servo_right(25);
LED_off();
}
-
Code looks fine, with a quick look... What gets output if you do an rprintf statement to show the sensor_left and sensor_right values?
-
I can't check, I don't have a data logger
-
Do you have a multimeter? See if you are getting anything out of the port.
-
Yeah, that's why I thought the connection wasn't bad. I did a continuity check between the pin and the sensor and it was ok, should I be checking something else?
-
Check the voltage on the output pin. The pin should go high or low depending on the sensors.
-
Check the voltage on the output pin. The pin should go high or low depending on the sensors.
If the LED output pin is changing but the LED isn't lighting then you may have connected the LED the wrong way around
-
Or you may have a bad LED also. ;)
-
Thanks for the replies guys, the LED isn't bad, I can turn that on and off manually without issue.. I also checked the voltage on the output pins.. getting about 0 - 1v depending on the position of the sensors. Still no idea whats going on! Doesn't seems to be an issue with the electronics, any other ideas?
-
You should usually get around 5V on the output pin. Try a different pin and update the code to reflect this and see what happens then.
-
I'm sorry I checked the voltage of the pin on the MCU the sensor was connected to.. did you mean the output from the voltage regulator? I get 5v off of that
-
What "I" meant was the output on the LED pin - since you say its not behaving - it should be either 0v or 5v - not 1v
-
The LED is fine, I can turn it on and off in the code manually.. the voltage on it is correct. Absolutely no response when using the LED_on/off code with the sensor reading though.. it doesnt seem that the microcontroller is reading the sensors
-
If by 'manually' you mean that the LED_on and LED_off calls work ok on their own then I'm guessing that its not getting past the 'threshold' value in the code (or the right sensor is always bigger than the left so its always calling LED_off). Try swapping the LED_on and LED_off lines over and see if that makes the LED be permanently on.
-
Yep, and I've tried that also. I've also tried if (sensor > 0) LED_on(); and a few other variations of that to no avail