Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Lighting with Ardunio?

2032 views
22 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, October 23, 2020 12:53 PM

Overmod

This is now perhaps the best thread I've read here about using servos for switches, better than the one we were complaining about 'trolling' on a few months back.

It's almost worth the idea of setting up something like a 'sticky' with a correct topic, and moving the off-topic servo material to it from this thread and continuing the discussion there.  In fact I encourage the people contributing to the discussion do exactly that with a new topic which mods could then make sticky...

 

Sounds good to me, I’ve kinda dinged Harold’s post.  Why don’t you start the new thread Overmod?  Randy and I can do our thing on your thread.
 

Mel


 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Friday, October 23, 2020 12:29 PM

 Well, if I stop making changes and finalize my design, I will create a thread about my system. The final version will be freely available - both the PCB layout and the firmware, because I am not the least bit interested in selling anything. I do think I'm done, I'm almost to the point of putting down the first track so it's time to have the control available. I just need to make a 'front panel' PCB for the buttons. Rights, lefts, and crossovers - aththe price you can get panalize PCBs for, it's the cheapest option, bright silkscreen on a dark background probably.

                                 --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    September 2003
  • 21,669 posts
Posted by Overmod on Friday, October 23, 2020 11:55 AM

This is now perhaps the best thread I've read here about using servos for switches, better than the one we were complaining about 'trolling' on a few months back.

It's almost worth the idea of setting up something like a 'sticky' with a correct topic, and moving the off-topic servo material to it from this thread and continuing the discussion there.  In fact I encourage the people contributing to the discussion do exactly that with a new topic which mods could then make sticky...

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, October 23, 2020 10:19 AM

Sorry Harold for commandeering your post.
 

Mel


 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, October 23, 2020 10:12 AM

Randy

I drilled a #64 clearance hole in the .04” Styrene sheet for the .03” rod at the X as the pivot point.

I cleaned up my drawing a bit to sorta clarify my design.


Double click to expand
 

Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Friday, October 23, 2020 7:59 AM

 Is the wire fixed to the servo anywhere but the hole in the horn? It would seem to me that an arrangement like that, the only thing keepign the points in place is the friction of the wire in the throwbar hole, that the points could easily be pushed against the setting without even trying. The style of mount liek the Tam Valley ones puts the base of the servo against the underside (I have one I use for testing that I stuck right to the bottom of the turnout - but on the layout they were under the benchwork, not dropped in from the top). This allows there to be some pressure on the wire even when the servo stops moving and is back to idle power. 

                                     --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, October 22, 2020 6:59 PM

Randy

I tried several servo mountings and this one seems to work the best and easiest to install.


The servo is attached to the bottom of the Atlas Custom line turnout.  It drops into a 1½” hole.

The one I have installed on my layout works very nice except the positive point rail pressure.

I’ve tried several different diameter rods to move the points and with out checking the one installed I think I ended up using .02” steel rod.  To keep pressure on the point rail the servo draws about 50ma and at 50ma the Tower SG90 Pro servo gets hot.  I know its only ¼ watt but the motor gets hot after about an hour.  The total actual servo current is current is 68ma, the electronics draw 18ma at idle and the motor draws 50ma to keep pressure on the point rails.

The servos are powered from the same 5 volt power supply that feeds the Arduino, the servo doesn’t use the Arduino regulator.
 

Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, October 22, 2020 6:34 PM

 WHat sort of linkage are you using? With a tick-tock wire like a Tortoise, running Atlas turnouts, there was still spring pressure in the wire even with the servo powered off. The servo may have drifted back a bit, but there was still spring pressure holding the points closed. 

http://tamvalleydepot.com/products/servosaccessories.html

