Using Touch Toggles with Microcontrollers

Note: Before going on with this page you may want to read Using Touch Toggles with your own electronics

Tam Valley Depot Products

It happens that Tam Valley Depot fascia control inputs need a momentary contact switch to ground. This design is provided in our Touch Trigger controls. Now you can have touch controls that directly operate your Tam Valley equipment. When operating with the Tam Valley Depot servo controls the indication on the control will change even if the switch is thrown by DCC!


The Arduino and Touch Toggles are a perfect pair. A number of “sensor shield” designs are available that provide each I/O pin of the Arduino with a 5v pin and ground pin in a neat row, exactly matching the Touch Toggle plug. With a sensor shield, Touch Toggles can plug directly into an Arduino. Similar shields are available for Arduino Megas too for really large projects. We also offer adapters to the Grove System for plug in simplicity.

Raspberry Pi, PICs and Other Controllers

All 5v logic-level inputs can read input from a Touch Toggle. Green is high, and Red is low.

Touch Toggles have a strong enough output to work with almost any 5v electronic logic at either TTL or CMOS logic levels. Each Toggle has an internal 20k pull-up resistor, and a common collector drain to ground which is open on Red. There is a 1k resistance before the output to prevent accidental damage to the Toggle. This arrangement provides about .2v (red) to 4.7v (green) into any high impedance input. Circuits that have their own 4.7k pullup resistors will read about 1v in the low (red) state. We offer an Inline Signal Booster for systems with high current TTL pull-up resistors.

Technical Notes and Geeky Stuff:

Controlling the Indication

It is neat trick to over-ride the native indication of a Touch Toggle using code from an Arduino or other microcontroller device. This is really handy when mixing the Toggles with computerized or DCC operation. In cases like these, you might want to change the indication sometimes without touching the Toggle.

The trick is to set up a loop in your code that alternates between checking to see if the button has been pushed and forcing the sensory lead high or low to make the Touch Toggle show green or red. Every tenth of a second or so the controller pin to the sensor lead is switched to an input to read the logical output value present in the Toggle. Once read, the pin is switched back to the desired output value to override the indication in the Touch Toggle. Repeat. This looping code is a super simple method of multiplexing the in and out on one wire.

On the Toggle, the logic output has an inline 1k resistance that makes sure the over-ride current will never exceed 5ma.

The loop should be set up as part of a state machine in the code, so that lots of timer loops can be occurring at the same time without interference. This is the only safe and sane way to setup any multi-tasking code so that none of the tasks will trip up the timing of all the others. Click here for a really good intro to state machines on Arduinos.

Using the standard Touch Toggle in the indicator/sense loop is very stable since each Toggle will remember it’s having been touched, no matter how long the loop may stop while other tasks are performed.

We also offer two-indication Touch Triggers. These are just like our standard Touch Toggles, but with a momentary output instead of the latching; touch on/touch off. Momentary operators often allow a simpler code, and lets the system see when a finger is removed, as well as when it first arrives.

Since the indicator on the Touch Trigger momentary control will always show green and then show red when touched, it has no useful application without the program loop controlling its display. Click here to read more about Touch Triggers.

Please let me know if you have any ideas to add here, or if you need further guidance. I hope to post some example code when I can get a free moment.

Kevin Hunter

443 527 6320


Comments are closed.