Hey guys, I am currently trying to stop my motors using an IR sensor (HW-201) I am using the L6205N motor controller, 2 dc motors, and an Arduino uno. I want the motors to stop when there is a wall in front ( approximately 5cm), but they are not stopping. Any help would be appreciated.
int IN1A= 9;
int IN2A = 8;
int IN1B = 3;
int IN2B = 4;
int EnableA= 10;
int EnableB= 2;
const int IR = A0;
bool val;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (IN1A, OUTPUT);
pinMode(IN2A, OUTPUT);
pinMode(IN1B, OUTPUT);
pinMode(IN2B, OUTPUT);
pinMode(EnableA, INPUT);
pinMode(EnableB, INPUT);
pinMode(IR, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite( EnableA, HIGH);
digitalWrite(EnableB, HIGH);
digitalWrite(IN1A, LOW); //backward, right wheel,
digitalWrite(IN2A, 1); //foreward, right wheel
digitalWrite(IN1B, LOW); //backward, left wheel
digitalWrite(IN2B, 1); //foreward, left wheel
digitalWrite(EnableA, 1);
digitalWrite(EnableB, 1);
val =analogRead(IR);
if(val==HIGH){
Serial.println("BLack");
digitalWrite(IN1A, LOW); //backward, right wheel,
digitalWrite(IN2A, LOW); //foreward, right wheel
digitalWrite(IN1B, LOW); //backward, left wheel
digitalWrite(IN2B, LOW);
}
else{
Serial.println("White");
digitalWrite(IN1A, LOW); //backward, right wheel,
digitalWrite(IN2A, 1); //foreward, right wheel
digitalWrite(IN1B, LOW); //backward, left wheel
digitalWrite(IN2B, 1);
digitalWrite(EnableA, 1);
digitalWrite(EnableB, 1);
also I want to slow down the motor speed but it does not seem to be working, can I have any tips on that?