Thursday, June 02, 2016

Circuit Bending Basics: Using a Relay to Simulate A Button Being Pressed

Previously, I've written about different way in which a Teensy or other Arduino-based microcontroller can be used to trigger button presses on a toy.

A relay can be used to the same effect, and may be successful in situations where other methods fail.

A relay is an electromagnetic coil. When a current is passed through the coil of sufficient voltage, the magnetic field physically moves a switch, thus making a connection that was previously unconnected.

A relay will have at least four pins, in two pairs. The first pair is the coil, and this is what is used to open or close the connection. The second pair is the actual connecting contact points that are either open or closed, depending on whether or not the coil is charged. A digital pin on the Teensy is used to control the coil, thus making or breaking a circuit.

In the relay above, the four pins are arranged as pairs, and are perpendicular to one another (one short pair, one long pair). The pair that is the longest away from each other, along the length of the relay, are the contact pair and should be connected to any two points that are to be controlled by the relay. The pair of pins that are the shortest is the coil, and should be connected to the Darlington transistor array described below.

A Darlington transistor array is used between the Teensy and the relay for three reasons. The digital pin on the Teensy cannot provide enough voltage for the relay to trigger. The digital pin on the Teensy cannot provide enough current for the relay to trigger. The relay may damage the Teensy if connected directly.

For these reasons, the ULN2003 Darlington transistor array chip is used as a switching source, with the Teensy pin as an input and the relay as the output. The connections are quite straightforward, as shown below:

• Teensy digital pin 0 is connected to pin 1 of the ULN2003 (red jumper wire)
• Teensy ground is connected to pin 8 of the ULN2003 (blue jumper wire)
• Teensy 5V is connected to pin 9 of the ULN2003 (blue jumper wire)
• ULN2003 pin 1 is connected to one side of the relay coil (white jumper wire)
• Teensy 5V is connected to the other side of the relay coil (green jumper wire)
• One side of the relay contact is going to one contact point of a button press on a toy (orange jumper wire)
•  The other side of the relay contact is going to the other contact point of a button press on a toy (orange jumper wire)

Once this has been set up, a HIGH state on Teensy digital pin 0 will energise the relay, and the two orange wires will be electrically connected. A LOW state on Teensy digital pin 0 will stop the relay, and the two orange wires will be electrically disconnected.

Example code is shown below to turn the relay on or off depending on incoming note on / note off events.






0 comments: