I’ve been playing with a couple of Arduinos for the last week, and doing some physical computing, interfacing with real devices from the microcontroller. It’s been interesting doing some low level electronics again, and it was a great feeling about half an hour ago to have the model railway running under computer control – using the laptop to send commands over the USB port to the Arduino, which then does PWM to control the speed of the train.
There were a few hiccups along the way – not least of which the Arduino crashed repeatedly when the train started moving – it appears that the power pack I was using didn’t like having its load being PWMed, causing voltage problems. I resorted to running the Arduino off the USB supply, disconnecting the common 12V power input to the board, and just using that external power pack to provide power for the direction change relay and output to the loco. Make sure that you keep the ground connected though, as the Darlington TIP120s need that to be common in order to work.
The eventual use for this project is to automate the model layout in the Corris Railway Museum, and allow visitors to put coins in a slot and the train will then run for a number of returns depending on the coin put in. More coins – the train runs a little quicker. The software allows for reed switches at either end of the line for reversing, as well as reed switches for stations.
The hardware driver circuit is shown here in the schematic below (I know it’s pretty rough, but it’s as good as I can do at short notice), and photo of the really dodgy looking breadboard prototype.
The diodes are 1N4004s and the caps are 0.1μF to protect against reverse current from the inductive loads.
Wow , I have been thinking about hooking up an arduino to an ethernet shield and my model for a while, this looks like an elegant way of doing it! I was wondering what sort of load your setup can take? Would it be capable of powering more than one OO model at the same time?
I have powered 2 N guage models at the same time, but the general idea is to use several of these boards to replace standard DC controllers – I intend in the future to allow a potentiometer input into the Arduino on an analog line and then have the Arduino generate the PWM output to allow smoother slow speed running as well as automatic control when it is needed.
The final setup will probably involve a number of Arduinos comunicating over I²C with ethernet or USB communication to laptop for high level application control. Each Arduino should be able to contro more than one of these motor drive boards (I think about 4 is the limit, though I need to do some tests to see how fast the code will respond) I’ll have to have an Arduino for point motor control, and another to handle user interaction with the LCD output and swich inputs. It’s going to take me a while, but the long term plan is there.
I came across these chips
http://docs-europe.electrocomponents.com/webdocs/0af4/0900766b80af42b5.pdf
which are ~ £2.50 each they offer a full H bridge driver , overload protection, and can have a seperate supply voltage. It would allow the removal of the relay , tip120 and still only use 3 pins per channel (SB pin is not needed). They are good for up to 3.5A per channel so at a push could even do G scale
Awesome blog! Regards.