Author Options:

need help coding Arduino to drive two 12V DC brushed motors Answered

Hi – I need the coding for an Arduino Mega to (separately) spin two 12V DC brushed motors through a pair of MOSFETs to about 2,000rpm. I’ll be using  Hall effect sensors and magnets mounted on the motor couplings to provide actual speed feedback. Please help or point me in the right direction??
Many thanks



Forgot to mention :(
If you encounter too many problems with balance due to the magnets then consider to salvage an old mouse - the really old ones with a ball inside.
The tiny photo switches around the wheels can be broken in the middle.
If placed at around 60° instead of directly facing each other you can misuse the motor axle as a reflector.
Paint one half or more black and leave the rest (of the diameter) shiny.
Might take some adjusting and fiddling but saves the troubles of an unbalanced shaft.

Check the Arduino Playground and take the examples for one motor as the base.
Same for the hall effect sensors, if not enough in the playground do a Google search for code examples and check what matches your needs.
Be aware that with about 70 impulses per second the Arduino might need additional hardware for the sensors to provide accurate readings.

Many thanks Downunder35m...I'm an Ozzie and a total newbie...

- I'll start looking at the Playground etc..

May I ask what you meant by 'additional hardware' please?

Thanks again :)

In some cases it can make sense to have an external counter included.
That way you only get on impluse to the Arduino while 100 or so get into the counter.
But try first how fast the Arduino can do it before having to worry about more hardware.