Home Creators Posts Import Register Favorites Logout

Content

Hi folks! A couple of people asked if I could demonstrate an ER puzzle that involved a clock, where the hands would move in a pattern or be triggered in some way to display a sequence of times that formed a code. So, here's a video that demonstrates one way of doing just that!

The actual mechanical setup and wiring is pretty straightforward - the key component that I'm using is a *dual-shaft* stepper motor (a BKA30D-R5, specifically) - and by fixing the hour and minute hands directly onto the two shafts you can control them independently to set any time you want.  

The code is a little more complicated than in some other projects, because I've included two separate methods to pass in the desired time to the Arduino - the first is using a USB serial connection, allowing you to send a time in HH:MM format via the Arduino IDE Serial Monitor, as follows:

I've also wired an ESP-01 device to the Arduino, which enables it to run a web server and parse parameters passed in the URL of an HTTP request. That means you can also set the time from the web browser of any device on your network by going to the IP address of the Arduino and sending "h" and "m" parameters as follows:

The code explanation for both these methods is long and can be quite complicated, but it's really useful to learn different methods to pass data between devices, and to call different actions based on the value of the data received. I've tried to explain each line as best I can,  but if you have any questions, please ask as always!

The wiring diagram, code download, and list of materials will be uploaded for Patreons shortly...

Files

What's The Time, Mr Wolf? An Arduino remote-control clock

Learn how to create an Arduino-powered clock whose hour and minute hands can be set independently via a USB serial connection, or remotely over Wi-Fi from the browser of any mobile phone, PC, or any other network device. Can be used as the basis for an Escape Room puzzle/prop, as an exercise in learning how to send data to an Arduino device over a network, or just for fun! For an example of a more ambitious project involving an entire array of similar devices, see https://www.humanssince1982.com/work/

Comments

Russell Hardman

Thanks Alastair, looks good. I agree, knowing different ways to send data to devices is useful to know. If you have time to look at my question from fruit machine that would be appreciated. If you don’t know that’s fine.

Michel Bouchard

Hi, good props!!! Love it. Is it possible to do it directly from arduino, placing it behind the clock, without using wifi ?

Jake

Hi Alastair. Just started on wiring it up. The wiring diagram indicates that the motor should be connected to digital pins 4,5,6 and 7, but the code refers to digital pins 2,3,4 and 5. I conclude it doesn't really matter as long as the code and the wiring correspond, or?

Danielle Jackson

Could this be used to open a maglock once youbset the hands to a specific time? Instead of typing in the time they would manually move the hands of the clock.

Michael

We're having trouble with the stepper motor, the hour hand seems to be working. However, the minute hand trembles and jumps to different times. Sometimes it doesn't work. It also turns forwards once and backwards another time. do you have an idea or an approach for us? See video

Michael

currently with USB

Michael

Yes I do have a additional power supply. But how do I connect it to which ports?

Steven Skindell

How do I get access to the source code and wiring diagrams for this. Signed up as a inventor. Thank you.

Steven Skindell

Found the source code however .. it does NOT compile for UNO using Arduino v 1.8.8 . 1000's of errors. It compiles correctly using Mega. Any ideas?

mark dennis (edited)

Comment edits

2026-09-07 18:00 I would like to share something with your readers. I got my BKA30D-R5 motors from AliExpress; same numbers, looks the same, but they sell a BKA30D-R5 stepper motor and a BKA30D-R5 360-degree stepper motor. Be sure to purchase the 360-degree motor (unlike what I did). I bought the BKA30D-R5 stepper motor and it only has about 320 degrees of motion and then it has to go the other way. A lot more coding would have to be done I imagine. Be aware...
2019-05-05 11:37

mark dennis (edited)

Comment edits

2026-09-07 18:00 Alastair, please let me know how you attached the hands of the clock to the stepper motor. I ordered the exact same clock and the hands do not fit on the shaft of the stepper motor. I am in the final stages of this project but I can't seem to get the hands attached. I have a second hand, a minute hand, and an hour hand; either they are too big or not big enough. Please help me... I am unsure of what to do.
2019-05-10 20:28

mark dennis (edited)

Comment edits

2026-09-07 18:00 One last question, although I know you never read my questions... How do I just give the time for the clock inside the program rather than through a serial monitor? I want the clock to go from one time to another back and forth over & over. I do not want to input the information. How do I do that by just inserting the time like you would in the serial monitor, but without using the serial port? Thanks if you get to me...
2019-05-24 10:17

Alastair Aitchison

Ah ok, I think I see. Let me try cooking something up and I'll send it to you!

Thomas Moore

Long time listener, first time caller. Built everything, uploaded the sketch but all i'm getting on the serial monitor is "initialising ESP module" then 4 timeouts, then cannot initialise ESP module, then fails to connect to the Wifi network, then alternates timeout and "no tag found".

David Schrempf

Hi Alistair, we have the ESP-01 working on an Uno with the Knock Knock puzzle and grabbed the Wifi portions of this sketch to have the puzzle respond to commands to reset and open the mag lock. The issue we are having is when sending a empty URL or ?h=number, the Serial monitor shows the client connected, then it may or may not show the requestBuffer. Mostly the WiFiEsp shows a TimeOut : XXX value. the browser hangs as well as the Knock Knock puzzle until I stop the connection. Any ideas?

Timo Oberkrome

have you uploaded the code already? I tried it on my own, but Ihave no experience with Arduimos. So it would be great to download the sketch. Kind regards from Germany

Graham Hickman

Hi Alastair i don`t know if my app on my mobile is working,i have sent about 6 messages over the last week but no reply so i can only assume you are not getting the messages, i have built the "what`s the time mr wolf but getting frustrated with it as i can not get it working. I know the issue is me not understanding everything you are saying on your video with the coding but i do get quite a lot of it. i am getting errors all the time saying "can`t initialise i have added the 3 library`s so i know that is not the problem, my wifi is found but can not connect even though i have added my ssid and password to your script, i am trying this with an arduino uno but preferably i want it to work on a nano but connecting my nano i can not even get the script to write to it.

Graham Hickman

sorry i did not tell you the error, it says failed to initialize esp every time i connect to usb and try to enter my time in serial monitor. the thing i don`t understand is even though i can not connect wireless i thought i would be able to use the serial monitor to input, or is it because if the wireless is not functioning then the serial monitor can`t operate. any help would be appreciated i really want to get this going now that i have bought everything, especially working on my nano. many thanks graham

Richard Wittens

Good evening, I just added myself as a patron. Can I find the code for this functionality? Please help me. I know its some time ago for you, but for mee it will be quite usefull :)

chris meredith

Hello I just built this exact same stepper motor wiring looks correct except in the wiring diagram you show here you have from stepper wired to 7654 but in the code you show it on 2345 I have tried it both ways and when I send a command nothing happens