Hi,
We’re trying to program a robot to follow a black line. Insteed of learning the code our teacher told use to copy and paste the code , so we dont learn anything.
This is what we have come up with so far. If anyone has any ideas let us know.
/*
*/
const int AO1 = 13; //control pin 1 on the motor driver for the right motor
const int AO2 = 12; //control pin 2 on the motor driver for the right motor
const int PWMA = 11;
const int PWMB = 10; //speed control pin on the motor driver for the left motor
const int BO2 = 9; //control pin 2 on the motor driver for the left motor
const int BO1 = 8; //control pin 1 on the motor driver for the left motor
int sensorPin = A0; // select the input pin for ldr
int sensorPin2 = A1;
int sensorValue = 0; // variable to store the value coming from the sensor
int sensorValue2 = 0;
void setup() {
pinMode(2, OUTPUT); //pin connected to the relay
pinMode(AO1, OUTPUT);
pinMode(AO2, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(BO1, OUTPUT);
pinMode(BO2, OUTPUT);
pinMode(PWMB, OUTPUT);
Serial.begin(9600); //sets serial port for communication
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
sensorValue = analogRead(sensorPin2);
Serial.println(sensorValue2);
if(sensorValue < 100) //setting a threshold value
{
digitalWrite(AO1,HIGH); //turn relay ON
digitalWrite(AO2,HIGH);
}
else //turn relay OFF
{
digitalWrite(AO1,LOW);
digitalWrite(AO2,LOW);
}
if(sensorValue2 < 100) //setting a threshold value
{
digitalWrite(BO1,HIGH); //turn relay ON
digitalWrite(BO2,HIGH);
}
else //turn relay OFF
{
digitalWrite(BO1,LOW);
digitalWrite(BO2,LOW);
}
}
The idea is to have the photoresistors sense the black and turn on the motors