Clock and Bluetooth Switch

Josh Carlisle

Overview

The project outlined below is a clock that can be programmed to run as an alarm, as well as this there is a secondary device which extends the functionality of the clock, by utilising a Bluetooth (BT) controlled plug socket. The goal of this project is to produce a usable device that can simplify daily tasks like turning on lights at a set times, using an alarm clock, turning on/off a plug socket and responding to changes in sundown throughout the year. The project contains the following functionality: firstly the project utilises a 0.91" display, which is used to display the time in 24hr clock notation. The time is automatically retrieved using a WizFi360 module, this module can also return other information such as, month, year and day of the week; thus allows for expansion of the project later on. The user can set multiple alarms (5 is the default), on top of this the first alarm (alarm 0) is used to communicate with the BT plug socket. Finally the project has a BT controlled switch can be both programmed to be controlled by the clock or independently by the users phone.

Top view Video

Hardware

Below is a list of the notable components used in the project

System (server and client)
Microcontroller System Board: BGM220 Explorer Kit Board (BRD4314A)
WiFi Module: WIZFI360-PA
External Button: PTS645SK70-2 LFS
OLED Display: I2C SSD1306
Speaker/buzzer: CPT-1255C-090
Switch (server only)
BT Module: BGM220PC22WGA2R
Voltage Regulator: MCP1703T-3302E/CB
Optoisolator: MOC3023S-TA1
Clock schematic Switch schematic

The projects principle component is the BGM220 Explorer Kit, which has an in built Bluetooth module using the BGM220P Gecko Bluetooth Module. The OLED display, WiFi module and external button are attached to the microcontroller, using the onboard mikroBUS Socket. All of the external components are all managed by their own code and they are interacted using GPIO (General Purpose Input and Output) and WiFi module is also communicated with using USART (Universal Synchronous/Asynchronous Receiver Transmitter).

Side view 1 Side view 2 Switch view Switch inside

Software

Below is a list of the software that is used in the project:

The project utilises the C programming language, the main functionality of the program is built on a series of LETimers (Low Energy Timers), these timers are used to control the time and the number of beeps; another timer the RTCC (Real Time Clock Counter) timer is used to control the frequency of the beeps. The primary timer which executes every minute is used to execute a number of functions, notably updating the internal time and printing it to the OLED display, checking alarms, switching lights based on alarm and switching lights based on sundown. There is an extra method which is called once per day, when the internal clock reports the time 00:00; this then re-initialises the time by synchronising the internal time with the time received from the internet; the method also gets the month which is then used to set the time for sundown.

The project also utilises Silicon Labs Bluetooth functionality, which runs certain methods based on BT events. Most BT events are not executed without user input or input from functions which are 2 called from the main method; this excludes BT startup events which are run on system boot. The main BT event is using the microcontroller as server, which is used when the user connects to the system controller from their smartphone; this connection cannot be made until the microcontroller is advertised which requires the user to press the onboard button (BTN0), it is used to set the alarms. The microcontroller is also used as a client when it connects to the switch; the methods which handle these events are called based on LETimer and the events occur either when the first alarm is called or when sundown occurs; to control the switch the microcontroller scans for the device, which has a specified MAC address and alters a specific characteristic (8), which either turns off or on the switch based on value sent.

Final Thoughts

The project went better than I thought, especially considering the time constraints I had with other classes, but if I were to do it again I would like to expand the specification and utilises the Bluetooth, the display and WiFi more, as I feel the final project lacked features and so it felt limited. To add to this towards the end of the project I started to take a keen interest in the security and advanced applications of Bluetooth; therefore I would like to study them more as I believe it will enhance the project further and lead to a better developed project. As this is my first major microcontroller developed using C, I am generally impressed with how the project went and the real-world applicability of the project, as the device works well and was useful this morning.

Downloads