Welcome to the forum   
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post in this topic Go to first unread post in this topic
Offline Big AL  
#1 Posted : 05 December 2020 20:16:19(UTC)
Big AL

United Kingdom   
Joined: 25/10/2020(UTC)
Posts: 55
Location: Scotland, Glasgow


IMG_0518.JPEG

In the video I programmed it to start the loco and ramp up the speed to a maximum speed, hold it there for a set duration then gradually slow down the loco, come to a stop for a set duration and repeat.

The direction of the loco can also be controlled and so can a second loco on a separate circuit. So you could use this for a linear layout. Either using diodes to stop at two stations one at each end of the track, or using Infra Red break beam or Hall effect sensors.

The motor shield can deliver 9V up to 2A without needing relays. The motor shield also powers the logic board on the bottom. In this case I used an Arduino Leonardo for that purpose.

The PWM duty cycle can be set in increments of 255. Here in my demo I go from 0 to 15. The little Marklin loco runs at 1/255th, the Rokuhan Shorty Z I tested will not run below 5/255ths and it squeals and complains below 15. While the Marklin runs perfectly and quietly at any speed. I think that tells a story in itself. Btw, I don't actually know what the PWM frequency is. I am sure it will be out there on the internet is anybody is specifically interested.

Two points I am aware of. One, I should have a 220 Ohm resister on that LED and two, my track needs a good clean! :D

This was actually pretty simple to build and program. The benefit of being a microcontroller is that you can easily add or modify the logic to suit. If anybody wants a how to I am more than happy to oblige and to share the very simple code.
thanks 4 users liked this useful post by Big AL
Offline fbaube  
#2 Posted : 06 December 2020 07:11:15(UTC)
fbaube

Finland   
Joined: 12/08/2020(UTC)
Posts: 21
Location: Uusimaa, Helsinki
Sure, post it! Or place it on (for example) GitHub.
Offline Big AL  
#3 Posted : 06 December 2020 14:16:27(UTC)
Big AL

United Kingdom   
Joined: 25/10/2020(UTC)
Posts: 55
Location: Scotland, Glasgow
Step ONE, Purchase
Buy an Arduino UNO or Leonardo and an Arduino Motor Shield

https://store.arduino.cc/arduino-uno-rev3
or
https://store.arduino.cc...no-leonardo-with-headers

https://store.arduino.cc/arduino-motor-shield-rev3

Note: you can also use cheaper clones. Just be aware some of them are not true clones so Caveat Emptor applies.

Optional: One LED and one 220 ohm resistor

You will also need a 9V power source.

Step Two, Upload the code to the Arduino
Using either the Arduino IDE or the Arduino online editor
https://create.arduino.cc/editor

Copy the code attached

ArduinioSpeedRamp.txt (5kb) downloaded 30 time(s).

into the IDE or editor and upload that to your Arduino board


Step THREE, Wiring
Using this picture as reference
IMG_0518.JPEG

Fit the shield on top of the Arduino and insert the LED + lead in pin 10 and the - in the GND pin. You should really protect the LED by putting a 220 ohm resistor between the + lead of the LED and pin 10, but often I do now bother.

Wire your track to the motor shield. That is the thin yellow and green wires you see in the picture.
Wire your 9V DC power source to the motor shield. That is the *brown and blue wires you see in the picture.
*AN IMPORTANT SAFETY NOTE
The cheapo wall-wart style power adapter I bought from amazon came with like 400mm of lead on it. I extended this lead with the first available two core wire that I had and that happened to be two core mains AC flex. I am only putting 9V DC through this wire.
DO NOT WIRE ANY PART OF THE ARDUINO OR MOTOR SHIIELD TO AC MAINS VOLTAGES. YOU UNDERTAKE THIS PROJECT ENTIRELY AT YOUR OWN RISK.

Possible improvements?
Add another LED to display braking? Currently I use the tiny amber builtin LED on the Arduino to do this.
Add an on off switch
Add a case

When I get some time (whenever that is) I am going to make a super small and more basic version based upon an Arduino Nano and an L298 this would be a lot smaller and cheaper.
thanks 1 user liked this useful post by Big AL
Offline Big AL  
#4 Posted : 15 December 2020 18:22:58(UTC)
Big AL

