DesignSpark Electrical Logolinkedin

Arduino Powered Useless Machine

I saw this project on Arvid Mortenson's website while browsing the internet and thought it would be fun to build my own for our Inner Geek competition at RS.

The idea is simple enough. It is a kind of modern day jack-in-a-box. It just sits there tempting the user to switch it “on”. When you do, the lid opens and a mischievous little leaver emerges and switches itself back “off” again. Each time you activate the switch you get a slightly different pattern of behaviour but it just keeps switching itself off, whatever you do.

As I started to think about how to build such a machine, I realised it was not as easy as I had though. To start with, the box does not actually switch itself off, it just appears that way. It needs to respond quickly to being switched on, so after initialisation the Atmega328 microcontroller inside actually goes to sleep. The box needs to remain active for long periods of time but the servos consume power all the time and would quickly drain the batteries so something needed to be done about that.

I ordered all the parts from RS and decided to prototype the design using an Arduino Uno and breadboard to connect the parts. Then I got to work on building the box out of hardboard to house everything. This took some trial and error but eventually the lid and arm servos where in place and I was able to write as small program using the Arduino Servo library to control the servos and calibrate their starting and stop positions. I then added the IRLZ14PBF N-channel MOSFET to isolate power to the servos during the sleep mode. I connected the gate directly to one of the digital outputs on the Arduino which goes HIGH to switch the MOSFET on. The problem was, it did not always go LOW reliably so I added a pull down resistor to sort out that problem.


Next step was to write the main code to put the microcontroller to sleep and wake it using the switch to activate an interrupt service routine (ISR). On the Arduino, only pin D2 & D3 can be used for this. The goToSleep() function uses the deepest sleep mode to save power. It also attaches the ISR. The attachment of the ISR routine is protected to guarantee that it takes place successfully:

void goToSleep() {
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
noInterrupts (); // Protects attachment of ISR
attachInterrupt (0, wake, LOW);
EIFR = bit (INTF0);
interrupts ();
sleep_cpu ();

It took a while to develop reliable code to wake the processor every time. I used an excellent reference by [Nick Gammon] who really covers all the details of saving power on the AVR microcontroller and using interrupt service routines.

The wake() function does what it says and wakes the processor allowing the MOSFET to turn on and the servos to activate and run their routines before going back to sleep again.

void wake(){
detachInterrupt (0);

Another thing I found useful was adding a small LED which comes on when the switch is activated. This was very helpful during debugging to show the processor was actually awake, even if it was not responding correctly.

Once all the code and the mechanism was sorted out, it was time to start up DesignSparkPCB to create a schematic so I could build a permanent version of the circuit. From the datasheets, I calculated that using 4 x 1.2V, 2600mAh rechargeable batteries, both the servos and microcontroller could be powered without using a regulator. This enabled me to pare back the components on the Arduino board to the bare bones. So just a processor, crystal and reset button plus the MOSFET and a few capacitors and resistors. I clocked the Atmega at 16MHz but you could probably go down to 8MHz to save even more power. There are a few essential filter capacitors and also a 100uF electrolytic capacitor across the supply to cater for voltage drops when the servos activate. These parts were all soldered onto an Arduino prototyping board so I did not have to have a PCB manufactured.


The tested power consumption in sleep mode came out at just over 0.5mA so the box could in theory remain active in sleep mode for several months without the batteries being recharged.


So I had a lot of fun creating this project and learnt a lot about servo control, low power techniques, interrupt servicer routines and MOSFETS that can be put to good use in IoT projects which need to remain dormant for long periods of time and then wake up and do something useful.

I also learnt to use DesignSparkPCB to build and document my circuit. It is a really powerful tool and quite easy to use so I would recommend you try it out.

The schematic, BOM and Arduino code are all available for download on Github, so have a go at building one yourselves, not at all useless really!


I'm a big Open Source fan and Linux lover with a penchant for Italian motorbikes


1 Votes

February 27, 2017 09:52

I own a 1974 Laverda sf

0 Votes

August 27, 2016 22:11

DesignSpark schematics, BOM and code are all available on GitHub link at bottom of post. I just used a prototyping board which was very easy to build.

0 Votes

August 25, 2016 19:06

Any danger of a list of parts and a step-by-step 'how-to' for those of us with an interest in following in your footsteps but having (very!) limited technical competence? I know you credit Mortenson's original, but the starting point for his model was a "home made PCB", and that's enough to put me off....


0 Votes

August 24, 2016 08:09

You could make the microcontroller power down each time it switches the switch off but this would make the lid and arm less reactive, which would detract from the fun. You would also need to handle powering down so the arm retracts and lid closes after the switch has been activated.

0 Votes

August 23, 2016 11:00

Bit late I know, but why doesn't it actually switch itself off? What if you spring loaded it, so it could return to the box? Although the action to switch off would take more power from the servos, surely you make up for that by the fact that it is genuinely off.

0 Votes

June 21, 2016 20:30

Nice post, but 0.5A in sleep mode is too much! If you're looking to run your project for longer periods you could you this board ... -node-avr/ as controller, maybe powered by one or two Alkaline AA... this board does less than 4uA in Sleep. Also, to power the servos from another power supply, maybe some non-recharchable Lithium as the rechargeable types normally have a big self dircharge rate. Cheers

0 Votes

May 31, 2016 13:18

If I wanted to add a regulated supply using batteries to power the Atmega and servos, what would be the most energy efficient way to do this given that the box has to stay powered on for long periods of time in its low power state? Say if I needed to power the Atmega at 3.3V and servos at 6V?

0 Votes

May 3, 2016 15:41

It may be “useless” but I’ve really enjoyed the challenge of building it and making it reliable. I’ve now got a much better understanding of using interrupts and power saving techniques that I can use in other more “useful” projects. It also attracts a lot of laughs when you leave it around in the office and people wonder what it is and whether to switch it on!

0 Votes

April 30, 2016 08:20

I saw the 'useless machine' a while back, laughed and thought "what a waste of time!", but friends thought it was amazing and asked why I didn't make something great like this!

I like your version and it is interesting to see the detail. I was also intrigued by "To start with, the box does not actually switch itself off, it just appears that way.", yes of course! But as an engineer with my brain in auto logical mode I also thought "it's an on/off switch, so it turns itself off".... duh! :)