How to make a motor work for a specific duration when push button pressed once (works like a toggle, without needing to hold it down)

Vcc1, pin 16 is 5V for the control logic
Vcc2, pin 8 is the motor supply voltage

5V should come from the Arduino
Vcc2 should be a separate power source, a 2nd battery

Thank you soooo soo soooo much. It works! do I need to add a diode? also is there a way to make button1 do its thing only if the button pressed before was button2? and vice versa?

I'm so sorry I'm a bit confused. I do have Vcc1 connected to the arduino's 5v, maybe its not visible because it's behind one of the wires.

presumably you mean each button works once and they have to be pressed alternately?

just being clear what the 2 voltages sources on the h-bridge chip are.

you should have separate batteries for the Arduino Vin and L293 Vcc2 if you expect to run this without a USB connection

Yes

you can add a state variable, it can be a boolean, true/false. only recognize a button being pressed for one state and changes it when recognized

    if (LOW == digitalRead (PinBut1) && ! state)  {
        Serial.println ("cw");
        digitalWrite (PinCw1, LOW);
        digitalWrite (PinCw2, LOW);
        tmr   = true;
        msec0 = msec;
        state = true;
    }

opposite for other button

Thank you so much! It worked!

To check my understanding, I need another battery that I can hook to the barrel jack, because the 5v powers the arduino board, and the other 9 is for the motors?

you can power the Arduino with 9V from either the barrel jack or the Vin pin. you'll need to do this if you don't use USB

the Arduino Motor Shield has a single input for the motor voltage and a 5V regulator that it also uses to feed power to the Arduino

I connected the 9v battery to the power jack, which got the arduino to get powered, but now the motors don't move. I am pretty sure that it is because I removed the the 9v battery that is connected to Vcc2

yes. thought it's been repeatedly said that you need separate batteries for the arduino and motors

Do i need a diode? I know the Hbridge already comes with ones built in

if you know that they already have diodes, why do you ask if you need need to add diodes?

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