United Kingdom   
Joined: 25/10/2020(UTC)
Posts: 55
Location: Scotland, Glasgow
I have got the Arduino Nano (clone) prototype working with an L298 board and and OLED display. I have some push buttons for menu control and have some IR detectors too. Still a work in progress as you can see from the picture. I will replace the buttons with a touch pad. I already have implemented some mode functionality and added some preset values.

Modes
0 = run like a regular controller. i.e. speed up then slow down on command.
1 = automated start, speed up, dwell, slow down then pause at halt, then repeat.
2 = (planned) run forwards slow down and stop, change direction, run backwards, then repeat.
3 = (planned) run on track slow down and stop if IR detected. e.g. stop at a platform.
etc... I am open to suggestions.

IMG_0519.JPEG

Cost of this model
Arduino Nano Clone £3.85
L298N board £4.90
OLED Display £5.50
Touchpad £4.49
Wiring £3.00
Total £21.74
thanks 2 users liked this useful post by Big AL
Offline Zme  
#5 Posted : 15 December 2020 19:30:31(UTC)
Zme

United States   
Joined: 02/10/2013(UTC)
Posts: 760
Location: West Texas
Hello, This is a great project. I was thinking I needed a controller which would run the train in one direction, slow to a stop and then change the direction and keep repeating. Previously, such a thing was possible but the stops were very abrupt and unrealistic. I already purchased an IR.

This looks to have solved this problem at a very reasonable price.

Are the components available in the US at such a bargain price?

Thanks

Dwight
Offline Big AL  
#6 Posted : 15 December 2020 19:53:41(UTC)
Big AL

United Kingdom   
Joined: 25/10/2020(UTC)
Posts: 55
Location: Scotland, Glasgow
Hi Dwight, I just checked on amazon.com and I saw all the same components for US customers at similar prices. I am sure you would also find those components on eBay and probably even cheaper if you were prepared to wait on shipping from China. I am sure you could get it all delivered for <$30 if you are patient.

My project is still evolving so don't rush out and buy anything yet, the components might change. It also needs a case!

And, my code has changed drastically from the very first version. It is still a messy work in progress so I will not post the code until it is complete and presentable.

It's definitely a project for those people who are comfortable with mechatronics and who are prepared to troubleshoot and tinker.

The beauty of a microcontroller is that you can program it to do almost anything you want within reason. I also like the digital nature of the control. I can set the exact speed for a particular loco on separate running sessions.

Warm Regards, Al.
thanks 1 user liked this useful post by Big AL
Zme
Offline Poor Skeleton  
#7 Posted : 15 December 2020 20:44:49(UTC)
Poor Skeleton

United Kingdom   
Joined: 09/10/2015(UTC)
Posts: 550
Location: England, Cambridge
Originally Posted by: Big AL Go to Quoted Post

My project is still evolving so don't rush out and buy anything yet, the components might change. It also needs a case!

And, my code has changed drastically from the very first version. It is still a messy work in progress so I will not post the code until it is complete and presentable.

It's definitely a project for those people who are comfortable with mechatronics and who are prepared to troubleshoot and tinker.



Do you know what voltage the motor runs at? I'm concerned that as you're using small duty cycles (15/255) the implication is that the voltage is quite high, and this could be bad for the motors.

Cheers?


Chris
Offline Big AL  
#8 Posted : 15 December 2020 21:15:38(UTC)
Big AL

United Kingdom   
Joined: 25/10/2020(UTC)
Posts: 55
Location: Scotland, Glasgow
Hi Chris, Unfortunately I fragged my multimeter testing a static grass applicator from Amazon. Who knew the multimeter was not rated for 6000V?

All I can tell you from memory is that the output of the L298N is maybe 0.5V less than the supply. So my 9V supply probably comes out of the L298N as 8.5V DC?

Santa is bringing me a much nicer multimeter than the Maplins special that I fragged if I am a good boy that is (oh well!).

The Marklin hardly runs at 1/255 duty cycle and prefers 3/255 minimum to give a reasonably slow speed, but still a little jerky. The Rokuhan Shorty Z's will not run below 8/255 and whine until 14/255 where they actually still run quite slowly but more smoothly than the Marklin as 3/255. The Marklin hardly makes a peep of noise at any duty cycle.

