Jump to content
 

DC Loco Control With an Arduino


BG John
 Share

Recommended Posts

Has anyone successfully used an Arduino to control DC locos? I've found a bit about using PWM DC motor controllers online, but nothing that says how well it works. I understand that PWM doesn't work well with all motors, so it may not work on all the various small layouts I'm building, so are there ways to control a conventional controller?

 

I assume that where PWM works, I can just use a standard PWM DC motor controller, and just connect it to the track. Is that right, or are there better and more sophisticated options?

 

Where PWM doesn't work, is there away to replace the potentiometer in the controller (I've got two Gaugemasters) with something that the Arduino can control, or is it practical to operate the pot with a stepper motor?

 

DCC isn't the answer, and I'll be starting a new topic for radio control later, but right now I need to get DC locos running.

Link to post
Share on other sites

I assume that where PWM works, I can just use a standard PWM DC motor controller, and just connect it to the track. Is that right, or are there better and more sophisticated options?

Yes. Last year I used Arduinos to build a wireless control system for a traditional DC club layout. The base units just plug in where the wired hand-held controllers plug in so the the two are completely interchangeable. But using the wireless system they don't keep tripping over each other.

 

The base unit contains a h-bridge motor controller that is directly connected to the tracks. The Arduino (and nRF24L01+) receives the potentiometer value from the wireless hand unit and produces an appropriate PWM output.

 

 

Where PWM doesn't work, is there away to replace the potentiometer in the controller (I've got two Gaugemasters) with something that the Arduino can control, or is it practical to operate the pot with a stepper motor?

You could operate a pot with a stepper motor, but a servo would be simpler.

 

However a better solution might be to use the Arduino to control a digital potentiometer that replaces the existing potentiometer.

 

What type of motors are you concerned about?

 

...R

Link to post
Share on other sites

Thanks Robin. I'm thinking of trying infrared first for remote control, as I'm only building small layouts. I'll try RC later when I've got my head round it, as I don't want to start running before I can walk! I want a very simple control panel on the layout too though. I'm aiming to build up standard systems I can use on all my layouts, and use software to do the fiddly bits.

 

I assumed a stepper motor would move the full range of the pot, but a servo would only give 180 degrees. My controllers have a separate reverse switch. I didn't know digital potentiometers existed, but now I do I'll probably be sending a few more quid to China!

 

I've got a mixture of motors, but as the layouts are different scales and gauges, what will be run on each layout will be different. I've got a 5 pole Tri-ang X04, a few Hornby Smokey Joes with both old and recent chassis, a couple of fairly recent Hornby 0-6-0s, and a few old Airfix and Mainline locos. I've got one Portescap that will only fit on one layout. I've also got an Oxford Adams Radial. Anything else is likely to get something from my stock of cheap Chinese motors, and some of the above may get re-motored, if it improves them.

Link to post
Share on other sites

My controllers have a separate reverse switch. I didn't know digital potentiometers existed, but now I do I'll probably be sending a few more quid to China!

After thinking about this, I was wondering about the reversing switch. Presumably it needs two relays to replace the DPDT switch. Or I could use a servo to operate a standard slide switch. They're both mechanical, so I supposed the servo version can't really be regarded as a bodge!

 

Or is there something else electronical I don't know about?

Link to post
Share on other sites

 

I assumed a stepper motor would move the full range of the pot, but a servo would only give 180 degrees. 

Sail-winch servos can rotate about 3 full rotations with position control.

 

There was a lot of stuff in old Model Railway Journals about controlling Portescap motors. At that time PWM did not seem to be favoured - but it might be worth getting an update from the manufacturers. Maybe high frequency PWM would be OK.

 

I reckon all the other motors would be fine with PWM.

 

...R

Link to post
Share on other sites

Another thing I didn't know about! But they're a lot more expensive than an SG90, and I'm a cheapskate!

 

I can try one of the Gaugemasters on the layout with the Portescap, using a digital pot, as I'd like to see how it works.

Link to post
Share on other sites

