So I know to drive a TIP120 transistor you just drive a pin either High or Low for it to turn the switch on or off.

I want to use a pair of these to drive a motor.

Transistor A - Drive the motor in a forward direction.Transistor B - Drive the motor in a reverse direction.

(Transistors in turn are controlling a heavy relay)

My question is, if you are driving the motor with transistor A and you want to switch the motors direction by running transistor B, what constraints can you put in place with the code so that it stops the signal to transistor A BEFORE it runs transistor B? I would really like to not have to worry about both of the transistorsbecoming active at the same time and cause a short.

Write yourself a few functions: MotorForward, MotorReverse and presumably MotorStop. Make sure that the code in them turns one transistor off before it turns the other on. Then, don't directly touch the transistor pins anywhere else in your code.

Note that the "delay" in there is to compensate for relay release time -- I'm assuming the relay will release within 10 milliseconds of letting up the driver. You should adjust those based on the "must release" time in your relay data sheet.

If he is then there is no need at all to worry about the order the relays are energised as taking a motor to the same potential will only help stop the motor before reversing the rotation. In fact it is probable a good idea to have a brief time in this state to prevent damage to the motor.

Kind of makes sense, but I still need to be able to start the motor with a button press from a keyboardexample: a- forward and b-reverse. Haven't really given it any thought, but it would still be feasiblefor the motor to run as long as long as the button was being held and stop when it was released. Actually is there a way to do this? (Would be really great to know)But it would still be great for both relays not to be powered at the same time.

Quote

If he is then there is no need at all to worry about the order the relays are energised as taking a motor to the same potential will only help stop the motor before reversing the rotation. In fact it is probable a good idea to have a brief time in this state to prevent damage to the motor.

This is not really important in this project as the motor will never be free spinning and is driving a system that is more of less a wormgear system. Power stops, motor stops.

Doesn't matter, forward, stop, reverse is always going to put less strain on a motor than forward, reverse.

Yes agreed and it really should be done this way.

Can this be written into the Arduino's code or does it need to be written into a library somewhere?I know the motor shield does this automatically. (different project) but its included in the AFmotor.cpp

Quote

Yes nothing simpler, just test the button and call forward if pressed and stop if not.

Quote

Awesome, just not sure how to write this. Absolutely not a programmer but trying to learn.

I wrote this for another project that uses a motor shield. Even though there is a release for the motor to stop in this code, if you press "w" and then immediately press "s" it will reverse the direction of the motor without needing to press the "k" for the motor to stop. I would like to do something like this with relays. The motorshield system works perfectly, but too low power for this project. Also I think the letter being pressed as would a temporary switch is a great idea too, if I can figure it out.

So since I am not telling the motors in the code to stop before it reverses, I am assuming that it is in the library or somehow else implemented.

A toggle switch won't be much help. For this project I need to be able to control a motor from a remote location, to do this I am simply going to use a keyboard button press through RDP as my trigger. I know with RDP there will be some latency but this really isn't going to be a problem, but also with this latency I think a "momentary button" feel from a keyboard key press would be a much better idea.

I like the idea of

Quote

if(letter == 'F' || pushButton == true) { // do your stuff

although I am sure the coding of this is not quits as simple. It would be nice to know the Syntax.