I am using a 4 IR Avoidance Module. When I am using 2, it works fine, but when I insert a 3rd one, the sensor is not working properly. I tried calibrating it with the potentiometer but there is no luck. I transferred IR no2 to no3 to test if no3 port is working, and it is working well. Any fixes?
Any code ?
Any schematic ?
You have not provided any of circuit any of the code or also detail of your project
1 Like
Is your code looking only at the first two sensors and not the third one?
Hello @idontknowhowtouse
I am quite sure I found your code... perhaps your #3 IR Avoidance Module is not plugged in correctly. Check again, or maybe post a photograph here.
/*Obstacle avoidance robot with Arduino.
created by the SriTu Hobby team.
Read the code below and use it for any of your creations.
https://srituhobby.com
*/
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
int Speed = 150;
#define sensor1 A0
#define sensor2 A1
#define sensor3 A2
#define sensor4 A3
void setup() {
Serial.begin(9600);
motor1.setSpeed(Speed);
motor2.setSpeed(Speed);
motor3.setSpeed(Speed);
motor4.setSpeed(Speed);
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
pinMode(sensor3, INPUT);
pinMode(sensor4, INPUT);
}
void loop() {
bool value1 = digitalRead(sensor1);
bool value2 = digitalRead(sensor2);
bool value3 = digitalRead(sensor3);
bool value4 = digitalRead(sensor4);
// Serial.println(value2);
// Serial.println(value1);
if (value1 == 1 && value2 == 1 && value3 == 1 && value4 == 1 ) {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
} else if (value1 == 0 && value2 == 0 && value3 == 1 && value4 == 1 ) {
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(200);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(1000);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(600);
} else if (value1 == 1 && value2 == 1 && value3 == 0 && value4 == 1) {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
} else if (value1 == 1 && value2 == 1 && value3 == 1 && value4 == 0) {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.