Simple code addition to make second dc motor run on l298 , help needed


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;
}

First you need to connect IN1 and IN2 to the Arduino, maybe use pins 11 and 12.
Make sure there ar jumpers on enA and anB

Yes thanks , so after I connect IN1 and IN2 to to arduino pin 7 and pin 8 how do I incorporate that code with the original code. Also is it necessary/mandatory to use enA and anB?

This should help you figure it out:

Thanks for attempting , but that won't help me incorporate the code.

There may be another that is willing to write the code for you but if you read and understand the tutorial you should be able to do it yourself
Is there something you don't understand?

thanks jim , i paid for someone to do the code for me on outwork it was only 50$ for my hobby project figured it was an easy fix to just incorporate. Much appreciated

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.