Homebrew RC train control: NRF24L01, Arduino, H bridge, Lipo - Page 1
Forum section: electronics / beginners

author: csongor.varga
author_rank: Newbie
timestamp: August 25, 2017, 10:17:03 pm
content: Hi All,I am into large scale model trains, and thinking about doing my own train control. There are RC products available on the market (e.g.http://www.rctrains.co.uk), but I was thinking about doing in cheaper if possible. These would be my constrains:- I want to use a commercially available motor unit / drivetrain modules, which work in 16-18V range (about 2A at full load)- I am no good at building PCBs, so I want to build this from ebay kits.This is what I was thinking:- Power will be provided by 18650s, connected in parallel- Charging and protection will be done by TP4056 board from ebay. I know these charge at 1A, so it will be slow charging up multiple 18650, but that is OK.- Receiver will be build using Arduino Nano and nRF24L01. I will drive the Arduino straight from 18650 via the RAW input. Arduino will powert nRF24L01 with 3.3V- Arduino will drive an eBay H-bridge DC motor controller: I found a few that match my voltage / current rating- Supply voltage for the motor and the controller will be via a LX6009 eBay step-up converter. I can probably go lower like 12V as I don't need great speed.- Headlights (LEDs) will be connected to Arduino pin via transistorI am confident that I can deal with the programming part, there should be lot of examples on the net. I am more concerned about the power side. Can I get away with using cheap 18650s from eBay?Let's assume the motor is drawing 16V 2A at full load (which should be uncommon). That is 16*2/3.7/0.7 = 12 A on the Lipo side (0.7 is the efficiency of the boost converter - I am guessing - at such a low voltage and high power). That just sounds very high. There is no way I can handle so much current with small electronics that can fit in a loco chassis. Also this means if I use cheap 18650 which have capacity 1000 mAh at best, each discharging at 2C means that I need at least 6 in parallel. Does this math sound vaguely correct?Is there an easy way to simply limit the current draw of the motor, making the engine less powerful? Would the boost converter just max out at the 4A rating?I know there are a lot of questions. Any advice would be appreciated.Regards,Csongor

author: Rerouter
author_rank: Super Contributor
timestamp: August 25, 2017, 10:56:57 pm
content: I believe most of the current approaches involve running the motor off the tracks via a h bridge inside. Keeping the power hungry stuff seperate. You would still have enough bulk capacitance and a rectifier for 1s of running if there is a poor contact point.You could then possibly use a 18650 for your control and wifi. So that a gap in the track doesnt knock out your control.

author: csongor.varga
author_rank: Newbie
timestamp: August 26, 2017, 07:25:03 am
content: Sorry, I was not clear. There will be no track power, entire loco will be battery powered.

author: Rerouter
author_rank: Super Contributor
timestamp: August 26, 2017, 07:55:19 am
content: Ok, for completly battery powered, First up, do not have the micro connected straight to the battery, if its a 3.3V micro, use a 3.3V LDO and have it set up to cut out at 3.5V using the regulators enable pin, you dont want it to misbehave when he battery ESR begins rising towards the bottom of the usable voltage.For the stepup, texas instruments planner begins at 81% efficiency for liion to 16V @ 2A and works its way up, so lets say 0.81 for the efficiency for now.Same deal, have the enable pin set to disable the switcher below 3.5V, or have it so the micro can only turn it on, and it defaults off.For the protection IC, you need to make sure that 1. The current sense resistor is correctly sized for > 10A protection threshold, and 2. That the mosfets are sized to handle 10A load.As a ballpark, assuming your running at full speed, your current from the batteries will be about 11A, if thats split over 4 cells, then that is 2.75A per battery, if you used cells better than 2800mah (tested) then your pulling less than 1C and it shouldn't stress the batteries too badly. with about 1 hour of runtime.

author: Ian.M
author_rank: Super Contributor
timestamp: August 26, 2017, 08:05:06 am
content: Brushed low voltage DC motors typically don't mind up to 2x overvoltage as long as the AVERAGE is no more than their rated voltage. Use a 6s series LiPO pack - that gives you minimum 18V and maximum 25.8V. Power the H-bridge at the full battery voltage. Sense the battery voltage with the Arduino (using a potential divider) and reduce the PWM duty cycle proportionately to maintain the maximum motor power equivalent to direct connection to 16V DC. Use an off the shelf 6s LiPO charger with balancing, and off the shelf 6s LIPO protection boards. Use a small buck converter to power the Arduino, radio receiver etc.

author: csongor.varga
author_rank: Newbie
timestamp: August 26, 2017, 12:23:27 pm
content: I am planning to use a TP4056 board which has a low voltage cutoff protection built in. I that case I guess there is no need for a separate LDO. That will cut the power to both the arduino and motor.

author: danadak
author_rank: Super Contributor
timestamp: August 27, 2017, 09:37:06 am
content: Instead of the NZRF24LO1 you might consider using ESP8266 or ESP32. Not difficultto program, can use Arduino IDE, many example projects on NET, Youtube, to buildfrom, and gets you a IP based control. Python for the PC side.Regards, Dana.

author: csongor.varga
author_rank: Newbie
timestamp: August 27, 2017, 09:42:05 am
content: Hi Dana,I have used ESP for other project, but I would like to do this sort of old school, no computers, no network.Csongor

author: Old Don
author_rank: Regular Contributor
timestamp: August 28, 2017, 08:22:32 pm
content: Latest train controls use DCC to control multiple trains on an AC track - AC voltage is +/-14V pulsed at about 10,000 Hz - which varies since the power is also the control data sent to all trains on the tracks. The old variable DC power is dead.With a DCC system the power supply is modulated by "Control Cab" to produce an AC data and power serial data stream. You will need about 2 amps of power to run several HO scale trains. Plus the power needs to be supplied via heavy duty bus bars and not depend upon the tracks to supply power from only one point unless a very small layout. Also, long track runs require booster power supplies running on several power zones. Each booster needs to work with the power cab and each brand of commercial DCC system are unique and mixed brands of boosters can not be used. The only standard is thedata signalsriding upon the power and not the control cabs or boosters. Receivers all receive the same data signals, even when running on different brands of equipment. One of the few universal bits would be the auto reversing power units that get tripped when track reversed upon itself (switches or points) and the engine is receiving opposite power voltages on lead vs. trailing wheels. Right rails and left rails can not touch at points due to the reversed polarity in a return loop. Outside rail in a loop becomes the inside rail etc. when looped.So it is possible to build your own system, but why? By the time you design boosters, power control software and some kind of interface you'll have lots of time into it. Look for a used DCC commercial system and then look into freeware scheduling software that interfaces with most brands. Really not worth reinventing the wheel since debugging could drive you crazy and/or let the magic smoke out of expensive boards.OBTW, several problems occur thatrequireadding capacitors to the train receiver circuit, such as passing over track switches (called points in Europe) where power is lost for a period of time. Dirty track can also be a problem, both for power and for loss of receiving new data from the "power cab". Run away trains happen if data is not received. Each receiver needs to decode data plus rectify the 10KHZ power into DC for the engine. Most receivers also have additional outputs for headlights, backing lights and may have onboard sound generation too. They are quite a piece of work.

author: csongor.varga
author_rank: Newbie
timestamp: August 29, 2017, 03:54:57 am
content: Hi Don,I have commercial models that use Marklin digital (very similar to DCC). This project is all about building something from scratch. I want an old industrial dirty layout. DCC needs a lot of care and cleaning for the trains to run reliably. This is why more people switching to battery operation in the garden scales.

author: picandmix
author_rank: Frequent Contributor
timestamp: August 30, 2017, 10:29:33 am
content: Quote from: csongor.varga on August 25, 2017, 10:17:03 pmHave not used these modules but seems a lot of web chatter about the actual range achievable.What distance are you trying to cover ?This link shows how you can improve the range; if you have not seen it already .https://forum.mysensors.org/topic/1851/extending-range-of-regular-nrf24l01Seems using the newer nRF24L01 + module and a genuine Nordic one is better than the ebay clones.

author: csongor.varga
author_rank: Newbie
timestamp: August 30, 2017, 10:36:45 am
content: Thanks for the comment. For my 10-20 line of sight range is acceptable. In the comments below, they say the printed antenna delivers about 20-30 m. That should be enough for me. I may even consider to have the antenna version in the controller unit as the communication will be one way anyway.

author: tszaboo
author_rank: Super Contributor
timestamp: August 30, 2017, 01:56:36 pm
content: Hi Csongor!What scale are you planning?I think you over estimate the power usage of the motors. Take a look at this:http://www.modelrectifier.com/product-p/0001278.htmThis is good for two engines, both of them have 10W of power. On up to HO scale.That can be easily supplied by a single 18650. You can also reduce the speed a little bit if necessary. Also, they will use much much less power, unless stalled.Dont use cheap 18650. They will claim 2600mAh (or even bogus 10Ah), but the real capacity will be much lower. I have 500mAh 18650s. There is a company, Li-ion Kft (with a logo of a lion. lol. get it?) Budapest, that sells genuine cells, and has shipping.I'm not sure though how easy it is to convert the trains.

author: csongor.varga
author_rank: Newbie
timestamp: August 30, 2017, 02:22:39 pm
content: The model is not fixed yet, but something like 7/8th scale (1:16) on 45mm gauge. So this is like 4-5x bigger than H0.Thanks for the tip on LiPo. But I am also considering the advice above to go for a high voltage LiPo pack to drive the motors directly and have a buck converter for the low power units like Arduino. And I think same capacity 4s LiPo pack would be smaller in volume than 4x18650 in a battery holder.

author: MarkF
author_rank: Super Contributor
timestamp: August 30, 2017, 07:05:07 pm
content: Hi Csongor,I take it that you're looking at the outdoor (garden) scale trains? I'm working on a HO layout myself and also building the throttle from scratch. Do the garden scale locomotives use AC or DC voltage?I did a little work with the nRF24L01+ modules. It took me some time to understand and program two of them to talk to one another using pic16f877 microcontrollers. I didn't try a distance test. But from some youTube videos, people have had varying success. Everything from just one room to from a 2nd floor to the ground. I believe the 10 to 20 meters to be very optimistic at best.

author: csongor.varga
author_rank: Newbie
timestamp: August 30, 2017, 08:44:34 pm
content: Yes, it is a simple DC brushed motor.

author: James_EAC
author_rank: Newbie
timestamp: November 30, 2017, 02:53:04 pm
content: https://youtu.be/dJpCXQvnozcI think put a MOSFET before the relay to ground and gate pin with PWM

author: soligen
author_rank: Contributor
timestamp: November 30, 2017, 03:30:06 pm
content: I developed an RC FHSS protocol using NRF24L01 and an arduino for flying RC models. I haven't done trains so I don't know if this would help you, but you can check it out athttps://github.com/soligen2010/RC_RX_CABELL_V3_FHSS

author: Old Don
author_rank: Regular Contributor
timestamp: December 01, 2017, 01:59:26 am
content: Rereading this I wonder why not use RC car/truck controller. These things are battery operated and controllers are off the shelf and drive motors plus have function controls for lights etc.

author: csongor.varga
author_rank: Newbie
timestamp: December 01, 2017, 07:05:45 am
content: Sorry Guys, I must have missed the notifications.James_EAC: nice tip, interestingSoligen: thanks for the github project, I will take a lookOld Don: you are correct, I just want to do it cheaper. Assuming somebody is now to RC, buying a transmitter, receiver and ESC can really ad up. On the other hand Arduinos, RF2401 nowadays a buck each.

author: Old Don
author_rank: Regular Contributor
timestamp: December 01, 2017, 04:42:22 pm
content: Take a look at:https://www.banggood.com/Payne-Open-Source-Arduino-DIY-Remote-Control-Transmitter-Kit-With-PPM-Output-For-RC-Airplanes-p-1225954.html?rmmds=search&cur_warehouse=CN