Society of Robots - Robot Forum

Software => Software => Topic started by: Aethur on August 18, 2011, 10:19:35 AM

Title: Photoresistor/Programming problem
Post 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!
Code: [Select]
//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();
}
Title: Re: Photoresistor/Programming problem
Post by: Gertlex on August 18, 2011, 05:31:32 PM
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?
Title: Re: Photoresistor/Programming problem
Post by: Aethur on August 18, 2011, 07:13:46 PM
I can't check, I don't have a data logger
Title: Re: Photoresistor/Programming problem
Post by: adanvasco on August 19, 2011, 05:29:53 PM
Do you have a multimeter? See if you are getting anything out of the port.
Title: Re: Photoresistor/Programming problem
Post by: Aethur on August 19, 2011, 07:37:43 PM
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?
Title: Re: Photoresistor/Programming problem
Post by: adanvasco on August 19, 2011, 08:02:13 PM
Check the voltage on the output pin. The pin should go high or low depending on the sensors.
Title: Re: Photoresistor/Programming problem
Post by: Webbot on August 20, 2011, 07:24:16 PM
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
Title: Re: Photoresistor/Programming problem
Post by: adanvasco on August 22, 2011, 09:49:36 AM
Or you may have a bad LED also. ;)
Title: Re: Photoresistor/Programming problem
Post by: Aethur on August 24, 2011, 08:12:15 PM
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?
Title: Re: Photoresistor/Programming problem
Post by: adanvasco on August 24, 2011, 08:18:24 PM
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.
Title: Re: Photoresistor/Programming problem
Post by: Aethur on August 25, 2011, 09:10:44 AM
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
Title: Re: Photoresistor/Programming problem
Post by: Webbot on August 25, 2011, 01:05:49 PM
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
Title: Re: Photoresistor/Programming problem
Post by: Aethur on August 26, 2011, 03:25:06 PM
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
Title: Re: Photoresistor/Programming problem
Post by: Webbot on August 26, 2011, 06:23:00 PM
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.
Title: Re: Photoresistor/Programming problem
Post by: Aethur on August 27, 2011, 01:06:49 PM
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