Look at the pictures on Tam Valley's page. The way these work is that as the servo arm moves back and forth, the wire moves side to side pivoting at the hole in the mount it goes through (the equivalent of the fulcrum hole on a Tortoise). The servo can move past the point of moving the points, which bends the wire. Try to go too far and the servo stalls, buzzes, and overheats, but pick an in-between stopping point and the servo can reach it without stalling, yet there is still spring tension on the wire to keep the points held in place. There's really no magic in the programming, just a min value and a max value to use in your stepping so the servo doesn;t move past those points.

 And that's maybe where you and speedybee went wrong - you don't simply issue a servo move command to one endpoint or the other - they go too fast and it makes a lot of noise. You need to loop and step them from one extreme to another. The size of the steps is and the time between each new servo command is what determines how long it takes to get from one endpoint to the other - a step of 1 is way too slow, I use a step of 2 (so far - might change as I play around with the circuit). The Servo library allows endpoints from 0 to 180, which is supposed to be the degrees of rotation. Most of these servos can't actually go all the way from 0 to 180 - I've been using 20 to 140 but again once I get the first one mounted, I may need to adjust those endpoints to keep from stalling the servo, but for now they work. I step through the loop ever 50ms. These are the only 'tricks' to make smooth servo motion. The same thing is what you would do to use a servo for some other animation - it needs to be stepped slowly through the range of motion so, for example, the brakeman is swinging his lantern, not whipping it into orbit.

https://youtu.be/Y8OvWW0RFbE

My video shows the difference between the cheapos and the TowerPro ones. The circuit and the sketch are exactly the same, all I did was unplug one servo and plug in another. The only sound you hear on the TowerPro ones is the click of the microswitch on the mount. 

                                --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, October 22, 2020 4:01 PM

Randy

I haven’t piddled around with my turnout servos in about 4 months.  All my servos are Tower SG90s.  They work super on my Atlas Custom Line turnouts but I would like them to keep a bit of pressure on the point rails.  If I set the servo to stop at say 50ma then disconnect the signal to the servo the servos will coast back.  The point rails stay but no pressure.  I have one servo controlled turnout installed on my layout and it works but with not enough pressure to give me the warm and fuzzy feeling I need.  I can see the point rails relax as the servo coasts after the servo doesn’t have drive applied.

All the regular switch machines give me the feeling I need.  I need to keep a few ma on the servo motor to keep it from coasting and relaxing the point rails.

When my arthritis pain is around 8 I can’t do much work on anything and when its above 8 working with tools handy would cause a lot of goodies to end up at the County Dump, pain goes up the lack of patience increases x2.
 

Edit:

My answer would be to add a Peco spring to every Atlas turnout.





Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, October 22, 2020 3:00 PM

 Some of the Tam Valley servo controllers automatically detect the endpouints of the servo. I presume they do so by measuring the current. Tam Valley controllers are all various PIC micros, not Atmel, but it should be possible to add the same thing using the analog pins of the Arduino. But that seems like excessively complicated - it's not that difficult to set endpoint limits - I just use some constants defined at the top of my program. My goal is to keep the mount and method simple, so they don;t need to be tweaked to the point that every single servo needs different settings.

 THe bottom line is - don't drive the servo from one extreme to the other - there's no turnout that needs that much range of motion to throw all the way. But I doubt an SG90 servo will break an HO turnout. Maybe N scale, if pushed too far. But stalling them out is defintiely a no-no, that's when they got hot and burn out. That MR article on converting them to simple toggle switch controlled stall motors - if that guy is actually doing that on his layout, he's probably repalced every one of them at least twice by now. Although perhaps the motor itself can take it, just not the electronics in the servo. Stalled and prevented from moving, even the little SG90s can draw over 1 amp - moving against the slight resistence of a piece of piano wire and a typical HO turnout, even a Peco with the spring still in it, they don;t even hit half an amp peak.

 Noisy - well, even the cheap ones I used on my last layout (but with Tam Valley controllers) were no louder than a Tortoise. As mentioned, I got some of the genuine TowerPro SG90 servosm, instead of the cheap eBay knockoff ones, and they are virtually silent, and move MUCH smoother than the cheap ones, this time on my homebrew controller. Well worth the extra money - still cheaper than a Tortoise.

 A servo could be connected EXACTLY the way shown on the pictures of the motors, though you would have to bury them a bit deeper since they are taller than the motor. The horn on the servo would connect to the wire or pwper clip going to the throwbar. You just have to reduce the throw from the full extension - most sample "how to use a servo with Arduino" sketchs simply move it from one extreme to another - just reduce the range. Or put the servo under the layout, you cna do that as simply as using Gorilla Glue to stick it to the bottom, with a hole under the throwbar, and the wire poking up, just like a Tortoise.

                                         --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, October 22, 2020 12:13 PM

