ESP Alarm Clock With Remote Snooze Button (alarm Only Turns Off When Far Enough Away)
by choimik26 in Circuits > Arduino
44 Views, 0 Favorites, 0 Comments
ESP Alarm Clock With Remote Snooze Button (alarm Only Turns Off When Far Enough Away)


Welcome to this ESP Alarm Clock Tutorial. Follow the steps below to learn how to code and wire the LCD and ESP together to create an internet alarm clock which tracks time on its own RTC module and automatically sends requests when internet is available to update its time. In addition, the alarm clock can be programmed to keep an alarm at a specified time and will only stop once a remote button is pressed which is a set distance away from the alarm clock. It is meant to make sure you actually get out of bed in the morning because pressing the button will only turn off when sufficiently far enough away
Supplies
LCD 16x2 Display
2x ESP32
Male to Female Connectors (a lot)
Male to Male Connectors
2x Mini Breadboard
DS 3231M RTC Module
CR 2032 Coin Battery
2x Micro USB Cable Connector
3x Piezo Buzzer
Connecting ESP to LCD


First, you will need to connect the ESP pins to the LCD pins.
// Create An LCD Object. Signals: [ RS, EN, D4, D5, D6, D7 ]
LiquidCrystal lcd(13, 12, 14, 27, 26, 25);
Notice how in the code snippet above we have assigned pins 13, 12, 14, 27, 26, 25 to respective pins of the LCD object to the ESP. These are the corresponding pins you will need to attach the female to male connectors in order for the code snippet above to work correctly. I suggest you follow the pin numbering above as it will be easier to use for the future. After attaching all these pins remember to attach the ground and 5V connectors to the breadboard to create a power source for the following pins. Finally, make sure to attach the potentiometer to vary the LCD screen's brightness.
I personally followed this tutorial making small adjustments with how the ground and VIN was hooked up; however, if you follow the connections to the tea from this tutorial by DeepBlueMbedded the code I wrote should be compatible with the setup in the tutorial. The only difference between the wiring is I directly connected with male to female connectors from the ESP to the LCD without a breadboard, and only used a small separate breadboard to power a rail for the various ground and VIN connections needed.
https://deepbluembedded.com/esp32-lcd-display-16x2-without-i2c-arduino/
Connect the LCD ESP to the RTC Module



- Connect SCL to D22 with Female to Female Connector
- Connect SDA to D21 with Female to Female Connector
- Connect VCC to VIN powered rail with Male to Female Connector
- Connect GND to GND powered rail with Male to Female Connector
- Insert CR 2032 Coin Battery into DS3231M RTC Module
Before you freak out when seeing the breadboard picture (it is the breadboard containing all the GND and VIN connections between the LCD, RTC Module and Piezo Buzzers), all you need to know is that the VIN and GND were rails defined along the left and right side of the breadboard with the capability to power the RTC module circuit by connecting the RTC to the corresponding VIN and GND rails.
Connect the LCD ESP to the Piezo Buzzer

Connect pin D32 to a rail (this will be your positive rail).
Connect pin GND (the GND next to the 3.3V pin not the one next to VIN) to a rail. This rail will be your ground rail.
Connect the positive end of the piezo buzzers to the positive rail and negative end to the ground rail. Rinse and repeat for as many piezo buzzers as you would like.
You are now done wiring the setup for the ESP which controls the LCD, buzzers and RTC module!
Wire the ESP Button Remote

Connect the second ESP to the button configuration shown above. The configuration is a simple pull up button with the GPIO pin from the ESP being declared a INPUT_PULLUP so that a pullup resistor is not required. In total, all you have to connect is to place a button on a bread board and attach a ground pin with a female to male connector from the ESP to the button and do the same with pin D13 to the other leg of the button.
ESP to Breadboard Connections:
D13 -> one leg of button on same side of breadboard
GND -> other leg of button on the same side of breadboard
Setup Arduino IDE for ESP


Before we can code the ESPs we will need some supporting libraries mainly esp32 by espressif and DS3231 by Andrew Wickert. Esp32 will allow us to upload code from the Arduino IDE to the esp and DS3231 is a library to control the RTC module.
Code the LCD ESP

You can copy and paste the code snippet below to get the ESP to connect to WiFi correctly and start updating time from the time servers online. Make sure to change the WiFi name and password to connect properly to your home network. When you are done copying and pasting make sure to have the correct setup to push the code into bytecode for your ESP. The code copy and pasted below will display time on the LCD, update the time with the time servers, reprogram time to the RTC module and buzz for an alarm at 7am (this time can be changed by changing defaultHour and defaultMinute in the code snippets below). You may also have to change the UTCOffset_sec variable to match your timezone (it is already set into ET).
CODE BELOW:
Code the Remote Button ESP

The code below will contact the other Alarm ESP to turn off the piezo buzzers if the remote is far enough away and while the alarm is on. The code basically switches between a peer to peer connection with ESP NOW protocol using a stationary mode and then switches the Remote Button ESP into a soft access point from which the other ESP once finished with its callback will connect to and calculate the RSSI value on its end.
CODE BELOW
Create a Housing for the Alarm Clock




Use foamcore to build a suitable housing for the electronic components of the alarm clock. You can use cardboard, foamcore or even 3d print your own alarm clock housing.
Create a Housing for the Remote


Use foamcore to build a suitable housing for the electronic components of the remote snooze button. You can use cardboard, foamcore or even 3d print your own alarm clock housing.
Credit to Sources
Credits (for sources I used to build this project):
https://www.youtube.com/watch?v=qxwXwNS3Avw
https://github.com/NorthernWidget/DS3231/tree/master
https://randomnerdtutorials.com/esp32-esp-now-encrypted-messages/#more-116459
https://randomnerdtutorials.com/esp-now-two-way-communication-esp32/
https://www.youtube.com/watch?v=yBgMJssXqHY&t=369s
https://deepbluembedded.com/esp32-wifi-signal-strength-arduino-rssi/
https://forum.arduino.cc/t/esp32-passive-peizo-buzzer/560562
https://www.youtube.com/watch?v=gj-H_agfd6U
https://esp32io.com/tutorials/esp32-piezo-buzzer#google_vignette
https://forum.arduino.cc/t/esp-now-struct-message/1239920
https://docs.arduino.cc/tutorials/generic/digital-input-pullup/
https://forum.arduino.cc/t/use-esp-now-and-wifi-simultaneously-on-esp32/1034555
https://forum.arduino.cc/t/esp32-wifi-rssi/1150959/3
https://randomnerdtutorials.com/esp32-ds3231-real-time-clock-arduino/
https://randomnerdtutorials.com/esp32-access-point-ap-web-server/
https://www.youtube.com/watch?v=aAG0bp0Q-y4
https://deepbluembedded.com/esp32-lcd-display-16x2-without-i2c-arduino/
https://randomnerdtutorials.com/getting-started-with-esp32/#esp32-programming-environments