TerraControl V3.0 - ESP8266 + BLYNK
by PraetorianCZ in Circuits > Wireless
9901 Views, 70 Favorites, 0 Comments
TerraControl V3.0 - ESP8266 + BLYNK
QUESTION: Would you be interested in new version using Wemos D1 mini and both DS18 sensor (for temperature) and DHT22 (for humidity)? Let me know in the comments. Thanks!
If you like this project, please VOTE for it in the Wireless contest... Thank you all very much!
Hey guys,
after few months of playing with ESP8266 I finally got new version of TerraControl I'm satisfied with and willing to share with you. Some of you might notice I'm skipping version 2.0...that's because that version was using mostly the old code with few additions but it was still messy as hell. Thanks to Blynk I was able to cut over 600 rows of code to 100 rows of much simple code!
What's changed?
- Little adjustments is the physical connections. Mainly because of the DHT sensor which could not be connected while booting up in the old version. It is all fixed now and no power blackout will mess with your settings.
- No ESP8266 WebServer. Which is a good thing, trust me on this.
- Total control via Blynk app. From anywhere in the world, you can control anything you want. I know this might sound as an advertisement, but I really grew to like Blynk.
- Much more possibilities - whole household connected and controllable/monitored via one app.
What You Need...
- NodeMCU 1.0 12E board - $3.32
- Relay board - for example - $5.90
- Temperature and humidity sensor DHT22(11) - $2.87
- Given the nature of NodeMCU board (its output is only 3.3v) you will either have to buy 3.3V relay board (in the link above), or modify 5v board, or buy I2C logic converter module - for example - $0.9
- 5V source (I'm using older usb charger)
- wires
- solder
- case/box
- Arduino IDE
Connections --> NodeMCU
DHT22/11 data pin --> D6
relayLight --> D1
relayHeat --> D2
relayHeat2 --> D5
relayFan --> D9 (RX pin on NodeMCU)
You need to power the modules according to their specs. If you are using 3.3v relay board, you can power it straight from the NodeMCU, otherwise you need to use external 5V.
I'm using my old parts and case, only needed to switch two wires...
Blynk Setup
For those who don't know what Blynk is, it is a Platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet. It's a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets. You might need to purchase some energy in the Blynk app but I think $4-5 is a good price for project like this.
Let's start on Andorid device (iOS version doesn't allow adding widgets or editing Eventor events yet):
- Download the Blynk app
- Sign up or login (if you already have an account)
- Tap "+" to create New Project Give the project a name and select device you are using (in our case it is ESP8266) and tap "Create" You will receive an Authentication token in you mail box, we are going to need it later
- On the Blynk Project page tap "+" and add:
- 4 buttons
- 4 LEDs
- 2 (labeled) displays
- Real-Time clock
- Notification
- Eventor
- History Graph (optional)
- Use the widget settings as seen on the last picture (if you set it up differently you will need to modify the code)
- In the project settings (nut icon on the top) "Send app connected command" to ON.
- Close the settings and open Eventor
Eventor
Let's continue with creating Eventor events...
First set up the Light control:
- Add new event
- When...TIME (select time when you want light to turn ON) set pin...(V10) to 1
- Add new event
When...TIME (select time when you want light to turn OFF) set pin...(V10) to 0
Now the Heat control
- Add new event
- When Temperature V8 is lower than 30 set pin...(V11) to 1
- Add new event
When Temperature V8 is higher or equal than 30 set pin...(V11) to 0
When you are done, close the Eventor and hit the play button on you project.
I hope you get the idea. If you start playing with Eventor you will discover more possibilities and options. In the current setup, the Light and Heat is automated and Heat2 and Fan manually controlled, but all four features can be controlled simply via pushing the button and it will override your current settings until the next condition is met.
The Code
Connect your board to the computer fire up the Arduino IDE, open the source code and let's have a quick look at it...
Libraries
You need to download three libraries to get the code working:
ESP8266WiFi.h
DHT.h
BlynkSimpleEsp8266.h (from the Blynk library)
Settings (change to your own needs)
const char ssid[] = "YOUR WIFI SSID";
const char pass[] = "YOUR WIFI PASSWORD";
char auth[] = "YOUR BLYNK PROJECT TOKEN"; (you will receive this in the e-mail after creating a project in the Blynk app)
That's it! You can upload the code and check on you phone that it is connected.
For full disclosure I'm still using the opposite states for relay 3 & 4 (Heat2 & Fan) from the first version. See the picture. Heat has states HIGH when the Blynk button is ON, LOW when OFF. The Heat2 has the opposite states.
Downloads
Working...? Great!
You might come up with even better solution of using the Eventor. To clarify the use of LED widgets: When you press a button or the Eventor sends a switch event, the code will at first switch the relay to the desired state and then fire a virtualWrite to turn the corresponding LED ON/OFF. This way you always know whether or not was your action successful (might be cause of connection issues but it did not happened while I was using this app for the last two months).
History graph is not necessary but a nice feature to have, it is using the same data we are sending to the Labeled values and stores them on Blynk server. You can have much more data available to you with the export option, which was not possible with the previous version.
This setup is universal. I believe I managed to clear up the code as much as it was possible with the same functionalities and more. You can use it to control your terrarium, aquarium, garden, aqua-phonic systems, incubators, etc. Just have fun and if you like this project, leave a comment. I'm sorry if I skipped some setup or something is not clear enough. In that case, send me a PM and I will fix it asap. Thank you for reading!