I am ignorant of any theory whatsoever. Is it reasonable to expect that the 8.5V voltage output of the L298N which is directly connected to the track is close to the voltage on the motor?

Is whine from a motor a bad thing if it is moving?
Offline kiwiAlan  
#9 Posted : 16 December 2020 14:23:02(UTC)
kiwiAlan

United Kingdom   
Joined: 23/07/2014(UTC)
Posts: 8,082
Location: ENGLAND, Didcot
Originally Posted by: Big AL Go to Quoted Post
Hi Chris, Unfortunately I fragged my multimeter testing a static grass applicator from Amazon. Who knew the multimeter was not rated for 6000V?
...
Santa is bringing me a much nicer multimeter than the Maplins special that I fragged if I am a good boy that is (oh well!).


Normally a cheap multimeter is barely rated to measure mains voltage, so maybe 400V max.

A good multimeter may be rated to 1000V max.

To measure higher voltages than that special probes are needed.

Offline Poor Skeleton  
#10 Posted : 16 December 2020 20:44:05(UTC)
Poor Skeleton

United Kingdom   
Joined: 09/10/2015(UTC)
Posts: 550
Location: England, Cambridge
Originally Posted by: Big AL Go to Quoted Post
Hi Chris, Unfortunately I fragged my multimeter testing a static grass applicator from Amazon. Who knew the multimeter was not rated for 6000V?

All I can tell you from memory is that the output of the L298N is maybe 0.5V less than the supply. So my 9V supply probably comes out of the L298N as 8.5V DC?

Santa is bringing me a much nicer multimeter than the Maplins special that I fragged if I am a good boy that is (oh well!).

The Marklin hardly runs at 1/255 duty cycle and prefers 3/255 minimum to give a reasonably slow speed, but still a little jerky. The Rokuhan Shorty Z's will not run below 8/255 and whine until 14/255 where they actually still run quite slowly but more smoothly than the Marklin as 3/255. The Marklin hardly makes a peep of noise at any duty cycle.

I am ignorant of any theory whatsoever. Is it reasonable to expect that the 8.5V voltage output of the L298N which is directly connected to the track is close to the voltage on the motor?

Is whine from a motor a bad thing if it is moving?


If the supply is only 9V there's not much chance of damaging the motor, although the L289N does seem a poor choice of driver to be operating from such a low voltage.

At 9V a 15/255 duty cycle equates to 0.5V which would have the motor running very slowly if at all. Maybe the isn't linear, though it's hard to see why or what the extra resolution at high output would be useful for.

It's common for motors to "sing" at the PWM frequency. As far as I know this isn't hazardous, though during my experiments with PWM one of my motors did develop a fault and I'm still uncertain if that was coincidence or due to the PWM drive.

Cheers


Chris
Offline pederbc  
#11 Posted : 20 December 2020 19:46:48(UTC)
pederbc

Sweden   
Joined: 11/06/2007(UTC)
Posts: 180
Location: Eslöv, Sweden
Hi,

Iwould like to add some info to this thread. I've been working on a small Z layout based on one of the Noch preformed. I'm using the motor drive L298 to drive the 2 tracks and IR sensors from ADA-fruit (I think) to get feedback signals. All driven by an Arduino Nano. I use an ULN2003 driver for the turnouts. The IR sensors are of type QRE1113 and fits neatly in the joint between tracks. I use them to control somewhat precise stopping. In order to make good use of the Nano pins, I'm using a cheap remote control that only use one input pin.

Here's a picture of the QRE1113:
QRE1113.jpg

and the motor driver:
Motor driver L298 double H-bridge.jpg

Where I have added the sensors:
IMG_0212.jpeg
IMG_0213.jpeg

I will try to upload a film sequence...

Best regards, Peder
Offline pederbc  
#12 Posted : 20 December 2020 19:55:50(UTC)
pederbc

Sweden   
Joined: 11/06/2007(UTC)
Posts: 180
Location: Eslöv, Sweden
And the movie...
Noch Z.mp4 (3,007kb) downloaded 31 time(s).
Offline Big AL  
#13 Posted : 21 December 2020 01:02:41(UTC)
Big AL

United Kingdom   
Joined: 25/10/2020(UTC)
Posts: 55
Location: Scotland, Glasgow
Nice job Peder!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

| Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.999 seconds.