I want to change polarity of 9 DC motors and turn them on/off but not at the same time. Also, I'd like to be able to have different speed of switching polarity. I did that circuit http://tinyurl.com/czkksm and it works very well (well... it's simple) but now I'd like to wire up that thing with Arduino like this http://tinyurl.com/cwnlp7.
How can I wire the "Direction" and the "On/Off" pins to Arduino?
Which code should I use for activate that circuit?
How can I wire the "Direction" and the "On/Off" pins to Arduino?
Just wire them up to an output pin say pin2 to direction and pin3 to on / off. Control them with a digital write command.
digitalWrite(3, HIGH); // to turn it on
digitalWrite(3, LOW); // to turn it off
with similar writes to pin 3 to change the direction.
In the setup function define these pins as outputs with a:-
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
Those designs look dangerous- please don't run them as-is.
a) there is a diode missing across the relays. It's listed in the components section but not in the schematic. You don't want ~200 Volts to hit your poor arduino, so put an N4001 in there
b) the on/off transistor to use depends on what kind of motor you want to drive. Does it use less than 625 milliwatt ? What's the current? That determines the value of your base resistor as well.
Personally I would pick a MOSFET instead of a regular BNJ transistor- that way you don't have to figure out the correct base resistance.
a) there is a diode missing across the relays. It's listed in the components section but not in the schematic. You don't want ~200 Volts to hit your poor arduino, so put an N4001 in there
Don't worry about the diode, Grumpy_Mike told us enough to remember... but should I add a diode across the motor or across the relay, or both?
the on/off transistor to use depends on what kind of motor you want to drive. Does it use less than 625 milliwatt ? What's the current? That determines the value of your base resistor as well.
Well... actually they are suppose to be electromagnets with V/R = 24/150 = 0.16 A
Personally I would pick a MOSFET instead of a regular BNJ transistor- that way you don't have to figure out the correct base resistance.
Your magnet/motor has a coil and gets switched rapidly by the transistor I'd say add another diode.
At 24V, 0.16A you are looking at close to 4 Watt of power. The N2222 can dissipate about 0.6 Watt. --> toast
Radioshack sells an IRF510 transistor. It's an n-channel enhancement type which pretty much acts like a regular NPN transistor. The max. drain (+) to source (-) voltage is 60V, max. current is 3.0A, max. power is 20W so that's all looking good. If you look at the data sheet you'll see that the gate (=base) switching voltage is somewhere around 3V which should work with any arduino output pin.
At 24V, 0.16A you are looking at close to 4 Watt of power. The N2222 can dissipate about 0.6 Watt
Don't confuse the power dissipated in the load with the power dissipated in the switch these are two completely different things. They don't have to match. Please see:- http://www.thebox.myzen.co.uk/Tutorial/Power.html