Controlling Devices Through Arduino With Mechanical Switching

by _Ben in Circuits > Electronics

3340 Views, 24 Favorites, 0 Comments

Controlling Devices Through Arduino With Mechanical Switching

picture.jpg

The Arduino can be used to control devices through the use of simple mechanical switches an relays.

Summary of Scope.

Untitled Diagram.jpg

This diagram simplifies in what order events will happen to control a device or devices with the Arduino through the use of mechanical switches and relays. The relays are used to complete circuits that are intentionally being broken but normally complete. Such as power to a device.

Constructing a Switch.

IMG-2058.JPG

I'm choosing to construct a switch, but most any type of switch can used. Mine is constructed from a copper clad circuit board material and a piece of copper tubing. There is a gap carved into the board to create two contacts that the copper tubing can be used to complete a circuit.

Mounting the Switch

IMG-2059.JPG

My switch is being mounted to a bicycle so the rotation of the wheel completes a circuit that the Arduino can read through its analog I/O. The tubing is mounted to the rim of the bicycle....

Mounting the Switch Continued.

IMG-2060.JPG

The copper clad portion of the switch is mounted to the bicycle frame.

Sample Code for Arduino

code.jpg

This sample code uses analogRead and analogWrite commands to read a signal switch input from analog pin 0 and write out to a digital output 9 with the analogWrite command. No code is needed in the "void setup" when using analogRead and analogWrite commands. The signal output from pin 9 is used to control a relay that powers the chosen device.

Controlling the Device

IMG-2062.JPG

The power circuit for the device, that is controlled by the relay, is interrupted by creating a gap between the batteries with pieces of copper clad circuit board placed back to back with leads attached.

Breaking the Circuit

IMG-2061.JPG

Placing the circuit boards between the batteries breaks the power circuit supplied to the device allowing it to be controlled by the relay.

Conclusion

picture.jpg

By using an Arduino to control a relay, a simple mechanical switch can be used to control many different types of devices.