Change internal logic from relays to an Arduino
Redo
An electronic project at a local science center was showing its age, calling for a refresh: in this case, rebuilding it almost from scratch with an Arduino instead of relays.
A museum exhibit called Buzzwire looks like outlines of two oversized hands giving you a high five (Figure 1). Each hand has a metal handle with a loop, and your goal is to move the loops up and down the hand without touching it. For an even bigger challenge, you can try to do both hands at once in the same or opposite directions. If either loop touches the hands, a buzzer and light come on and the handle vibrates.
The original circuitry for the hands comprised interconnecting timer relays to switch the assorted components. The design had no microcontrollers or anything smarter than a switch, which had several drawbacks – but the main one was that if the puzzle was abandoned mid-run, the light, buzzer, and vibration motor would run continuously until the handles were removed.
Because one of the components had burned out on more than one occasion, the decision was made to rework the exhibit with upgraded technology that addresses some of its problems.
New Tech
To design the new controller, I started with an Arduino Mega because I had one on-site. An Arduino Uno would have worked just as well, but in this case, the Mega is a standard part, is easy to trade out, and is kept in stock. (See the "Physical Rebuild" box.)
Physical Rebuild
While I rebuilt the control electronics, I sent the case out to be rebuilt as well. The original design was made out of plywood and had started to accumulate a lot of dings and scratches. The case rebuild was very helpful because it showed areas that needed to be reinforced. Ultimately, I had the entire front panel replaced with Delrin, a very hard plastic that will withstand wear and tear better than plywood. It also brings a fresh look for anyone that has seen it before.
The physical rebuild also incorporated larger vibration motors in the handles. The old version used pager motors, which were more heard than felt. The machine shop I worked with fabricated new handles from scratch that incorporated larger motors, making the buzz much more noticeable.
I started by assigning pins on the Arduino. The handles each need an input pin, so I started with those. Other than timers the handles are the only inputs to the circuit design. For outputs, I wanted several things to operate with different timing, so I set up four pins to control relays, which will handle both the assorted voltages and the ability to switch things on and off at different times (Table 1; Figure 2).
Table 1
Arduino Connections
Pin | Connection |
---|---|
2 |
Left handle input |
3 |
Right handle input |
8 |
Relay 1 control signal |
9 |
Relay 2 control signal |
10 |
Relay 3 control signal |
11 |
Relay 4 control signal |
GND |
Left hand (puzzle) |
GND |
Right hand (puzzle) |
GND |
Relay board ground |
5V |
Relay board power |
Finally, for ease of connections into the exhibit itself, I assembled everything on a piece of plywood and brought all of the connections to a pair of barrier strips (Table 2). Each hand got its own barrier strip, and the two are identical except for power input on connections 11 and 12.
Table 2
Barrier Strip Connections
Connection No. | Left Barrier Strip | Right Barrier Strip |
---|---|---|
1 |
Hand (sculpture) |
Hand (sculpture) |
2 |
Handle |
Handle |
3 |
Ground (1) |
Ground (1) |
4 |
Ground (1) |
Ground (1) |
5 |
Ground (1) |
Ground (1) |
6 |
12V (switched) (2) |
12V (switched) (2) |
7 |
12V (switched) (2) |
12V (switched) (2) |
8 |
12V (switched) (2) |
12V (switched) (2) |
9 |
Ground |
Ground |
10 |
5V (switched) |
5V (switched) |
11 |
Ground |
Ground |
12 |
12V power in |
5V power in |
(1) Interchangeable ground terminals. Choose one. |
||
(2) Interchangeable 12V terminals. Choose one. |
Logic Flow
Now that all of the hardware was assembled and simple test programs tested the activation of the relays, which in turn vibrated the handle or turned lights and buzzers on and off, I needed to figure out the flow of the control program.
One of the things that is often overlooked in a project is documentation. So as not to fall into that trap, I made copious notes and typed them up into a documentation package. One of the things I included was a flowchart to describe the logic (Figure 3; see the "Flowcharts" box).
Flowcharts
Flowcharts are an excellent way to visualize flow through a system, program, or other process. In the early days of computers when programs were built on punched cards and you "programmed" on paper, they were an essential tool to understand flow. Although still useful for design, they aren't at the forefront, as they once were. Flowcharts are seeing a resurgence, though, in online forms where data moving through a system is now visualized in the flowchart style that once originally designed it.
Walking through the flowchart, the first decision is the diamond right below Start asking whether the ring is touching the puzzle. If not (exit to the right), you wait 250ms, turn off the relays, and return to the original decision. It should be noted that Turn relays off will happen even if they are already off.
If the ring is touching the puzzle (exit the decision through the bottom), then turn the relays on. The next decision diamond checks whether the relays have been on for more than 10 seconds. If so (exit right), you turn off the relays and return to the first decision. If not (exit bottom), just return to the first decision.
That process will loop infinitely until power is removed from the Arduino. You should also note that this flowchart shows a simplified process. I don't specify assigning variables or duplicating the process for both hands, just the theory of operation about what's happening inside the logic. In this way, the program flow is easy for even a non-programmer to follow.
Code
Arduino code is made up of two sections. The setup
section runs once when the Arduino powers up, and the loop
section then runs infinitely until power is removed. As their names imply, they are designed to initialize everything and then run continuously.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.