Hi everyone!
Ik have a question about a project of mine, but first let me explain what the end goal of this project is.
I wanted to create a robot that drives in an area the is marked with black lines. The robot works with 2 LDRs and 2 motors. When the LDR on the left reads the presence of a bIack line, the robot curves to the left, and when the LDR on the right reads the presence of a bIack line, the robot curves to the right. When both LDR are triggered, the robot curves to the left. The motors are controlled by a H-bridge, and receive power directly form the arduino.
I have build the robot, and i have finished the programming, there is only a small problem: The robot drives to fast over the black lines, and it doesn't have time make the curve it's suppost to. I have tried PWM but it seems that doesn't effect the H-bridge. The robot has anoher problem, it doesn't work if I connect an external battry. I'm using a 2600mah 6v battery.
The coding:
int inp1 = A1;
int inp2 = A0;
int outpgreen = 6;
int outpred = 3;
void setup()
{
Serial.begin(9600);
pinMode(inp1, INPUT);
pinMode(inp2, INPUT);
pinMode(outpgreen, OUTPUT);
pinMode(outpred, OUTPUT);
}
void loop(){
Serial.println(analogRead(inp1));
Serial.println(analogRead(inp2));
delay(500);
int ss1;
ss1 = analogRead(inp1);
int ss2;
ss2 = analogRead(inp2);
if(ss1 < 8 & ss2 < 8) {
digitalWrite(outpred, 0);
digitalWrite(outpgreen, 1);
}
else{
if (ss1 < 8) {
digitalWrite(outpgreen, 1);
}
else{
digitalWrite(outpgreen, 0);
}
if (ss2 < 8) {
digitalWrite(outpred, 1);
}
else{
digitalWrite(outpred, 0);
}
}
}
Do you have any suggestions?
Thanks in advance,
Max