Speedybee

Randy has the servo fix but I have to be in an Arduino Sketch Mode to work with Arduino programming and that will be awhile.  The older I get the less patience I have and I didn’t have much to begin with.  Writing Arduino Code isn’t my thing.
 

Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, October 22, 2020 11:54 AM

I do the Arduino design work on my computer and I make drawings of all my projects including the Arduino expansion boards. So I can print out the boards in actual size for cutting, installing parts, wiring and connector pinouts.  My drawings also have the Arduino pinouts for helping with the designing.



Anyone wanting one of my drawings drop me a PM with your email address and its on the way.


Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    December 2016
  • 168 posts
Posted by speedybee on Thursday, October 22, 2020 11:44 AM

RR_Mel
I have a couple of servo project that work very good but still piddling around trying to get a servo to work as a switch machine.  Not satisfied with the point holding current, the servos heat up quickly under a small amount of stall current. 

I first also experimented with using cheap servos as turnout motors and found them lacking. Very fiddly to set up, malfunction somtimes, and they can apply so much force that I was concerned they could break something.

After much trial and error (mostly error) I now have great success using small geared DC motors as stall motors. I've tried a few models, my favourite is the metal and black one seen in two of the three photos. They cost a buck or two on eBay. They're around 1/2" thick and 1" in size, so they can be jammed in relatively tight spaces, though the white plastic model shown in one photo is even smaller.

metal motor 1

metal motor 2

plastic motor

Regardless of which motor I used, the principle is the same... attach an arm made out of paper clip or safety pin or whatever to the output gear and either have the arm directly move the throwbar, or via a linkage. I drive the motors with constant current 60mA. It provides enough power to reliably switch the points, but not so much that I worry about breaking the turnout or overheating the motor.

I can provide further details or schematics if anyone is interested. I have 9 of them installed and so far they've been working flawlessly, albeit it's only been a couple months and a couple hundred switches, so not exactly a long term test.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, October 22, 2020 11:42 AM

wolfman hal

Mel

Is there a place that explains all the different hole connections on a expansion board? I can understand the simple ones such as additional  5v & GRN connections. 

Do these expansion boards expand the number of PINS? 

I have a ELEGGO board. I tryed there website with little results.

Harold

 

The expansion boards I buy are blank, depending on which one you get some have the Arduino pin numbers printed on the board.

You can position any connectors or parts anywhere on the boards.  Any number of pins on any number of connectors, I even make my own conectors with weird pin arrangements.

I made these NANO expansion boards.




This is my UNO expansion board for my crossing gate controller.


This is an early UNO with the high current driver chips and monitoring LEDs.  I no longer put monitoring LEDs on my Arduino projects, wasted effort.

This is a MEGA board with connectors, no wiring or parts.



I buy the expansion boards off eBay from China, the price is right the delivery not so.  I sorta stock my Arduino stuff in advance so I don’t have to wait for the slow boat.

The frame above the MEGA board is a Mel card cage, It will hold 7 UNOs or MEGA board with one expansion board and one MEGA with two expansion boards (far left). I have a lot of Arduinos, two card cages.


 
 

Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Thursday, October 22, 2020 11:26 AM

the D pins (e.g. D8) are digital I/O pins  that are typically used for simple on/off outputs are sensing a binary input

the A pins (e.g. A1) are analog pins that can measure varying voltage levels between ground and  5V using analogRead().   they can also be used as digital I/O pins.

arduino uno pins

greg - Philadelphia & Reading / Reading

  • Member since
    January 2019
  • 158 posts
Posted by wolfman hal on Thursday, October 22, 2020 11:09 AM

Mel

Is there a place that explains all the different hole connections on a expansion board? I can understand the simple ones such as additional  5v & GRN connections. 

Do these expansion boards expand the number of PINS? 

