Code Monkey home page Code Monkey logo

sunrisealarm's Introduction

SunriseAlarm

A digital clock with auditive and visual alarm.

When an alarms goes off, a ledstrip above the bed slowly simulates a sunrise and music starts to play, increasing very slowly. Different LED light scenes can be set and the wake-up time can be set and changed, both using a rotary knob and remotly. The Sunrise Alarm can send and receive commmands using MQTT, so remote control is possible with a wide range of devices, like a smartphone or a home automation system.

Here are some photos and a video of the installation and light effects: https://photos.app.goo.gl/3kZMjbhgKaqZbkF48

Component list and why they are used:

  1. ESP8266 NodeMCU LUA CP2102 ESP-12E Internet WiFi Development Board, 5.8$ The nodeMCU ESP8266 is the brain of my Sunrise alarm clock. It's connected to the internet and gets its time from an Mqtt request that returns the exact local time.

  2. DAOKI MAX7219 Dot led Matrix MCU 8x32 Control LED Display Module Drive, 12.4$ A Led dotmatix is used to show the digital clock and to show the menu items for the settings menu.

  3. RGB+White Individually Addressable LED Strip from Visdoll, 32$ 5 meters (16.4Ft), 150 Pixels 5050 RGB + White Individually Addressable LEDs, 30Leds/M, DC 5V, Non-Waterproof This LED strip is mounted on a wooded frame above the bed. It also holds the mosquito net ;-)

  4. 5V Power Supply,PHEVOS, 5v 5A Dc, Universal Switching Power Supply, 12$ Powers the LED strip and NodeMCU.

  5. Rotary encode module with push botton, <3$ This rotary knob is reachable from inside the bed and can be used to set the alarm time, turn it on and off, and activate some premade light scenes. These actions (and more) can also be controlled on a smartphone with any MQTT controller app.

  6. LDR, <1$ This light dependant resistor makes sure that the clock display intensity adapts to the light in the room. It took quite some experiments to have a good readable clock in any circomstances. You want it very dimmed at night but the clock should still be readable when natural light or light from the LED strip shines on it. So I programmed it to adapt to the LDR, and also increase intensity when the rotay button is used, and go in idle mode after 30 seconds. I can also tweak the intensity factor using my phone.

  7. DFPlayer Mini, a small and low price MP3 module with an simplified output directly to the speaker, 11โ‚ฌ This board makes playing MP3s easy. All controlls (play, pause, volume, ...) can be steered from code. MP3s play directly from a TF memory card.

The Sunrise

To have the best possible sunrise accuracy, I creates an image in Photoshop. The pixel width of the image is the number of leds of te strip (150 pixels). The height of the image is the time: each row of pixels is a point in time of the sunrise animation. So pixel 1,1 shwos the starting color of led 1, and then fades to pixel 1,2 over 20 seconds. The next 20 seconds pixel 1 fades to tehe color of pixel 1,3 and so on.

The image is read from a Raspberry Pi that is already used for my dyi home automation. Using MQTT I request to read the n-th pixel row of the image. One row contains: rrggbbaa,rrggbbaa, ... The aa is the png transparancy and reflects the inverse intencity of the white LEDs. Eg: f4f1e8ff,f6f2eaff,f6f4ebff,f7f5edff,f8f6eeff,f8f6efff,...

The menu

To have a good UI and UX on the clock setting, I did some experiments to find the best menu system using a single rotary knob. This is still work in progress, but at least I already have a system in place to read a json file as a tree structure for the hierachical menu. That makes modifications quite straightforward.

Other light effects

It was an afterthought, but since I already had the image-to-LED effect in place, I decided to add a generic way to load any picture as a light effect. Each 20 seconds a new MQTT message is published with the next row of that image, creating an infinite fade from row to row.

Another option is to select a single color (eg from the smartphone app) and fade towards that color. Some preset colors are added to the menu that is controlled with the rotary knob.

I discovered that the raw RGB values should be gamma-corrected to show an accurate color, but luckily the NeoPixel library I used had a handy function in place to do that for me.

OOP(s)

Because a lot of different sensors, events and modes are used, I wanted to organise my C++ code as object oriented as possible. But OOP in the Arduino world is hard to find. Quite some beginner coders are available on the Arduino platform, and code examples are poorly written. So I spend a lot of time iterating and refactoring the code to have it more or less as I want. All components are nicely black-boxed in their own cpp file and communicate to each other in the main app file. But since this is my first real c++ project, I'm afraid I still miss a lot of important c++ typical syntax to write elegant c++ code... The use of pointers is still pointless to me (no pun intended), and I know I have to get rid of Strings and use char arrays, but that's something for the next refactoring ;-)

OTA

What's cool about the NodeMCU is the over the air (OTA) updates system: in stead of connecting the clock directly to my PC using a usb cable, I could install the clock where it belongs, above the bed, and send all code updates over WIFI directly to the clock. How cool is that?!

WAF

Last but not least, to increase the WAF (Wife Acceptance Factor), I made a nice wooden housing for the clock. The rotary knob is built into the hanging cupboard above our bed. All cables are tucked away by sinking them under the LED strips.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.