ANY-maze Help > I/O devices supported by ANY-maze > The ANY-maze interface device family > The ANY-maze Digital interface > The ANY-maze Digital interface switch input ports

The ANY-maze Digital interface switch input ports

Contents

This topic contains full details about ANY-maze Digital interface switch input ports and covers:

 An introduction to the switch input ports 
 Configuring a switch input port 
 Connecting to a switch input port 
 Testing a switch input port 
 Switch input port specification  

An introduction to the switch input ports

The ANY-maze Digital interface switch input ports allow ANY-maze to detect when a simple two terminal switch is opened or closed. The interface device checks the switch 10,000 times each second and whenever the switch changes state it sends a message to ANY-maze.

The 'pin-out' of the ANY-maze Digital interface ports is as follows (counting left to right, looking into the port):

 Pin 1Digital port N
 Pin 2GND
 Pin 3Digital port N+1
 Pin 4GND

A switch simply connects between a digital port and GND. So it could be connected between pins 1 and 2 or pins 3 and 4.

  

  

Figure 1. Example of a switch connected between pins 3 and 4 of an ANY-maze Digital interface port.

Internally the digital ports are 'pulled-up' to 5V via a 15K resistor. What this means, in simple terms, is that reading a digital port will usually report the port's state as HIGH. However, if a switch is connected between the port and GND and the switch is closed then the port will read as LOW - this is how the switch input port works. In fact, the ANY-maze Digital interface inverts the signal from the port, so when the switch is open it reads LOW and when closed it reads HIGH.

  

  

Figure 2. Conceptual internal circuit of an ANY-maze Digital interface switch input port. The same circuit applies to pins 3 and 4 as well.

Configuring a switch input port

To configure a port as a switch input, you should open the ANY-maze Digital interface configuration window, select the appropriate port and then select Switch input from the Use this port as a drop down list. This is described in detail here.

When a port is configured as a switch input, some additional options are available in the configuration window - see figure 3, below:

  

  

Figure 3. The switch input port options.

Changing the port's active state

As mentioned above, a switch input port will read as LOW when the switch is open and HIGH when it is closed. By default switch input ports are 'active high', which means that the port will be considered to be active when the input is high, i.e. when the switch is closed. In other words, whenever the switch is closed ANY-maze will consider the switch to be 'active', which is probably what you'd expect.

However, there can be cases where this isn't ideal: for example, consider the case of the step down platform shown in figure 4. Here the animal is normally on the platform, and its weight keeps the platform pressed down which keeps the switch closed. When the animal steps down, the platform rises and the switch opens.

  

  

Figure 4. Example of a step-down platform. Here the normal (inactive) state of the switch is for it to be closed and the active state is for it to be open.

So in this case the 'normal' (inactive) state of the switch is for it to be closed (HIGH) and the 'active' state is when it is open (LOW). To address situations like this, you can change the active state of a switch from 'Active high' to 'Active low'. In the case of the step down platform, this would mean that ANY-maze would report the platform as 'active' when the animal steps down, which is probably what you'd want.

Debouncing a switch input

When a switch closes the two contacts (which are usually springy pieces of metal) often bounce open and closed a few times before they settle down - this is a normal phenomenon, known as 'contact bounce' and generally only last for a few milliseconds. However, consider what happens if the switch is linked to a lever that the animal can press and you want to count the number of lever presses. As the switch bounces open and closed, ANY-maze will count multiple presses, so while the animal only actually presses the lever once, ANY-maze might register 4 presses. Fortunately there's a simple solution to this issue which is to wait a until the switch settles down, i.e. until there are no further changes for some set period, known as the 'debounce interval'. By default an ANY-maze Digital interface switch input port will use a debounce interval of 20ms, but you can change this if you wish.

You might wonder why you'd want to change this interval, but it has an important side-effect: it reduces the number of state changes that can be detected per second. For example, with a 20ms debounce interval, a change from off to on will only register 20ms after it occurs, and a change back from on to off will again only register after 20ms. So a complete cycle from off to on and back to off will take 40ms. This means that changes that occur faster than this won't be registered correctly. In other words a switch input with a 20ms debounce interval will be able to register changes that occur up to 25 times per second, but not any faster than that. In the majority of cases this isn't a problem, but if you think a switch might open and close faster than this then you should reduce the debounce interval accordingly.

Connecting devices to a switch input port

Physically connecting a device to a switch input port is simple; you just need to take wires from each side of the switch and connect them to the port's digital input line and to ground. It doesn't matter which way round you connect the wires. Recall that the 'pin-out' of the ANY-maze Digital interface ports is as follows (counting left to right, looking into the port):

 Pin 1Digital port N
 Pin 2GND
 Pin 3Digital port N+1
 Pin 4GND

So, you should connect to pins 1 and 2 or to pins 3 and 4. In fact the GND pins are the same, so you could connect to pins 1 and 4 if you like (this is important if you change Pin 2 to be 5V).

Testing a switch input port

After you have connected your switch to a switch input port, you will of course want to test it. This is easily done using the I/O page.

 1.Open the ANY-maze Digital interface in the list on the left side of the I/O page. 
 2.Select the interface's Input switches, again, in the list on the left side of the page. 
 3.The right hand side of the page will show all the ports that are configured as switch or TTL inputs; normally they should all be inactive (red). 
 4.Now close the switch - the relevant port should then be shown as active (green) - see figure 5, below.  

  

  

Figure 5. Testing the ANY-maze Digital interface on the I/O page. Here the switch connected to port 1 is active.

If you find that the port seems to be shown as active (green) when it's inactive and inactive (red) when its active, then you probably need to change the port's active state.

If you find that the port doesn't register as active (green) when you close the switch then you should check the wiring and also double check that the port the switch is connected to is indeed configured as a switch input and that you're testing the correct port.

Switch input port specification

 Read frequency10KHz*
 Power output5V (available on Pin 2, if so configured)
 Max power current300mA (USB powered), 900mA (DC powered)

*Note that the default debounce interval makes the effective read frequency 25Hz - more details here.

See also:

 An overview of the ANY-maze Digital interface 
 Setting up the ANY-maze Digital interface 
 Configuring the ANY-maze Digital interface 
 Connecting the ANY-maze Digital interface to your equipment and testing it 
 Using the ANY-maze Digital interface in tests 

© Copyright 2003-2026 Stoelting Co. All rights reserved

ANY-maze help topic T1060