Hello everyone this is an ir breakbeam that activates a hobby dc motor I want to incorporate a second motor. I know that a 9v 600mah shouldn't run 2 dc mtors but I have tons of l298 and dc hobby motors. Also I used a different code two see if the 2 dc motors will run and it did effortlessly for more than 10 minutes before I took it off. Also the project only requires the motors to be on for 5 seconds.The code works fine with one motor <!!!!!!! Does anyone know what to incorporate in this code to make the other dc motor run? !!!> Here is the ir breakbeam code fully from the adafruit website if needed Arduino | IR Breakbeam Sensors | Adafruit Learning System
#define in3 9
#define in4 10
#define SENSORPIN 4
// variables will change:
int DelayInMilli = 30000;
int MotorTurningTime = 5000;
int sensorState = 0, lastState = 0; // variable for reading the pushbutton status
void setup() {
// initialize digital pin for the motor as an output.
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// initialize digital pin LED_BUILTIN as an output.
pinMode(13, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
// Initialising the motor at off state
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
Serial.begin(9600);
}
void loop() {
// read the state of the sensor value:
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
sensorState = digitalRead(SENSORPIN);
if (sensorState == LOW) {
// turn LED on:
digitalWrite(13, HIGH);
// Set Motor B backward
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(MotorTurningTime);
// Turn off the motor
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(DelayInMilli);
} else {
// turn LED off:
digitalWrite(13, LOW);
}
if (sensorState && !lastState) {
Serial.println("Unbroken");
}
if (!sensorState && lastState) {
Serial.println("Broken");
}
lastState = sensorState;
}