ANY-maze Help > The ANY-maze reference > The I/O page > Making I/O connections > Connecting using generic digital I/O devices > Connecting an on/off input switch

Connecting an on/off input switch

The details given in this topic provide guidance on connecting a switch to generic I/O devices such as the Switch and Sense 8/8. Connecting a switch using the ANY-maze interface is much simpler - refer to the ANY-maze interface topic for further details.

Introduction

The purpose of this topic is to describe the process of attaching an on/off switch (like a light switch) to ANY-maze via some type of I/O device. Thus, ANY-maze will be able to sense when the switch is on and when it's off.

Although this sounds as if it should be trivially simple, you'll find that it can be a little more complex than you might imagine.

  
 Types of input - TTL and opto-coupler 
 Connecting to TTL inputs 
 Connecting to opto-couplers  

  

Types of input - TTL and opto-coupler

The "inputs" found on the generic I/O devices supported by ANY-maze fall into two categories, TTL level inputs and opto-coupler inputs - but what do these names actually mean?

TTL inputs have this name because they connect directly to a TTL 'chip' (for the curious, TTL stands for Transistor-transistor logic). In practical terms this means that the chip will be able to tell when the input is at a "logic high" (around 5 volts DC) or a "logic low" (around zero volts DC) - this is the 'digital' part of computing, everything is high = 1 or low = 0. We'll come back to TTL in a minute, but what about those opto-couplers.

Opto-couplers, as their name implies, 'couple', i.e. connect, your input to the I/O device using light. The big benefit of an opto-coupler is that it isolates the I/O device, and hence the computer connected to it, from the equipment you attach. There are a number of technical benefits to this isolation, but they're beyond the scope of this help - suffice to say that quite a few I/O devices use opto-couplers so you may need to connect to them.

Connecting to TTL inputs

As mentioned above a TTL input should either be held at around 5V or 0V, so our switch needs to connect either 5V or 0V to the input - using a simple on/off switch this suddenly doesn't seem so easy after all.

Fortunately help is at hand, in the form a 'pull-up' resistor. Again, I won't get too technical, but if you look at the circuit in figure 1 you'll see that the resistor connects the TTL input to 5V so the input will be at 5V and the TTL chip will sense a logic 1. Now when the switch is closed the TTL input is connected to 0V (through the switch) and so the chip will sense a logic 0 - bingo, we have our switch connected.

  

  

Figure 1. A circuit to connect an on/off switch to a TTL input

But this leaves a couple of questions - first why do we need the resistor, couldn't we connect directly to 5V, and second where are these 5V and 0V coming from?

The answer to the first question is that without the resistor we would be shorting-out the 5V and 0V lines whenever the switch was closed, this would create a very big current and something would go wrong. The resistor reduces this current to something small (around 1mA) so we can ignore it.

The answer to the second question, where are these 5V and 0V coming from, is that our I/O device will need to provide them for us. In fact I/O devices that have TTL inputs almost always have pull-up resistors built into them, so we won't actually need either a resistor or a connection to 5V. All we'll need is a connection to 0V, usually called GND (ground), and you'll always find a GND output on a connector with TTL level inputs.

In summary to connect an on/off switch to a TTL input you will need to use a pull-up resistor, but most I/O devices have these built in so you can just use a simple circuit like the one shown in figure 2.

  

  

Figure 2. The real-world connections normally required to connect an on/off switch to a TTL input. Essentially the switch connects between the input and GND - this does assume that the input has a built-in pull-up resistor, but most do.

Connecting to opto-couplers

Inside an opto-coupler is a circuit like the one shown in figure 3. Don't worry about the details here, all you need to understand is that when a current flows through the LED it lights-up and this light is detected by the photo-transistor which the I/O device then interprets as meaning that the input is 'ON'.

  

  

Figure 3. An opto-coupler. When current passes through the LED it lights-up and this is detected by the photo-transistor. Opto-couplers create electrical isolation between two circuits as only light passes between them.

So, what this means is that our on/off switch will need to control the current flow through the LED - so it really just becomes a switch in a lamp circuit, like the one shown in figure 4.

  

  

Figure 4. A circuit to connect an on/off switch to an opto-coupler. Although not shown as such, many I/O device have the resistor built-in.

Straight away you'll notice that this circuit includes a battery - does this mean we will need some additional power source (a battery or a power supply) to make our switch work? The answer is yes - and this is one of the disadvantages of using an opto-coupler input for a simple on/off switch.

The next thing you'll notice is that there's a resistor in the circuit, what's that for? The answer is that without the resistor the current that would flow through the LED in the opto-coupler would be very high and would almost certainly destroy it - so the resistor is rather important. Fortunately most device's actually have the resistor built (although it's not shown like that in figure 4).

Finally, you'll be left with one question, what voltage battery or power supply should I use? The answer to this will depend on the device you're using and will be found in its specification, but a typical value is 5VDC, although some devices accept a wide range of inputs, for example the isolated input module of the RTV-24 digitizer accepts any voltage from 5VDC to 24VDC.

Wrapping things up

In summary, it's usually much easier to connect a simple switch to a TTL level input than it is to connect it to an opto-isolated input because you don't need an external power source. This might make you wonder why opto-isolated inputs exist at all, and the answer to that is because they're better for connecting other types of inputs, they're just not too convenient for switches.

© Copyright 2003-2026 Stoelting Co. All rights reserved

ANY-maze help topic T0919