Hi all
So i have an Arduinio and H-bridge for my robot Mop i am building, pretty much all i am trying to do is get the bumper switches to initiate the collision avoidance, i have plugged the bumper switches directly to the D8/D9 pins (without the resistor) and the reamining terminals to the ground pin. It all seemed to work fine, and then suddenly , D9 stopped working, so i tried reprogramming it to look for d10/11/12 , none of them seem to work,
What have i done here, copy of my script below
const int channel_a_enable = 6; //Left Motor Conencted
const int channel_a_input_1 = 4; //as above
const int channel_a_input_2 = 7; //as above
const int channel_b_enable = 5; //Right Motor Connected
const int channel_b_input_3 = 3; //as above
const int channel_b_input_4 = 2; //as above
const int bumpRight = 9; // Right bumper pin 9
const int bumpLeft = 11; // Left bumper pin 11
int pbRight = 0; // Var for lef t bump
int pbLeft = 0; // Var for left bump
void setup()
{
pinMode( channel_a_enable, OUTPUT ); // Channel A enable
pinMode( channel_a_input_1, OUTPUT ); // Channel A input 1
pinMode( channel_a_input_2, OUTPUT ); // Channel A input 2
pinMode( channel_b_enable, OUTPUT ); // Channel B enable
pinMode( channel_b_input_3, OUTPUT ); // Channel B input 3
pinMode( channel_b_input_4, OUTPUT ); // Channel B input 4
pinMode(bumpLeft, INPUT);
pinMode(bumpRight, INPUT);
Serial.begin( 9600 );
Serial.println("Starting up");
}
void loop()
{
pbRight = digitalRead(bumpRight);
pbLeft = digitalRead(bumpLeft);
Serial.println("Channel A forward");
analogWrite( channel_a_enable, 70);// Speed Defined for Left Motor
analogWrite( channel_b_enable, 70);// Speed Defined for Right Motor
digitalWrite( channel_a_input_1, HIGH);//Right Motor Start
digitalWrite( channel_a_input_2, LOW);
digitalWrite( channel_b_input_3, HIGH);//Left Motor Start
digitalWrite( channel_b_input_4, LOW);
delay(10);// 10 ms loop
if (pbLeft == HIGH){//Left bumper switch close, reverse Main Motors
analogWrite( channel_a_enable, 60);
analogWrite( channel_b_enable, 60);
digitalWrite( channel_a_input_1, LOW);//Left motor reverse
digitalWrite( channel_a_input_2, HIGH);
digitalWrite( channel_b_input_3, LOW);
digitalWrite( channel_b_input_4, HIGH);//Right motir reverse
delay(1000);
allInputsOff();
// Then turn right
analogWrite( channel_a_enable, 60);
analogWrite( channel_b_enable, 60);
digitalWrite( channel_a_input_1, LOW);//Left motor reverse
digitalWrite( channel_a_input_2, HIGH);
digitalWrite( channel_b_input_3, HIGH);//Right motor off
digitalWrite( channel_b_input_4, LOW);
delay(3000);
allInputsOff();
}
if (pbRight == HIGH){//Right bumper switch close, reverse Main Motors
analogWrite( channel_a_enable, 60);
analogWrite( channel_b_enable, 60);
digitalWrite( channel_a_input_1, LOW);//Left motor reverse
digitalWrite( channel_a_input_2, HIGH);
digitalWrite( channel_b_input_3, LOW);
digitalWrite( channel_b_input_4, HIGH);//Right motir reverse
delay(1000);
allInputsOff();
// Then turn left
analogWrite( channel_a_enable, 60);
analogWrite( channel_b_enable, 60);
digitalWrite( channel_a_input_1, HIGH);//Left motor off
digitalWrite( channel_a_input_2, LOW);
digitalWrite( channel_b_input_3, LOW);//Right motor reverse
digitalWrite( channel_b_input_4, HIGH);
delay(3000);
allInputsOff();
}}
void allInputsOff()
{
digitalWrite( 4, LOW );
digitalWrite( 7, LOW );
digitalWrite( 6, LOW );
digitalWrite( 3, LOW );
digitalWrite( 2, LOW );
digitalWrite( 5, LOW );
digitalWrite( 9, LOW );
digitalWrite( 11, LOW );
}