I created a Christmas Tree layout using the Hornby Santa Special a couple of years ago, which was controlled using an Arduino Uno and a "Dual Bridge L298N Stepper Motor Driver Controller" ( http://www.ebay.co.uk/itm/Dual-Bridge-L298N-Stepper-Motor-Driver-Controller-Board-Module-Arduino-x1-x3-x5-/181768536409?var=&hash=item2a523fc159:m:mOuIrlio6FObTFYtN6sxFPw ), together with some pushbutton switches for manual start and stop purposes and reed switches to stop the loco at a station and behind the back scene.

 

It was all fairly straightfoward, including the programming.....

 

Speed in this case was set using software, though it would be simple to have potentiometers wired to other input pins and used to set the PWM values manually.

Link to post
Share on other sites

I know this page says DCC, but it's the code that determines DC or DCC PWM :yes:

 

http://www.oscale.net/?q=en/simpledcc

 

The diagram can be used for a DC setup too, just add different code. Connect the brake input of the driver chip to an Arduino port as well, and a logic "1" to that pin will short circuit the outputs.

 

This is the data sheet of the chip:

attachicon.giflmd18200_mosfet_H_bridge.pdf

 

LMD18200 chips seem rather elusive and expensive. It seems cheaper to buy them ready built into a board than just buy the chip, from what I've found so far. Is there any advantage to them over the cheaper L298N?

 

I created a Christmas Tree layout using the Hornby Santa Special a couple of years ago, which was controlled using an Arduino Uno and a "Dual Bridge L298N Stepper Motor Driver Controller" ( http://www.ebay.co.uk/itm/Dual-Bridge-L298N-Stepper-Motor-Driver-Controller-Board-Module-Arduino-x1-x3-x5-/181768536409?var=&hash=item2a523fc159:m:mOuIrlio6FObTFYtN6sxFPw ), together with some pushbutton switches for manual start and stop purposes and reed switches to stop the loco at a station and behind the back scene.

 

It was all fairly straightfoward, including the programming.....

 

Speed in this case was set using software, though it would be simple to have potentiometers wired to other input pins and used to set the PWM values manually.

I've got a few of these on way from China. I'm wondering if I should have bought a version with a heatsink, but they're cheap and I'll find another use for them if I need one.

Link to post
Share on other sites

Personally I'm be happier with the heat-sinked version for driving a DC locomotive. Also the screw terminals allow the board to be incorporated in a circuit without waving a soldering iron about. in addition, it makes it easier to swap it out if you DO fry the controller!

 

As well as the Santa loco, it was quite happy hurling a variety of other Hornby locos about the layout!

Link to post
Share on other sites

The L298 is definitely old technology. There are many newer H-bridge motor controllers on sale. Have a look at the Pololu website for examples. Their stuff is available from UK suppliers.

 

For the system I built i used Toshiba TA8428 drivers from RS Components. But they are also slightly old tech but at the time I could not find a MOSFET chip in a convenient package. Now I think I would be comfortable using an SOIC device - but not any of the smaller IC styles.

 

One thing I reckon is essential is to choose a driver than can withstand short circuits.

 

For my own battery powered locos I am using Pololu DRV8833 drivers - but they have a max of 10v IIRC. I am using them at 3.6v with a single LiPo cell.

 

...R

Edited by Robin2
Link to post
Share on other sites

I have used an arduino to do this in Gauge 3.

 

 

The arduino is a nodemcu connecting to wifi that outputs PWM to a L298 bridge to run I think 9V to the motor.  works well but need to adjust the fequancy to avoid a hum.

  • Like 1
Link to post
Share on other sites

I have used an arduino to do this in Gauge 3.

 

The arduino is a nodemcu connecting to wifi that outputs PWM to a L298 bridge to run I think 9V to the motor.  works well but need to adjust the fequancy to avoid a hum.

Must make a note - no touch sensitive controls ;).

 

I'll be starting a new topic on radio control very soon, as that's planned for a future layout.

Edited by BG John
Link to post
Share on other sites

Must make a note - no touch sensitive controls ;).

 

I'll be starting a new topic on radio control very soon, as that's planned for a future layout.

It did fail that time have since upgraded software and works fine now

  • Like 1
Link to post
Share on other sites

I haven't forgotten this topic, but my Arduino starter kit arrived, and I've been trying other things.

 

I can see the benefit of using newer motor controllers, but do they actually make any difference to the quality of running? That seems to be the most important question to me. On a layout powered from the mains, I don't see that a bit of extra efficiency makes much difference. Battery power is where it matters. Anyway, as I want to get on and make things work, I've ordered a couple of L298N boards with heatsinks, from a UK supplier, to see how they work. That will probably mean the Chinese ones will arrive about the same time!

Link to post
Share on other sites

If you are not concerned with efficiency and if the voltage drop within the L298 does not matter then they should be fine.

 

I can't recall if they can deal with a short circuit. That seems to me essential for any driver that is putting power into the tracks.

 

I know to my cost that L298s do not like reverse polarity from their power supply :)  (I was assured that the black wire was negative and the red was positive and I foolishly did not check with my multimeter)

 

...R

Link to post
Share on other sites

Has anyone successfully used an Arduino to control DC locos? I've found a bit about using PWM DC motor controllers online, but nothing that says how well it works. I understand that PWM doesn't work well with all motors, so it may not work on all the various small layouts I'm building, so are there ways to control a conventional controller?

 

