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!

Arduino sensor input

3566 views
6 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    December 2012
  • 4 posts
Arduino sensor input
Posted by D-man on Friday, November 4, 2016 4:23 PM

I am thinking of using an Arduino for controlling several signals. I have a question I hope someone can help with. I want to use the output from my NCE DB20 occupancy detectors as input to the Arduino. Can I connect the DB20 output directly to the Arduino without risking damage to it? What about the output from a Tortoise Switch SDPT? Can it also be connected directly? I've searched the web for an answer to this with no luck.

  • Member since
    December 2012
  • 4 posts
Posted by D-man on Monday, November 7, 2016 6:17 PM
UPDATE: after further research I found that I can indeed directly connect the NCE BD20 output to an Arduino but it is necessary to configure the input pin as pull-up enabled. As for connecting to a Tortoise switch, I misunderstood how the switches work. The voltage used is externally provided and therefore can be limited to a level that is safe to connect to the Arduino inputs.
  • Member since
    July 2009
  • From: lavale, md
  • 4,677 posts
Posted by gregc on Tuesday, November 8, 2016 10:47 AM

D-man
but it is necessary to configure the input pin as pull-up enabled.

in general, an open-collector output is convenient to provide a signal from one device to another.   The problem is each device may be operating at different voltages.   Even if they both operate at 5V, they may be slightly different.

with an open-collector output, the receiving device provides the desired voltage thru a pull-up resistor (e.g. 10k) and the device providing the signal simply grounds the voltage provided by the pull-up or it doesn't ground it allowing the signal to be at the pulled up voltage.   It doesn't need to know what the receiving device voltage is and the two devices can operate at significanty different voltages.

The partial schematic below shows an open-collector output, a single transistor with its collector connected thru "1" to a pulled-up input of a 2nd device.

Figure-2 of the NCE BD-20 manual shows an open-collector output with a capacitor across it.   It sounds like the Arduino inputs can be optionally configured with an internal pull-up resistor.

A mechanical switch can also be used in place of an open-collector output, since both can ground the input.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Tuesday, November 8, 2016 12:11 PM

 Yes, the digital pins on the Arduino have optional internal pullups you can utilize, OR use the traditional external pullup resistors.

 Note that if you hook the Tortoise contacts up to switch an input to ground, you'll almost certainly want to add some debounce logic to your code (plenty of examples on the Arduino site) so that it doesn't flip back and forth between ground and not while the wipers are still moving inside the 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
    December 2012
  • 4 posts
Posted by D-man on Tuesday, November 8, 2016 3:31 PM
I'll have to do some more research and testing. I have not come across any mention of input bounce in what I have read so far but there probably is a good chance it occurs with the Tortoise switch. It may well be a problem with the BD20 as well. Thanks for the advice.
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Tuesday, November 8, 2016 4:47 PM

 SHould not be a problem with the BD-20, there is debouncing in the design of the circuit because otherwise it would flip back and forth between occupied and not occupied if the track was even a little dirty.

 If you've looked at any of the Arduino tutorials it's mentioned in the first one that uses a button to turn the LED on and off. Those cheap tactile switches that come in the parts kits usually have some serious contact bounce problems and as that tutorial explains, when you have a simple program that turns the LED on or off each time you press the button, sometimes you will press the button and the LED will stay off. Or stay on, if it was on - that's not because it missed your press of the button, but because it saw 2 or more pressees even though you think you only pressed once. Code is given to get around that, but if there will be multiple inputs (one Arduino can certainly handle more than one block detector and one turnout) there is a library called Bounce you can use that handles the debouce for whatever inputs you want.

                            --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
    December 2012
  • 4 posts
Posted by D-man on Tuesday, November 8, 2016 5:27 PM
Thanks for pointing out the Bounce code, Randy. You're right about the occupancy detector. I had this vision in my mind of the locomotive loosing contact as it travels along the rails but that doesn't happen as you pointed out.

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

There are no community member 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!