The microcontroller is AVR and the processor in it is ATMEGA8. I wrote a piece that followed the black color. It is like :
#include<avr/io.h>
#include<util/delay.h>
int main()
{
int rs,ls; // denotes the right sensor and left sensor respectively
DDRC=0x00; // DENOTES THAT WE TAKE INPUT FROM THE SENSER
DDRB=0xFF; // DENOTES THAT PORT IS MEANT FOR THE OUTPUT FROM THE MOTOR
while(1) {
ls=PINC&0b0000001; // last bit on
rs=PINC&0b0001000; // 1st bit on
if((ls==0b0000001)&(rs==0b0001000))
PORTB=0b00010010; // forward
if((ls==0b0000001)&(rs==0b0000000))
PORTB=0b00000010; // right
if( (ls==0b0000000) & (rs==0b0001000))
PORTB=0b00010000; // left
if((ls==0b0000000)&(rs==0b0000000) )
PORTB=0b00010010; // stop
}
}
I am trying to write for the edge avoider. It has the same sensors that detect the black color. But now those sensers have to avoid a pit while moving on the table. I am unable to decide as to how i can do this.
NOTE : Sensor is able to detect the pit if there is nothing beneath it. But how do I am having problem writing code.
There can be many solutions for Edge Avoider. One implementation I have seen is –
Explanation –
You need to experiment with delays, to get appropriate working.
These are the values needed below (I had omitted them before, because they are dependent on configuration)-
The below code should go inside
while (1)