I assume that where PWM works, I can just use a standard PWM DC motor controller, and just connect it to the track. Is that right, or are there better and more sophisticated options?

 

Where PWM doesn't work, is there away to replace the potentiometer in the controller (I've got two Gaugemasters) with something that the Arduino can control, or is it practical to operate the pot with a stepper motor?

 

DCC isn't the answer, and I'll be starting a new topic for radio control later, but right now I need to get DC locos running.

 

If you want to run the motors on DC you could use an analog output from the Ardunio to produce a controllable DC voltage. That voltage will have to be buffered through some sort of DC amplifier to supply current to the track, and you might need a two pole relay for forward/reverse. The DC amplifier does not have to be very sophisticated. There may be a suitable product available but I don't know if there is or not because I make my own (they are cheap!)

 

If you do it that way it might be possible to make the output PWM or smooth DC, or even a combination of both.

Link to post
Share on other sites

you could use an analog output from the Ardunio

The regular Arduinos (such as Uno and Mega and Leonardo) do not have a DAC to produce an analog output. The analogWrite() function produces a PWM output.

 

It would be possible to average that to get a varying voltage with a suitable external circuit - but I can't see any advantage.

 

...R

Link to post
Share on other sites

The regular Arduinos (such as Uno and Mega and Leonardo) do not have a DAC to produce an analog output. The analogWrite() function produces a PWM output.

 

It would be possible to average that to get a varying voltage with a suitable external circuit - but I can't see any advantage.

 

...R

 

That's a bit of a surprise. The information I'm looking at says that the Leonardo does have analog outputs, but I'm no expert on the Ardunio, so maybe I have the wrong end of the stick. Yes, you could average a PWM output to produce smooth DC.

 

The advantage is that you'd be running the motors on smooth DC rather a pulsed DC. DC motors run hotter on PWM, and some get really hot. I believe coreless motors might be the worst, and some cored motors get pretty hot too.

 

My preference is to only use PWM at very low speeds and transition to smooth DC as soon as possible, but it's just a personal thing.

 

EDIT: Added "smooth" to differentiate from "pulsed".

Edited by AndyID
Link to post
Share on other sites

I've always assumed that decent controllers needed some electronics to give good running, as opposed to old fashioned Tri-ang/H&M types that just had a big potentiometer in the form of a resistance mat. So are you saying that just pure DC is needed, and the electronics is only used because a potentiometer can't handle the current? I'm very rusty with all this stuff!

Link to post
Share on other sites

I've always assumed that decent controllers needed some electronics to give good running, as opposed to old fashioned Tri-ang/H&M types that just had a big potentiometer in the form of a resistance mat. So are you saying that just pure DC is needed, and the electronics is only used because a potentiometer can't handle the current? I'm very rusty with all this stuff!

 

Hi John,

 

The Tri-Ang type controller has a variable resistor (a rheostat). Rheostats can be designed to handle lots of current. The problem with that method is that, because the controller output voltage is not regulated, it drops as the load increases. That's why trains tended to slow down or even stall on bends and rising gradients.

 

Electronic controllers (whether "smooth" DC or PWM) don't suffer from that problem (so much) because the output voltage, or average output voltage, is not affected by the load.

 

Some motors tend to heat up on PWM, although it's not a problem for many of them. PWM is good for preventing motors from stalling when they are turning slowly, but it's not necessary once they are rotating at a reasonable speed.

 

So, there isn't any hard-and-fast rule about what's best. It's a case of what works best for the individual enthusiast. My preference is PWM for slow running and smooth DC at greater speeds.

 

Regards,

Andy

Link to post
Share on other sites

The regular Arduinos (such as Uno and Mega and Leonardo) do not have a DAC to produce an analog output. The analogWrite() function produces a PWM output.

 

It would be possible to average that to get a varying voltage with a suitable external circuit - but I can't see any advantage.

 

...R

 

My mistake! I checked. Analog in, but not out. But, as you say, a good analog voltage could be synthesized from a PWM channel.

Link to post
Share on other sites

My mistake! I checked. Analog in, but not out. But, as you say, a good analog voltage could be synthesized from a PWM channel.

I wonder what fool decided to call the function "analogWrite()" when he could have saved himself some typing if he had called it pwmWrite()   :)

 

...R

Link to post
Share on other sites

All my layouts are small, so trains will either be arriving or departing slowly, or shunting. Nothing will be run very fast, or for very long without at least a brief stop.

 

The two L298N boards with heatsinks have just arrived, so I've got most of the bits I need to put a system together for testing. Final assembly can't be done until the postman brings more bits.

 

Overload and short circuit protection was mentioned earlier. Someone on another forum is using these with L298N boards. Has anyone got any comments on whether they're suitable? I couldn't find any alternative products online, so does anyone knows of anything better?

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...