I'm making a small robotic car and designed this circuit on a simulator [attached]. It also works in real life, I get direction and speed control. However I have read many times on this forum that just because a circuit works doesn't mean it's a good design. Also the PWM makes it "sing" which I found a bit worrying - maybe it's normal?
Is this design reasonable and safe, and how could I improve it?
The MOSFET is a logic level type and is activated when 5v is applied to the gate. When the logic PIN of arduino is 5v it goes one way and logic 0 causes the DPDT relay to switch over and the motor goes the other.
I can't help with the circuit but the singing is very likely because of the PWM frequency. By default it's about 1 KHz or 500 Hz (depends on the pin) which is obviously in the audible range. The cure is to push the frequency past 25 KHz (which will probably cause problems for any bats near your house).
Coding Badly - Thanks for clearing up the singing thing.
I'm using the arduino mega2560 I looked here Arduino Playground - TimerPWMCheatsheet for tips on altering frequency, but it looks advanced for an intermediate like me. Is there an easier way? I wonder if anyone wrote a library that does the register stuff in the background and I can just do something like
#include <lazyPWM.h>
setPWMfreq(int Hz);//
although I guess I learn more playing directly with the timers.
The transistor driving the relay coil is wrong, its wired as "emitter follower", rather than
"common-emitter" configuration (which is always used for switching). Google/wikipedia those
terms for more info.
If the motor is large you need a snubber circuit across its terminals to avoid arcing
the relay contacts when they switch (unless you stop the motor before reversing
drive).
Coding Badly- I'll probably use pin 10 on the mega2560.
also thanks MarkT and afremont for the tips about the switching tranny and snubber. At the mo, I'm only using a couple of amps @12vdc, but I want have these scalable so in future I can use larger currents so snubbers will be needed then.
I settled for this DPDT relay design http://www.audiowind.com/pdf/D-128.pdf and a X4 config of my mosfet circuit on perf-board see attached pics. Also with the higher freq PWM.