My sketch still is not working properly with the motor drive. We are building an autonomous robot that uses 3 proximity sensors to control the motors. Ive provided my sketch below. Just like before, no LEDs turn on on the motor drive once i wire it into the arduino and I dont think the outputs from the sensors are taking any effect. I have only coded for the two sensors that directly control the movement of the motors. The third sensor will act as an interrupt. Please someone help me!
i just need an arduino sketch that can take the analog signal from two proximity sensors that effects the pwm output to the motor drive
int PWM_1 = 3; // Motor 1 Control
int IN1_A = 4;
int IN1_B = 7;
int PWM_2 = 11; // Motor 2 Control
int IN2_A = 12;
int IN2_B = 13;
const int SNS_1 = A0; // Sensors
const int SNS_2 = A1;
const int SNS_3 = A3;
int sensorValue = 0;
int outputValue = 0;
int sensorValue1 = 0;
int outputValue1 = 0;
int sensorValue2 = 0;
int outputValue2 = 0;
void setup()
{
Serial.begin(9600);
pinMode(PWM_1, OUTPUT);
pinMode(IN1_A, OUTPUT);
pinMode(IN1_B, OUTPUT);
pinMode(PWM_2, OUTPUT);
pinMode(IN2_A, OUTPUT);
pinMode(IN2_B, OUTPUT);
pinMode(SNS_1, INPUT);
pinMode(SNS_2, INPUT);
pinMode(SNS_3, INPUT);
}
void loop(){
int sensorValue = analogRead(SNS_1);
int sensorValue1 = analogRead(SNS_2);
int sensorValue2 = analogRead(SNS_3);
outputValue = map(sensorValue, 0, 1023, 0, 255);
outputValue1 = map(sensorValue1, 0, 1023, 0, 255);
outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
Serial.println(sensorValue, DEC);
Serial.println(sensorValue1, DEC);
Serial.println(sensorValue2, DEC);
if(outputValue <= 160, outputValue1 >= 90){ //Make the robot go left if to close to right
digitalWrite(IN1_A, LOW);
digitalWrite(IN1_B, LOW);
analogWrite(PWM_1, 0);
digitalWrite(IN2_A, HIGH);
digitalWrite(IN2_B, LOW);
analogWrite(PWM_2, 255);
}
else if(outputValue >= 90, outputValue1 <= 160){ // Make the robot go right if to close to left
digitalWrite(IN1_A, HIGH);
digitalWrite(IN1_B, LOW);
analogWrite(PWM_1, 255);
digitalWrite(IN2_A, LOW);
digitalWrite(IN2_B, LOW);
analogWrite(PWM_2, 0);
}
else{
digitalWrite(IN1_A, HIGH); // Make the Robot go forward
digitalWrite(IN1_B, LOW);
analogWrite(PWM_1, 255);
digitalWrite(IN2_A, HIGH);
digitalWrite(IN2_B, LOW);
analogWrite(PWM_2, 255);
}
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
Serial.print("sensor = " );
Serial.print(sensorValue1);
Serial.print("\t output = ");
Serial.println(outputValue1);
Serial.print("sensor = " );
Serial.print(sensorValue2);
Serial.print("\t output = ");
Serial.println(outputValue2);
}