Line Following using 3 Sensors
FlowChart for Line Follower using 3 sensors (link to drawing)
Line Follow Template-3 sensors
Can be modified to use 6 sensors/3 pairs
Code snippets...
// define pins
#define SensPin0 A0 // leftmost sensor
#define SensPin1 A1.....
#define threshold 300 // typical range is white < 100, black > 750; set threshold in the middle
// set up sensor variables( reading) and status variables- is it on black ( HIGH) or white (LOW)?
int Sensor0;
int Sensor1.....
int Sensor0Status=LOW;
int Sensor1Status.....
void loop() {
readSensors();
...determine actions
}
void readSensors() // read the sensor values; set status variables HIGH or LOW
{
Sensor0 = analogRead(SensPin0);
Sensor1.....
if (Sensor0> threshold)
{
Sensor0Status= HIGH;
}
else {
Sensor0Status= LOW;
};
if (Sensor1 > threshold).......
#define SensPin0 A0 // leftmost sensor
#define SensPin1 A1.....
#define threshold 300 // typical range is white < 100, black > 750; set threshold in the middle
// set up sensor variables( reading) and status variables- is it on black ( HIGH) or white (LOW)?
int Sensor0;
int Sensor1.....
int Sensor0Status=LOW;
int Sensor1Status.....
void loop() {
readSensors();
...determine actions
}
void readSensors() // read the sensor values; set status variables HIGH or LOW
{
Sensor0 = analogRead(SensPin0);
Sensor1.....
if (Sensor0> threshold)
{
Sensor0Status= HIGH;
}
else {
Sensor0Status= LOW;
};
if (Sensor1 > threshold).......