jellewie / Arduino-Smart-light

A smart 3D printed light clock/lamp, that includes, but is not limited to; WIFI and manual control, Clock mode, multiple animations, and transitions.
Other
7 stars 1 forks source link
clock esp32 smart

Smart clock

A smart 3D printed light clock/lamp, that includes, but is not limited to; WIFI and manual control, Clock mode, multiple animations, and transitions.

If you have interest in buying one and live in The Netherlands, feel free to contact me.

You can skip to Quick start guide if you already own a smart-clock, and just want to run the set-up.

You can skip to OTA updater if you just want to update it.

Index

Show/hide

- [Quick start guide](#quick-start-guide) - [Creating a unit](#creating-a-unit) - [Hardware](#hardware) - [Creating the model](#creating-the-model) - [Desk model](#desk-model) - [Wall model](#wall-model) - [3D printed only](#3d-printed-only) - [CNC](#cnc) - [PCB & wires](#pcb--wires) - [Firmware ](#firmware) - [Compile](#compile) - [BIN](#bin) - [Features](#features) - [Button](#button) - [LED status](#led-status) - [Potentiometer](#potentiometer) - [WIFI page](#wifi-page) - [Setup](#setup) - [Getting it’s IP](#getting-its-ip) - [Control](#control) - [Soft settings](#soft-settings) - [Clock mode](#clock-mode) - [Task List](#task-list) - [OTA (Over The Air update)](#ota-over-the-air-update) - [Full reset](#full-reset) - [Specifications ](#specifications) - [Input voltage](#input-voltage) - [Power consumption](#power-consumption) - [Appendix](#appendix)

Quick start guide

Follow the following steps to setup the lamp, stop after the first step if you do not want to set up Wi-Fi.

  1. Connect a proper power supply. The LEDs will blink shortly a soft white for a split second to show that bootup was successful.
  2. The potmeters or button will change the light.

Optional for WIFI:

  1. Long press the button, this will make the LEDs go PURPLE/RED/PURPLE/RED this means it is trying to connect to Wi-Fi, if this takes more than 10 seconds it will have created an Access Point. (Long press the button again to cancel this setup)
  2. Connect to this Access Point, by default it will be called “smart-clock”.
  3. When connected go to 192.168.4.1 this will show a page where the WIFI name (SSID) and password (Password) can be set, do not forget to submit to apply. Other settings on this page are explained in soft settings, for example 'Clockoffset' is the rotation of the LEDs (there are 60 LEDs so filling in 30 will rotate the clock by 50%). The light will also try to make a captive portal to prompt you to login and setup these settings. Sadly, this only works with HTTP, use the mentioned IP if the device does not prompt the login page (Not working as of now, Known issue)
  4. When the device is connected to WIFI it can be accessed by its IP address, but on devices who support mDNS, like Windows and Apple, smart-clock.local/ can also be used.
Desk clock image Desk lamp image

Creating a unit

Hardware

Creating the model

There multiple types of model, the 'DESK model' is used in this readme as example project. But the other models have the same features, just a different shape.

All STL files for 3D-printing have a predefined tolerance of 0.2mm build-in.

Desk model

The model is Desk.ipt, for this model there are 4 files that need to be printed.

  1. Lamp body.stl is the main body. It is suggested to do at least (0.4mm*3lines=1.2mm) walls so light will not shine though as much. It is printed on its face (like the STL orientation) and only the inner part needs a bit of support (overhang angle 90 degrees, density 2%).
  2. Lamp shield.stl is just a simple shield to add aluminium foil on, and will be intern so can be printed quick and dirty.
  3. Lamp stand.stl can have 3 times a pair embedded magnets in it, if the magnets are desired a layer pause need to be used. this model should be printed in the normal standing position on the round flat part.
  4. Diffuser.gcode A perfect spiral Gcode, this can be created with Jespers Perfect Spiral-Gcode. Altough a STL file is also included.

Wall model

This model and PCB is 'Work In Progress'!

There are 2 variants, and fully 3d printed model, and a CNC model.

3D printed only

The model is Wall Clock.ipt, for this model there are 2 files that need to be printed.

  1. Clock Top.stl This is the top of the clock, which houses the PCB controls.
  2. Clock x2.stl This needs to be printed twice, and is the bottom left and right.

CNC

The model is Wall Clock CNC.ipt.

  1. Wall Clock CNC.ipt This is the part that needs to be cut, it has thicker walls and no LED seperates
  2. The CNC .ipt mentioned above does have hidden LED seperates in the file, the idea was to 3d print them but this is still a WIP idea thing.

PCB & wires

Please refer the in the appendix - PCB & schematic for the schematic, but here are some common notes about the schematic, for example in Input voltage and power consumption more information is given about the specifications of the electrics.

Firmware

The firmware needs to be flashed once to enable OTA BIN file upload. Either with Arduino IDE and compile it, or using a BIN uploader of choice.

Compile

BIN

Uploading a BIN file with a cable to the ESP can be done by any ESP32 BIN file uploader. this step is required for the first flash time.

The BIN files themself can be found at releases. The newest version is always recommended and can be updated with OTA.

Features

Button

Although these options change a bit over time, here is a list of 3 actions what the button generally does, these can also change in different modes.

  1. StartPress Triggered when you start a press, will be rejected if sooner than Time_RejectStarts (80ms) of the last press).
    • Will toggle the lamp ON/OFF
  2. StartDoublePress Triggered when you start a second press between Time_RejectStarts (80ms) and Time_StartDoublePress (200ms) after the last one ended.
    • Will change the mode to 'DoublePressMode' (RAINBOW by default)
  3. StartLongPress Triggered when you press the button longer than Time_StartLongPressMS (5000) but shorter than Time_ESPrestartMS (15000) ms.
    • If in APmode it will cancel and reboot.
    • If it was connected to WIFI it will show its IP, Which is explained in WIFI page - Getting it’s IP.
    • If it isn’t connected to WIFI it will start connecting to WIFI (and possibly go into AP mode, that is explained in

LED status

In the back of the desk model is a LED (below the button). This is also the LED on the PCB of the ESP (LED_BUILDIN) this LED reflects thes errors:

Some statuses are also reflected by the LED strip itself, but due to the difficulty driving these in some WIFI modes, these are static set at the start of the status.

Potentiometer

The 4 Potentiometers are Red, Green, Blue, and White. Where white stand for the luminescence. When any of the RGB Potentiometers are turned the mode will switch to on/manual and the RGB value will be shown.

WIFI page

The 2 most important pages are the Setup page, where the user can setup the light. And the main landing page where the UI is that the user uses to contol the smart-clock.

Setup

WIFI page /ip

The setup page will be accessible and shown in APmode, but can also be access by going to smart-clock.local/ip. An example of this page is shown in the figure on the right. The password is replaced with starts, and cannot be received without changing the firmware. Leave fields blank (or for the password leaving only stars) to not update those values upon sending this forum. By default the SSID and password is limited to 16 characters by the firmware, and the total bytes that can be stored in memory is limited to 128. Going over these values results in unexpected behaviour.

Getting it’s IP

User devices that support mDNS, like Windows and Apple, can use smart-clock.local/info to obtain its IP.

Alternatively the IP can be shown in the LEDs themself. To trigger this see Button. The LEDs are divided into 10 sections, and each byte in the IP range will be shown one at a time, to goto the next section press the button shortly again. The numbers are like a clock and in clockwise direction, top/right is 0 and the one right/down of that is 1. Where RGB will be the order of the numbers, so red will have a x100 multiplication and green will have x10, so when the IP is 198.168.1.150 and it shows the last section (150) then section 1 will be Red, 5 will be green and 0 will be blue. This is shown in the figure below

ShowIP 198.168.1.150

Control

Home page

The control page is the default landing page the user will land on. An example of this page is shown in the figure on the right.

Settings page

An example of the settings page is shown in the figure on the right.

Soft settings

There are multiple soft settings, these are settings that can be changed after the sketch has been uploaded, but are still saved so they can be restored after a reboot. The most up-to-date values can be found in the top of the WiFiManagerBefore.h source file, and can only be set in smart-clock.local/ip. These settings are saved EEPROMSaveDelayMS (Default 30000ms) after the last change of SoftSettings, or directly after APmode and in the smart-clock.local/ip page. Note that the character " and TAB (EEPROM_Seperator) cannot be used, these will be replaced with ' and SPACE respectively. Leave black to skip updating these, use spaces ' ' to clear the values

Clock mode

For the use of clock mode the right time zone needs to be set up, these are stored in timeZone (Default to Amsterdam).

Clock mode can only be started when WIFI has been connected and the user switches mode, after switching to Clockmode the lamp will turn PURPLE/GREEN/PURPLE/GREEN this means it is getting the time from a time server.

Also the clock can be manual updated with smart-clock.local/time?h=3&m=59&s=50 where H is hours, M is minutes, and S is seconds. The clock also automatically updates every day at 4:00

Furthermore the clock has some softsettings like ClockHourLines, but these are descibed in Soft settings

Task List

Tasks page

This page can be accessed on by opening the settings menu and clicking on the button 'Tasks' There can be 16 tasks, and the first 8 will be saved to EEPROM and will be restored after boot. By default the SYNCTIME had been added at 4:0:0

The format of Tasks "TimeH,TimeM,TimeS,TaskType,Var"

Some examples of TaskType and Var: TaskType (x but converted to name) - Var (x but can be converted to name)

  1. SWITCHMODE - New mode to switch to "x" either in string or ID form
  2. DIMMING - Stepsize,GoTo,TimeInterfall in ms "x,y,z"
  3. BRIGHTEN - Stepsize,GoTo,TimeInterfall in ms "x,y,z"
  4. RESETESP
  5. CHANGERGB - Red,Green,Blue,OPT_Brightness "x,y,z" |OR| "x,y,z,w"
  6. SAVEEEPROM
  7. SYNCTIME
  8. AUTOBRIGHTNESS - True/false "x" either in string or ID form
  9. HOURLYANIMATIONS - Time in seconds for the animation "x"

OTA (Over The Air update)

This page can be accesed on smart-clock.local/ota (or 'IP/ota') and enables you to update firmware over WiFi. On this page is a 'choose file' button where the new version can be selected. Make sure the right, compatible, most updated file is selected ("Smart_clock.bin"). This can be downloaded from releases. After which the 'Upload' button needs to be press for the update process to begin, the unit will automatically update and reboot afterwards. Note that SoftSettings are preserved.

Full reset

If a full reset is desired it can be achieved by going to 'smart-clock.local/reset'. But note that accessing the page will directly wipe all SoftSettings from existence and there will be no way to restore them back. If the wipe was successful it will be reported back and will execute a restart.

Specifications

Input voltage

The power supply is either 5V or 12V. The difference in the voltage is the used LED strip. If the WS2812B is used it would need to be 5V, but if the WS2815 (with redundant data lines) is used then 12V is required.

positive polarity

The pinout of the DC jack has by default positive polarity. Meaning the outer tube -as shown in the figure right- is the ground connection. The lamp will fail to work otherwise (but is able to handle the shock).

Power consumption

The lamp will consume 18Watts at maximum, so as an example for 12V a 1.5A (or 5V at 3.6A) power supply is required to allow full brightness. Although actual measurements came closer to 12Watt.

The idle power consumption is about 0.65Watt (measured with LEDs turned off, and WIFI turned on)

Appendix