Automatical lamp for plants based on ESP8266 Wi-Fi MCU and NodeMCU firmware. Can be scheduled or work depending on sunset and sunrise time.
You should rename src/settings.lua-TEMPLATE to settings.lua and edit it before uploading firmware.
Your's Wi-Fi network name.
Your's Wi-Fi network password.
Pin to which your relay/mosfet/etc is connected. Note that NodeMCU pin numbers differs from ESP8266 GPIO. More info here.
SNTP UTC (equal to GMT+0) time server (you don't need to touch this in most cases, time.google.com is ok).
Interval between time syncing in minutes. Lower == more accurate, because ESP8266 RTC can't provide time accurate enough.
Interval between failed time syncing attempts in minutes due to internet connection loss/SNTP error/etc. Lost connection means time error growth, so it's better to get connection as fast as possible.
Your timezone.
Assign this to true if there is daylight saving time in your country.
Write in when starts and ends daylight saving time in your country. Values in template are true for Latvia.
Time, when lamp should turn on and off. Currently, toggle_time.off
should be higher than toggle_time.on
. These values are ignored if use_sun_times == true
(described lower).
0 <= hour <= 23
0 <= min <= 59
Lamp smoothly turns on and off during fade_time
(described lower).
Time, during which lamp smoothly turns on and off.
Lamp will start to turn on at toggle_time.on
or sunrise and will be fully turned on when fade_time
will pass.
Lamp will start to turn off at toggle_time.off
or sunset - fade_time
and will be fully turned off when fade_time
will pass.
Human brightness perception is logarithmic due to the Weber-Fechner law. It means that changing brightness level from 2 to 3 (max value 1023) is a lot more visible than changing it from 1002 to 1003, so linear brightness changing is not the best solution.
Program supports three smooth brightness changing functions:
fade_function = 1
– linear
fade_function = 2
– parabolic
fade_function = 3
– exponential (recommended)
Linear – blue, parabolic - red, exponential - yellow. Green lines - max value (1023).
Assign to true if you want to replace toggle_time
with sunset and sunrise time for your location.
Coordinates for sunset and sunrise time acquiring. You can get it from google maps. If you click somewhere on map you will see coordinates of that point presented by two numbers. First number is latitude, second – longitude.
Firstly, you need to install nodejs packages (uploader scripts use nodemcu-tool):
npm install
After that you should build NodeMCU. For example, you can use this site:
Modules, that you need to include in your build:
- file
- GPIO
- HTTP
- net
- node
- PWM
- RTC time
- SJSON
- SNTP
- timer
- UART
- WiFi
You need to get version with float numbers. After you downloaded firmware, you need to flash it on your ESP8266. There are a lot of tools for our purposes:
https://nodemcu.readthedocs.io/en/master/en/flash/
I advice to use NodeMCU PyFlasher on windows (because you only need to download it and launch without any messing) and esptool.py on linux (because you can easily install it with pip and upload nodemcu firmware with one terminal command)
On windows you can find COM port of connected ESP8266 through device manager, on linux - using this command:
ls /dev/ttyUSB*
!IMPORTANT BEFORE FLASHING!
It's very easy to get confused if you use ESP8266 for the first time. You need to know some things about its bootloader. When you reset module, GPIO15 ALWAYS should be connected to ground, and GPIO2 to VCC. If you connect GPIO0 to VCC, MCU will boot in normal mode and execute your program in its flash memory. If you set it to GND, MCU will wait for firmware flashing. You need to set GPIO0 to GND ONLY when you flash firmware. When you upload program, it should be HIGH. You need to use resistors for all connections.
GPIO | Normal mode | Flashing mode |
---|---|---|
15 | Low | Low |
2 | High | High |
0 | High | Low |
You can read more about ESP8266 boot process here:
https://github.com/esp8266/esp8266-wiki/wiki/Boot-Process#esp-boot-modes
It's important each time when you reset MCU. After resetting, these pins can be used as regular GPIO. You need to think about this if you have pure ESP8266 module. If you have custom board with USB like NodeMCU development kit or WeMos board, then most likely GPIO15 and GPIO2 are correctly connected internally, and GPIO0 is triggered from USB when flashing. Also on these boards can be flash button, which connects GPIO0 to LOW when pressed (so, you should press it while resetting MCU before flashing).
After firmware uploading you should launch upload_build.bat or upload_build.sh if you are using windows or linux respectively. I recommend to compile code during uploading (described below).
First argument must be a COM port (in windows com ports looks like COM0, COM1, COM2). Uploader supports these flags:
/f - formats NodeMCU filesystem
/c - preprocesses and compiles .lua files
For example:
upload_build.bat COM3 /f /c
Uploader supports these flags and options:
-p <COM port>
-b <baudrate> (115200 if not specified)
-f - formats NodeMCU filesystem
-c - preprocesses and compiles .lua files
For example:
sudo ./upload_build.sh -p /dev/ttyUSB0 -f -c
Just connect MOSFET gate or relay coil to lamp_pin
(in case of using relay you shouldn't enable fading) and you are ready to go.
Example with MOSFET:
Note that it's a RGB LED strip, and I've connected to MOSFET only red and blue LEDs, ignoring green. More about that in next paragraph.
Plants are green because they reflect green color. It's obvious, but from that we can get one important thesis - light source for growing shouldn't be white (better say - shouldn't contain green in its spectre), this just isn't effective. Plants need red and blue light spectres, and if you are making custom light system using monochrome red and blue LEDs you should note that it's better when red LEDs count is 2-4 times higher than blue ones.
There are a lot of LED strips with red and blue LEDs in correct ratio. You can even find powerful 50W modules with one violet LED crystal with correct spectre, which appears to be a good solution.