Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: kevinisnekkid on October 08, 2008, 09:31:08 PM

Title: $50 Photocell Help!!
Post by: kevinisnekkid on October 08, 2008, 09:31:08 PM
  I am having a problem with my robot. I got everything built ok.  8) I'm not fully understanding the photocells. But I followed the directions. The robot just goes straight. I can re-program the robot just fine. I have modified the code to remove the threshold, but the best result I've gotten was a very brief pause (less than a second). I've tried turning the plug around. I don't have the proper sockets, so I modified a socket from a computer hard drive cable. Since photocells are usually used in pairs, there shouldn't be any reason this won't work. I've checked the continuity on the circuit board, everything checks ok. The photocells look like they are wired right. What else can I check?  ???

Btw, I used 1k resistors instead of 1.5k resistors. Will that make it completely not work? I have an ISP cable, can I use that to get values from the board?
Title: Re: $50 Photocell
Post by: pomprocker on October 08, 2008, 11:54:34 PM
make sure your battery is charged, and post your code
Title: Re: $50 Photocell
Post by: kevinisnekkid on October 09, 2008, 01:26:25 AM
It's a freshly charged 8.4v pack. I ran it around for over an hour after I tried the photocells. And it was still going strong.
I used stock code. I just set the threshold to 0 for maximum sensitivity.
Code: [Select]
#include "SoR_Utils.h" //includes all the technical stuff

int main(void) {
  //declare variables here
  int i=1000;//a 'whatever' variable
  int sensor_left=0;//left photoresistor
  int sensor_right=0;//right photoresistor
  int threshold=0;//the larger this number, the more likely your robot will drive straight

  configure_ports(); // configure which ports are analog, digital, etc.
  a2dInit(); // initialize analog to digital converter (ADC)
  a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
  a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

  /*********ADD YOUR CODE BELOW THIS LINE **********/
  LED_off();//turn LED on

  while(1) {
    //store sensor data

    //detects more light on left side of robot
    if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold) {//go left
    //detects more light on right side of robot
    else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold) {//go right
    //light is about equal on both sides
    else {//go straight
    delay_cycles(500);//a small delay to prevent crazy oscillations
  /*********ADD YOUR CODE ABOVE THIS LINE **********/
  return 0;
Title: Re: $50 Photocell Help!!
Post by: Admin on October 10, 2008, 04:53:13 AM
I have modified the code to remove the threshold
Does it work without code modification?

Did you check the photocell voltages with a multimeter?
Title: Re: $50 Photocell Help!!
Post by: kevinisnekkid on October 12, 2008, 02:25:39 AM
Code modification didn't affect it.

I pulled out my breadboard, and checked. Only a tiny voltage would have gone to the chip, probably too small to read. I'm slightly puzzled why a 1.5k resistor was recommended. I went over the math and resistance readings. It seems that an 8k would be perfect. I tried a 15k, and the voltage tests good.

It's too late tonite (1:30am) to finish it, so I will continue tomorrow. I made a new set of "eyes" with 15k resistors. I'll put a plug on them later, and try it tomorrow.

Ok, it works!! :) My robot now chases my flashlight!! :) I will modify the code to have a smoother tracking, and change the wheels for better traction. Yay!! :)
Title: Re: $50 Photocell Help!!
Post by: Admin on October 15, 2008, 06:40:22 AM
and you will post a vid and pics too :P
Title: Re: $50 Photocell Help!!
Post by: kevinisnekkid on October 17, 2008, 09:37:41 AM
*sigh* my robot rolled over, and it's not working again... once I have it working good, I'll post pics & vid :) I'm going to change out the wheels to get better traction.

I'm also making a second board to help with diagnostics, so I can swap "eyes" and other sensors between them to help see if it's a board problem, or an "eye" problem. I ordered an rs232 adapter to have it talk to my computer, and I'll use it to read values. :)