Help needed: Setting time via Bluetooth

I have coded a simple bedside clock (no need for alarms - I'm retired) using Mega Pro Mini, an BME280, a DS3213 and a SH1106 display.

Why the Mega - the fonts take up all memory.

This device has 2 buttons - the first ,turns times the screen off and on (the code automatically turns the screen back on at 6am) and the 2nd powers off & on a MP3 device (playing hours of rain). The MP3 turns off automatically at 12pm but it can be toggled to stay on longer.

I have included the working code below.

I hate buttons to set the time! I want to be able to use a cellphone and it's Bluetooth capability via a Terminal app to update the clocks time when needed. I don't want to use WiFi because the network conditions may change (like when I move into a rest home [joke]).

So the code needs to be wrapped in the Bluetooth script and if anything pairs with it, it springs into a (yet unknown) a routine to update the clock. Help doing this would be much appreciated. I have 05 & 06 bt modules.

oledsmallclockwithdbme280withbuttons.ino (3.2 KB)

It all sounds simple enough. You just need to have a line in the loop that awaits signal, any signal, at the serial port. I imagine there are libraries around that already have a subroutine to use that char to set an RTC. You just need to send the char in the correct format from terminal app on the phone.

You are right, but in my mid-seventies, anything more than 4 lines of logic and I’m lost.

Cheers … Peter Miller

Phone 07 41592645 and 0410 252133

One of the young guys,huh?

I have never used an RTC library myself, never had the need, but this is one of those times when a library is probably a good idea. You just need to find one with an example that has the facility you want. Somebody has surely done this for you already....

Yes, having got the data, I can update the RTC – in a hacking way. I need someone with finesse to poll the BT device and when paired, prepare to accept a 14 character string and push it up to the RTC. And then go back to the usual loop.

If you have a look at my code and run you’ll see it quite useful. Especially if you like to go to sleep with gentle rain each night.

I understand using WiFi devices is all the go but there shorting comes hinge on the client being able to connect to different SSID’s.

Cheers … Peter Miller

Phone 07 41592645 and 0410 252133

Please post the code as to how you set the time on the RTC.

If you are setting the RTC over serial, you should be able to send the same message from a phone. I would recommend using Kai Morich's Serial Bluetooth Terminal.

You are not using Serial in the sketch so after code is uploaded, you can place the HC05 on the hardware serial pins of the Arduino and use the phone and BT in place of the Serial monitor.

You simply need Bluetooth permanently waiting for an input. Something like this

void loop() { 
    while (Serial3.available()) 
    char c =;
    readString += c; 
  }// end while

  if (readString.length() >0) 
   } // end if

I think Bluetooth is entirely appropriate for this sort of thing. The only good reason for using WiFi is that you've got it in your hand and you don't have a Bluetooth.

Thank you for your code. I will attempt to use it but my printer has just died. I’ll let you know how it goes. Thanks again.

Cheers … Peter Miller

Phone 07 41592645 and 0410 252133

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.