I have a ELEGGO board. I tryed there website with little results.

Harold

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, October 21, 2020 10:26 PM

If your object is MyServo, just do Myservo.detach() after it reaches the endpoint. When it's time to move it again, Myservo.attach(). When you send it the first position command, it needs to be the same as the last known position, or close, so the servo doesn't jump.

 And the servo makes a difference - I've been using the cheap SG90s from eBay. I got a couple of Tam Valley switch machines (servo, mount, and microswitch) which use the real TowerPro servos. I did all sorts of things in my program to try and keep the servos from wiggling during program initialization when I first turn the circuit on, and it's mostly fixed but still does it a little. I hooked up one of the real TowerPro servos - NO WIGGLE. Also they are nearly silent. So no more el cheapo SG90 knockoffs for me, I'm going to use the genuine TowerPro ones from now on. I posted a video showing the sound and smoothness difference. Actually, I'll probably just buy the Tam Valley machines, my latest version of the circuit drops the relay for frog control and I cna just use the microswitch for that. I need some sort of servo mount anyway. And since this layout is just 3/4" plywood and no foam to the track, the included piece of wire is long enough and stiff enough, if I remove the springs from my Peco turnouts. 

                           --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Wednesday, October 21, 2020 6:11 PM

Randy

How do you remove the servo signal?  I haven’t had any success at dropping the servo drive.
 

Mel


 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, October 21, 2020 5:07 PM

 You need to not think of servos as stall motors. They will always continue to try and move to the command position, so the endpoints need to be limited to as far as it can physically move the points and the linkage. Also over thick piano wire will either prevent the servo from reaching the throw limit, or push it back if power is cut. My last layout ran the wire through 1/2" plywood, 4" of extruded foam, and standard HO cork roadbed before reaching the turnout throwbar. I used either .037 or .039, have to find my stash of leftovers to knwo for sure which, but that gave PLENTY of force to move the points and keep them pressed against the stock rails - with a snap, if you manually moved them away and let them snap back. The give in the wire allowed the servo to reach the set endpoints.

 On my own controllers, I also stop the signal to the servo at the endpoint. This effectively removes power - with no command signal, the servo doesn't try to turn, so it draws no current. The slight tension on the music wire is plenty to hold the points closed and doesn't exceed the force required to move the servo aginst the internal resistence of the gears, so they stay put.

                                   --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Wednesday, October 21, 2020 2:04 PM

I have a couple of servo project that work very good but still piddling around trying to get a servo to work as a switch machine.  Not satisfied with the point holding current, the servos heat up quickly under a small amount of stall current. (point pressure)
 

I buy the blank expansion boards on eBay

https://www.ebay.com/itm/10Pcs-KEYESTUDIO-Prototype-Circuit-PCB-Board-Shield-Starter-Kit-for-Arduino-UNO/132729452760?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2060353.m1438.l2649



Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    January 2019
  • 158 posts
Posted by wolfman hal on Wednesday, October 21, 2020 12:39 PM

You are still a liitle over my head but I am getting closer. The wired board you are showing looks like the Expansion Module Shiels V5 I have in my kit. 

Your answer that it can be done will help me to work out the projects. I have just finished 10 LED lighting projects with Ardunio that are working great.

I am now looking in the kit at Servos.

Thanks

Harold

 

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Wednesday, October 21, 2020 11:03 AM

I use incandescent bulbs in all of my structures and now drive them with Arduino Random Lighting Controllers.  The Arduino won’t drive the bulbs directly, too much current.  I build up expansion modules using seven channel driver chips that have 500ma per port.  The UNO with the driver board will randomly turn on and off 20 bulbs.



I have post on my blog for my controllers.

 https://melvineperry.blogspot.com/p/blog-page_27.html
 

I have 8 UNOs driving 20 lights in 8 houses, they look lived in.



Mel



 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    January 2019
  • 158 posts
Lighting with Ardunio?
Posted by wolfman hal on Wednesday, October 21, 2020 10:48 AM

Can you use Ardunio UNO to connect to regular model incondesent model light bulbs?

Harold

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!