Hi. New to Arduino and the intricacies of its programming. I'm building a circuit where I'm using a Nano to control a simple two motor robot. Two QRD1114 sensors and an L298 motor driver are the inputs and output respectively. I've written the following program (I will replace the dreaded delays later). When I check for outputs, the pins I am using for the enables, 8 and 9, will not go high. I'm using a multimeter to check for a high signal but they both remain low. Also, the sensors do not change the motor output states from what was designated in the forward function. The sensor circuit returns low inputs to the Nano when they are activated (verified as working). This reverses motor direction through two functions, one for each sensor. I've moved the enables to within the void loop() and also the forward function with no change in result.
I have tried both digitalWrite and analogWrite (my preference for motor speed control).
I've looked at a ton of examples and cannot see what I am doing wrong. My gut says I am declaring/assigning the pins wrong somehow.
Any input is appreciated.
int enA=8; // assign pin 8 as enable a
int enB=9; // assign pin 9 as enable b
int m1aPin=7; // assign one connection of motor 1 to pin 7
int m1bPin=10; // assign one connection of motor 1 to pin 10
int m2aPin=11; // assign one connection of motor 2 to pin 11
int m2bPin=15; // assign one connection of motor 2 to pin 15
int senaPin=6; // assign sensor a digital input to pin 6
int senbPin=5; // assign sensor b digital input to pin 5
void setup() {
// Setup code to run once:
// Enable pins are set as outputs and used to turn motors on:
pinMode(enA, OUTPUT); //declare enaPin as an OUTPUT
pinMode(enB, OUTPUT); //declare enbPin as an OUTPUT
// Designate motor control pins as outputs:
pinMode(m1aPin, OUTPUT); //declare enaPin as an OUTPUT
pinMode(m1bPin, OUTPUT); //declare enbPin as an OUTPUT
pinMode(m2aPin, OUTPUT); //declare enaPin as an OUTPUT
pinMode(m2bPin, OUTPUT); //declare enbPin as an OUTPUT
// Designate sensor pins as inputs:
pinMode(senaPin, INPUT); //declare enaPin as an INPUT
pinMode(senbPin, INPUT); //declare enbPin as an INPUT
// set the enable pins high to wake up the L298 motor driver
//These are used with PWM to control motor speed
analogWrite(enA,200); //set enA on full speed to start
analogWrite(enB, 200); //set enB on full speed to start
// Start motors going forward
Forward();
}
void loop()
{
//Check to see if the sensors are detecting the edge of the ring
if (senaPin==LOW) {RevLeft();}
if (senbPin==LOW) {RevRight();}
}
void Forward()
{
// Function to turn the motors on to go forward
digitalWrite(m1aPin, HIGH); //set m1a HIGH to start
digitalWrite(m1bPin, LOW); //set m1b LOW to start
digitalWrite(m2aPin, HIGH); //set m2a HIGH to start
digitalWrite(m2bPin, LOW); //set m2b LOW to start
}
void RevLeft()
{
// Reverse motors, turn left, then go forward again
digitalWrite(m1aPin, LOW); //set m1a HIGH to reverse
digitalWrite(m1bPin, HIGH); //set m1b LOW to reverse
digitalWrite(m2aPin, HIGH); //set m2a HIGH to reverse
digitalWrite(m2bPin, LOW); //set m2b LOW to reverse
delay (1000); // reverse for 1 second
// turn
digitalWrite(m2aPin, HIGH); //set m2a HIGH to turn
digitalWrite(m2bPin, LOW); //set m2b LOW to turn
delay (1000); // turn for 1 second
// go forward:
digitalWrite(m1aPin, HIGH); //set m1a HIGH to go forward
digitalWrite(m1bPin, LOW); //set m1b LOW to go forward
}
void RevRight()
{
// Reverse motors, turn right, then go forward again
digitalWrite(m1aPin, LOW); //set m1a HIGH to reverse
digitalWrite(m1bPin, HIGH); //set m1b LOW to reverse
digitalWrite(m2aPin, HIGH); //set m2a HIGH to reverse
digitalWrite(m2bPin, LOW); //set m2b LOW to reverse
delay (1000); // reverse for 1 second
// turn
digitalWrite(m1aPin, HIGH); //set m1a HIGH to turn
digitalWrite(m1bPin, LOW); //set m1b LOW to turn
delay (1000); // turn for 1 second
// go forward:
digitalWrite(m2aPin, HIGH); //set m2a HIGH to go forward
digitalWrite(m2bPin, LOW); //set m2b LOW to go forward
}