Introduction: TerraControl - With NodeMCU Webserver
UPDATE 3: Version 1.3
I'm working on making the code as user friendly as possible but it's going to be a long run. I'd like to have separate html and css files but I'm still figuring it out. For now, few changes...:
- ! ! ! included mDNS protocol, so from now on you don't need IP address to connect to your NodeMCU, simply put terracontrol.local in your browser and you are done (you have to be on the same network, of course)
- separate file for setting up the variables (setting.h). Unzip the file to your Projects folder, when you open the *.ino file, setting.h should be opened as well.
UPDATE 2: Version 1.2
- improved graph displaying range
- new values in graphs are moved to the end of array, not starting from the beginning again
- improved light setting - it is now unlimited (ON time can now be later than OFF time)
- code for manual defining your own server is in one place and commented by default (i.e. it is on automatic setting)
- clearer information in serial monitor
- unified function for min/max values in array
- new function for printing out minute values
UPDATE 1: Please see the version 1.1 I got the graphs and statistics working! Well, sort of...the range is still not as I want it to be, but at least now it is correctly displaying min and max. Plus new mouseover feature for the individual values in the graph.
After my first attempt to create controlled terrarium using Arduino board I got my hands on NodeMCU 12E board and I knew it was going to be a big step up!
I took me a few days before I began to understand how this board works (thanks to a lot of instructables here and google of course) and the possibilities it had. It think I'm on the right path to create exactly what I was dreaming about for several years...
So what is TerraControl v1.2 capable of?
- 2 automatically controlled relays (light timer and heating)
- 2 manually controlled relays (fan, second heating)
- GMT time change
- Simple graphs with highest/lowest temperature/humidity over the last 24 hours
- Monitoring temperature and humidity in terrarium
- All accessible and adjustable through webserver using HTML and CSS
- NodeMCU Lua 12E board- $3.40
- Relay board - for example - $2.50
- Temperature and humidity sensor DHT22(11) - $3
- given the nature of NodeMCU board (its output is only 3.3v) you will either have to buy 3.3V relay board, 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
Step 1: Getting the Parts Together
Connecting these parts is easy, just look at the source code and keep in mind that GPIO's of the NodeMCU board is different from the actual boards description (as seen on the trird picture):
//Define sensor pins
#define SENSOR_IN 15 //D8
#define SENSOR_IN_Type DHT22
//Define Relay pins
#define relayLight 5 //D1
#define relayHeat 4 //D2
#define relayFan 12 //D6
#define relayHeat2 14 //D5
i.e. DHT sensor pin goes to D8 (board's D3, D4, D8 can't be used as output but can be used as input), and the relay pins accordingly to the code. Remember, if you are using 5V relay, you need to modify the relay board or use I2C logic converter.
! ! ! IMPORTANT! When uploading the code to the board, you have to disconnect the DHT sensor, otherwise you will get an error when attempting to upload ! ! !
All parts can be powered with 5v power adapter
Step 2: Setup and Customization
Before we upload the code, there are few things that needs to be set up in setting.h:
//You WiFi AP
const char ssid[] = "SSID Name"; // insert your WiFi AP name
const char pass[] = "password"; // insert your WiFi password
// T E R R A R I U M S E T T I N G
float tempMin = 24; // temperature in Celsius for switching the heating ON
float tempMax = 30; // temperature in Celsius for switching the heating OFF
int humMin = 50; // minimum humidity in %
int humMax = 70; // maximum humidity in %
// hour and minute for light to go ON
int lightOn_hour = 7;
int lightOn_min = 0;
// hour and minute for light to go OFF
int lightOff_hour = 20;
int lightOff_min = 30;
// Central European Time (1 for winter time)
int timeZone = 2;
Uncomment the following part of the code if you know how to define your server manually or just run the code and get addresses from the serial monitor.
/*--- UNCOMMENT THIS FOR MANUAL SETTING ---
IPAddress ip(192, 168, 0, 111); //Node static IP
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(ip, gateway, subnet);
*/
All done? Great, let's move on...
Attachments
Step 3: Alwas ON/OFF Relay Connection
One thing I wanted was the relay board to be used as little as possible. As you probably know, relays have two possible ways of connection: ON when not used and ON when used. So I connected the light and heating to "ON when not used" (heating is almost always ON and lights are ON for about 13-14 hours every day) and fan and heating 2 to "ON when used" (I barely need to use one of them).
That is why the code for the same function is using different values:
if (heatVal == 1) {
client.println("ON");
} else {
client.println("OFF"); }
AND
if (heat2Val == 1) {
client.println("OFF");
} else {
client.println("ON"); }
You can of course modify the code according to your needs.
Now just connect the DHT sensor and let's look at the result!
Step 4: Webserver
When you open the webserver you will see simple page with all information about your terrarium and some features:
- Light ON/OFF time can be adjusted (step are: 1 hour for hour setting and 5 min for minute setting). At the moment ON time has to be earlier that OFF time (ON 22:30 and OFF 0:30 will not work - yet) - fixed in version 1.2
- Temperature setting (steps are 0.5 degree Celsius)
- Manualy turn ON/OFF other two relays - Fan and Heat 2 and adjust timezone when the time changes
if needed, change your timezones in following part of the code:
if (request.indexOf("/TIMEZONE_SWITCH") != -1) {
if (timeZone == 1) {
timeZone = 2;
setSyncProvider(getNtpTime);
} else {
timeZone = 1;
setSyncProvider(getNtpTime);
} }
- Webserver is using automatic time synchronization
Step 5: Disclosure
I know that the HTML and CSS code could be much more simple and the coding is not really user friendly but for the moment it works as it is supposed to (only the graphs are not very accurate but I'm still working on them) and I will get to these points when I start working on version number two. I have already decided to use external power supply (in this version I just stripped the 5v adapter and soldered it inside the box) and I also want the power cables to be more accessible and easier to connect/disconnect. I hope you guys (and your pets) will appreciate this instructable, if you do, please leave a short comment. And of course, suggestions are more than welcome! Thank you

Participated in the
Beyond the Comfort Zone Contest
35 Comments
Question 9 months ago on Step 5
bonjour , j'ai un souci avec l'heure ou les minutes ne s'affiche pas a certaine heure .
et de meme pour le reglage des minutes pour la lumieres ,ds mon exemple ça affiche un carré a la place de 30 ...
quelqu'un s'aurais me repondre a ça ? merci
ps: pour les valeurs de temp et hum c'est normal je n'ai pas connecter la dht22 sinon de se cotes la c'est bon chez moi
2 years ago
Good evening, I would like to realize the same project, but for an aquarium. I'm having trouble creating my web page, I'm new to web programming. Can you share your code.Thank you .Cordially .
3 years ago
Hi,
Great project!
I ran it on ESP 8266, it works fine. Did somebody tired to adjust it to ESP 32. I tried, but it doesn't work.
3 years ago
Hello Everything works very well, but the temperature and humidity appear on the web page as "nan".
4 years ago on Step 5
Hi. Fantastic project. I am new to HTML thing But it looks interesting.. Will look into learning a bit more about it.
Re the question below... "connection diagram" This would be very helpful in helping people like myself to complete the project.
Reply 4 years ago
Thank you! I don't have connection diagram but the connection of components is very easy and described above. BTW check out my newer project - TerraControl 3.0 with Blynk support
Question 4 years ago
Good afternoon, you can send a connection diagram of all the elements of your project
Answer 4 years ago
Hey, the connection is described in step 1:
#define SENSOR_IN 15 //D8
#define relayLight 5 //D1
#define relayHeat 4 //D2
#define relayFan 12 //D6
#define relayHeat2 14 //D5
the power connection depends on the used parts (some relay boards are using 5v, other 3.3v
I also recommend you to check out my updated version - TerraConrol 3.0 (link below in the comments). It is much easier to setup
Reply 4 years ago
thank
Reply 4 years ago
Reply 4 years ago
DHT sensor is connected to D8 pin.
Reply 4 years ago
4 years ago
Hey nice instructable. If only this had humidity UP automation for my moisture generator and humidity down so it can turn on the fan when the humidity is too much.
4 years ago
Hallo
Eine tolle Sache.Ich möchte gern über dyndns aus dem Internet auf das Modul zugreifen.
Es soll ein "Login " mit Benutzername und Passwort erfolgen.
Was muss man im Code eintragen,damit das geht.
Kann mir einer helfen.Danke
Question 5 years ago
hello, i need simple one look like my photo
my esp8266 give string via serial and use "RTClib.h" 1307 to make time and clock and then save time and clock with received data to micro sd card
now i want to show my serial received data and to id1 -id4
and download sd save file over browser as txt file looks like report.txt file in sd card can you make it for me?
i write the serial read and save sd with time part by my self
5 years ago
hi dear PraetorianCZ and all others i want to build a thermostat.i have a nodemcu board and LCD and high level trigger relay and dht11 now i can see and control min and max with button and LCD,and only i can see the temperature and humidity in HTML with web server and i cant control that., i write the form for input but i don't know how to write code to Equal the text box input number to variables of min and max.please help me.i am new in arduino and esp world.sorry about my bad English.plz change my code
ino file:http://www.filehosting.org/file/details/721840/dalichai.ino
5 years ago
This code: wemos D1 mini ESP8266 wifi modul +adafruit I2C oled display.
5 years ago
The modified code.
.
https://drive.google.com/open?id=1nAZZq_bSe_lKkZfLj3psvu-BTa4w_ZEZ
5 years ago
HI guys. I update the code. Added I2C oled diplay. ;-)
5 years ago
OK, guys. It is DONE! I hope you are going to like it... TerraControl v3.0!
https://www.instructables.com/id/TerraControl-V30-...