go away spammer

Author Topic: Photoresistor/Programming problem  (Read 2756 times)

0 Members and 1 Guest are viewing this topic.

Offline AethurTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Photoresistor/Programming problem
« 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();
}

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 763
  • Helpful? 24
  • Nuclear Engineer ยท Roboticist
    • Index of Oddities
Re: Photoresistor/Programming problem
« Reply #1 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?
I

Offline AethurTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: Photoresistor/Programming problem
« Reply #2 on: August 18, 2011, 07:13:46 PM »
I can't check, I don't have a data logger

Offline adanvasco

  • Full Member
  • ***
  • Posts: 107
  • Helpful? 6
  • Necessity is the mother of invention.
Re: Photoresistor/Programming problem
« Reply #3 on: August 19, 2011, 05:29:53 PM »
Do you have a multimeter? See if you are getting anything out of the port.
Knowledge does not weigh.

Offline AethurTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: Photoresistor/Programming problem
« Reply #4 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?

Offline adanvasco

  • Full Member
  • ***
  • Posts: 107
  • Helpful? 6
  • Necessity is the mother of invention.
Re: Photoresistor/Programming problem
« Reply #5 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.
Knowledge does not weigh.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Photoresistor/Programming problem
« Reply #6 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
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline adanvasco

  • Full Member
  • ***
  • Posts: 107
  • Helpful? 6
  • Necessity is the mother of invention.
Re: Photoresistor/Programming problem
« Reply #7 on: August 22, 2011, 09:49:36 AM »
Or you may have a bad LED also. ;)
Knowledge does not weigh.

Offline AethurTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: Photoresistor/Programming problem
« Reply #8 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?

Offline adanvasco

  • Full Member
  • ***
  • Posts: 107
  • Helpful? 6
  • Necessity is the mother of invention.
Re: Photoresistor/Programming problem
« Reply #9 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.
Knowledge does not weigh.

Offline AethurTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: Photoresistor/Programming problem
« Reply #10 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

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Photoresistor/Programming problem
« Reply #11 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
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AethurTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: Photoresistor/Programming problem
« Reply #12 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

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Photoresistor/Programming problem
« Reply #13 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.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AethurTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: Photoresistor/Programming problem
« Reply #14 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

 


Get Your Ad Here

data_list