New line follower circuit..!

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

first i have been connecting the analog inputs directly to the uC, now i have made use of LM339N comparator IC, with pots(trim resistor) so that i can caliberate.

I didnt put provision for ISP header coz i have an arduino , which i could use to program the uC.

Please suggest any possible changes or corrections i should make.
thanks

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why use comparators? Could you not feed the sensor analog signas into the ADC and do the comparison in software?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not a single one of the chips power pins have ~100nF bypass capacitors. Not even the regulator.

Also that (if not most) comparators can only have low output or floating, so the leds won't work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What were you hoping the circuit would do? If you can explain what your desired function is then we can offer suggestions. Also tell us about the inputs that go into the LM339. Are they analog and do you wish to measure with ADC? You can, as suggested before, do compare in software and then drive LEDs with other pins.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For someone just getting started with AVR's, it makes sense to do some of the functions in hardware (sensor calibration) rather then software, but as Jepael pointed out the LM339 is open collector output and cannot drive high, so it won't drive your LED's. You should get in the habit of wiring the LED's to VCC and driving the other side low, in this case it would allow the OC comparator to drive the LED's.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Why use comparators? Could you not feed the sensor analog signas into the ADC and do the comparison in software?

Initially i did that, but at different competetions(line tracer competetions) the lighting would be different and i will have fully reprogram it which would be hard, turning the pot would be way easier.
Quote:
Not a single one of the chips power pins have ~100nF bypass capacitors. Not even the regulator.

Im really confused and i really dont know where all i have to add caps, please shed some light on that .. :)

Quote:
What were you hoping the circuit would do? If you can explain what your desired function is then we can offer suggestions. Also tell us about the inputs that go into the LM339. Are they analog and do you wish to measure with ADC? You can, as suggested before, do compare in software and then drive LEDs with other pins.

The input to the comparator comes from 4 IR sensors( uses an IR led and IR photodiode). Where do you suggest i place my LED's?

thanks all for replying :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually a lot of line followers are setup to calibrate themselves at runtime. I use to run our events in Phoenix and you would see contestants on the track manually turning their line followers back and forth over the track lines. What they are doing is running a simple program that looks for highest and lowest readings on each sensor. These values are then used to compute the thresholds use for each sensor during the actual runs.

Your LED placement is ok, but you need to reverse the way you have them wired up. Connect the anode to the resistor and connect the cathode to VCC. Now when the comparator drives low, the LED will light. Depending on how your sensor works, you may have to swap the inputs to the comparator as well. Do you want the LED to light when a line is detected? Also is the line black or white?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Actually a lot of line followers are setup to calibrate themselves at runtime. I use to run our events in Phoenix and you would see contestants on the track manually turning their line followers back and forth over the track lines. What they are doing is running a simple program that looks for highest and lowest readings on each sensor. These values are then used to compute the thresholds use for each sensor during the actual runs.

Is that a separate program?

Quote:
Do you want the LED to light when a line is detected? Also is the line black or white?

It is a black line on a white background, so the LED should glow when the sensors detect the line..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The calibration is part of your total program. Depending on what you have for a user interface, you use anything from a button you hold down at powerup, to a menu selection on your display (see my avatar). In your case the simplest thing would be a pushbutton that you read when the micro is reset (or turned on). If the button is pressed then run your calibration routine and store in eeprom. If the button isn't pressed then run your line follower code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im sorry but why should i store it in EEPROM? i was wondering i could use something like this,
(arduino code)

.
.
.
.
for(int i=0; i<5000; i++)
{

int val = 0;
for(int j=0; j<=5; j++)
{
val = analogRead(j);
if(val >= mx)
mx = val;
if(val <= mn)
mn = val;
}
delay(1);
}

mid = ((mx + mn)/2);
.
.
.
.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You would store the calibration values in eeprom so you don't need to do a calibration each time. You probably might want to add some hysteresis into your code to make it work a bit better otherwise a bit of noise might upset the rest of your logic.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you tell me where all i should add caps and why? ( just curious and im just learning stuff)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You store in eeprom so the values are remembered after turning of your line follower. If your event is like mine they want to keep it moving so they don't want someone on the track doing a cal before each race. And as Kartman suggested you need to take your min/max readings and pull them in so you account for noise and other factors. For example if you get a reading of 20 for black and 220 for white, then use a threshold of say 50. So now anything less then 50 means the sensor is over the line, otherwise assume it's off the line. You'll have to experiment with your setup for what works best.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now, that youve told ive planned to take down the comparator and do the calibration with the program , like u said. So what should i do about the noise reduction?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would focus first on getting your board working. If you decide to remove the comparators, I would still keep the LED's just so you have a visual verification that everything is still working. Don't hang the LED's on the same pin as the sensors, this will corrupt the sensor reading. Instead use 4 unused port pins and drive the LED with those. In software you read a sensor and depending on it's value, you've determined it's on the line or not. If it's on the line drive the LED on, otherwise turn off the LED.

Once that's all working as you would expect, then go after a calibration routine. Then the real work begins, you will need to develop a routine that reads the sensors and alters the motor speeds to stay on the line. Do some research on PID control loops to get a feel for what's involved. Look for some examples on how others have done line followers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Do some research on PID control loops to get a feel for what's involved. Look for some examples on how others have done line followers.

Any good links?

Ive updated my schematic, have a look :)

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What are you using for sensors? If they are something like an IR reflective sensor, which uses an IR photo transistor/diode, that's an open-collector output and you will need pullups on the 4 sensor inputs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

but isnt there internal pullups in the UC pins?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jayakrishnan wrote:
but isnt there internal pullups in the UC pins?

The internal pullups a weak pullups and won't work well for what you're doing here. If memory serves we're talking ~100K and you need something more like 5K for your pullups.