This is only a preview of the May 2020 issue of Practical Electronics. You can view 0 of the 80 pages in the full issue. Articles in this series:
|
Visual programming with XOD
By Julian Edgar
Instant pushbutton timer
I
n this world of ours, timers abound. We’ve got
timers in our smartphones, timers on our kitchen ovens
and timers built into our watches. So why would we need
a project like this?
Two reasons. First, for ‘standard’ time periods of the sort
you use a lot, this timer can be activated in just moments –
far faster than fiddling with a phone or similar. Second, it
can be easily wired to either operate a piece of equipment
for a pre-set time period, or to sound an alarm when that
period has elapsed (or both).
An example use? I am using the timer together with a
mains-voltage solid state relay (SSR) to operate my soldering iron. I press the button once and the iron stays on for 15
minutes, press the button twice and it stays on for 30 minutes. Three button presses? – 45 minutes. You get the idea.
So rather than glancing up and seeing the iron still switched
on a few hours after I last used it (something that used to occur frequently!), the timer gives me a warning beep when it’s
about to shut down and then turns the iron off, saving power.
Fig.1. The timer is ultra-fast to operate, user-configurable and uses
an Arduino Uno, a pushbutton and a buzzer.
62
The two key elements of the timer are these. (1) A single
pushbutton – that’s the only user control. Each time the button is pressed, it adds another time increment to the timed
period. (2) The length of the time increment is programmable in the software.
So if you set the time increment to 120 seconds (ie, two
minutes), and press the button three times, you have a
six-minute timed period. Or, as in the case of the soldering
iron, if each increment is 900 seconds (ie, 15 minutes), each
button press will add another 15 minutes to the timed period.
So rather than being a universal timer configurable for any
value, you set it up for the specific use you’re making of it.
If you want to cancel the timed period at any stage, just
press the button for a longer time. A long press-and-release
also cancels the alarm if it is sounding.
Another example use? On older cars, the windscreen
washer spray operates only for as long as your finger is on
the switch. Add this timer (and a relay or MOSFET module)
and you can have the spray operate for 5, 10 or 15 seconds,
the time determined simply by how many flicks you make
of the lever. (And in that application, you’d leave off the
buzzer.) I’ve been using this type of timer on one of my cars
for about eight years and its attraction has never dulled.
Hardware
The timer is based on an Arduino Uno controller. These
boards are now available very cheaply indeed. However,
note that the cheapest Uno modules do have one ‘wrinkle’.
Many use a non-standard USB communications chip, which
if you are to communicate with it, needs a new PC driver.
Some users report that Windows can find the driver by an
automatic on-line search, but I had to download the driver
from: http://bit.ly/pe-may20-xod
If you are new to using Arduinos, perhaps initially stick
with ‘official’ products – these don’t need new drivers. The
only other parts that are required are a pushbutton momentary switch and a buzzer that can operate on 5V.
Fig.2 shows the connections, and the port numbers (all
digital – ie, ‘D’) are:
D2 Pushbutton (no pull-up needed)
D7 Output activated during timed period (eg, feeds a
solid-state relay or MOSFET module)
D4 5V buzzer
D13 Optional LED
Practical Electronics | May | 2020
If you want to add a MOSFET board there are lots available; for example, search on eBay for ‘3-20V MOSFET MOS
Transistor Trigger Switch Driver Board PWM Control Module’. At the time of writing, item 303491652040 is just £2.80
delivered. This one is a PWM-controllable MOSFET board,
which will work fine and gives you more options for other projects, but this application does not have to have the
PWM functionality. Still, at this price, why not?
Software
The pushbutton timer program (‘sketch’) is written in XOD
(pronounced ‘Zod’), a free visual programming software
that is easy to follow – and very easy to alter. (For an introduction to XOD see the March 2020 issue of PE.) After
you have installed XOD on your PC (see https://xod.io/
downloads/), you can download the ‘Push-button timer’
sketch from the May 2020 page of the PE website and then
upload it to the Arduino.
Refer to Fig.3, which shows the XOD program. Don’t
panic! Just like a circuit, it’s easy to break it down into its
functional sections.
Starting at the top of the red box, the input of the pushbutton increments a ‘count’ node. Each time the button is
pressed, the count node increments by whatever amount
has been set by the ‘step’ value. This gives us our timed
period. This number is fed to the ‘delay’ node that in turn
operates a ‘flip flop’ that turns on the ‘on during period’
node. (The link from ‘count’ to ‘delay’ is actually through
an ‘if long hold’ node, that I’ll get to in a moment.)
Refer now to the yellow box. When the timed period
ends, another ‘flip flop’ turns on the buzzer for the length
of time selected by the ‘length of alarm’ number running a
‘clock’ node. The ‘on-delay’ (even when set for zero) prevents a tiny switch-on squeak from the buzzer.
Up at the top-left (brown box) is a ‘click-hold’ node that
determines if the button press is short or long. If it is long
(the default is 0.5 seconds) then the time period is set to
0 – ie, it is reset. The sounding of the buzzer is also prevented in this condition – a long button press and release
will cancel the buzzer if it is on.
Note how there’s another input from the same pushbutton (green box) – this operates the buzzer on each button
press, audibly confirming how many times the button has
been pushed.
Finally, the white box shows the nodes used to flash the
on-board LED when the ‘count’ is greater than 0; ie, when
the timer is active. (This feeds D13, and this port can also
be used to flash an external LED if wished.)
The three user-definable constants are:
Value of the time increment
Length of time the buzzer sounds at the end of the
timed period
Length of time regarded as a ‘long push’ of the button.
All these values are in seconds. These are easily changed
in XOD as required – just click on the ‘VAL’ box and then
alter the number in the box in the bottom-left of the screen.
In use
If you wished to use the project as a standalone timer, you
could power it from a USB 5V supply and install the Uno,
buzzer and pushbutton in a box. If you are installing the
device in other equipment, ensure you have a supply of
5-12V available. Switching mains current is most safely
done with a solid-state relay; these have the connections
clearly marked on them.
Conclusion
Until you use a pushbutton timer like this one, it is honestly hard to describe how useful it is. From boiling an egg to
activating a light for a designated time; from timing an exercise session to reminding yourself of a daily activity, I love
it. And, with the wonders of modern DIY electronics, it’s
never been easier or cheaper to make a timer like this one.
XOD files
The XOD file discussed in this article can be downloaded
from the May 2020 page of the PE website.
P ush button
GN D
P W M
Gnd
D4
D7
D2
+ 12V
GN D
+
T o item
und er
control
7
6
5
4
3
2
1
0
SCL
SDA
AREF
GND
13
12
11
10
9
8
–
(O p tional) MO S FET mod ule
DIGITAL
UNO
B uzze
r
+
POWER
Gnd
Practical Electronics | May | 2020
Gnd
A0
A1
A2
A3
A4
A5
5V
RES
3.3V
5V
GND
GND
VIN
ANALOG IN
Fig.2. Just two components need to be
connected to the Arduino Uno – a pushbutton
(between D2 and ground) and a 5V buzzer
(between D4 and ground).
For optional direct electronic control using the
timer just add a MOSFET control module.
63
Fig.3. The sketch, written in XOD visual programming language.
The timed period is set by pushes of the button (red box), turning
on a buzzer when the timed period has elapsed (yellow box). The
green box shows how the input of the button is used to trigger
the buzzer with each press (giving a confirming beep). The brown
64
box nodes differentiate between short and long button pushes,
and the white box nodes flash an LED during the timed period.
Three values may be set by the user – the time increment of
each button push, the length of time the alarm sounds, and the
length of time regarded as a ‘long’ button push.
Practical Electronics | May | 2020
|