Introduction: TerraControl - With NodeMCU Webserver

Picture of 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?

  1. 2 automatically controlled relays (light timer and heating)
  2. 2 manually controlled relays (fan, second heating)
  3. GMT time change
  4. Simple graphs with highest/lowest temperature/humidity over the last 24 hours
  5. Monitoring temperature and humidity in terrarium
  6. All accessible and adjustable through webserver using HTML and CSS

What is necessary:

  • 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

Picture of 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; // te
mperature 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...


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

Picture of 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

Comments

Cs.T (author)2017-11-20

This code: wemos D1 mini ESP8266 wifi modul +adafruit I2C oled display.

Cs.T (author)2017-11-20

The modified code.

.

https://drive.google.com/open?id=1nAZZq_bSe_lKkZfLj3psvu-BTa4w_ZEZ

Cs.T (author)2017-11-20

HI guys. I update the code. Added I2C oled diplay. ;-)

PraetorianCZ (author)2017-10-30

OK, guys. It is DONE! I hope you are going to like it... TerraControl v3.0!

https://www.instructables.com/id/TerraControl-V30-...

lanchlan (author)2017-10-07

Hey guys I have a problem with setting the correct fan operation at low humidity and missing the on / off switch, please help

PraetorianCZ (author)lanchlan2017-10-27

Hey, not sure how to check what is wrong without the code but I see you are using the first version with LCD where Arduino was used. I moved to NodeMCU and Wifi control for this reason...to many things to setup for LCD. I recommend to try it or wait for version 3, which I will be posting in few days, hopefully.

lanchlan (author)PraetorianCZ2017-10-27


Hi, great, both projects I launched,
I have in both problem with relay control from moisture,
I'm waiting impatiently for another project.

GuyS31 (author)2017-08-30

I wanna run it an an mega 2560 need help

PraetorianCZ (author)GuyS312017-10-27

You would need external ESP8266 module for that, but I can't help you with the wiring and setup as I don't own the mega. I'm sure you can find some instruction on the Internet. I suppose you want to use mega for more usable pins...?

PraetorianCZ (author)2017-10-27

Hey guys! Thanks for all your comments! Here is a little teaser of what I am working on... Terra/aqua/home setup fully controllable via Blynk (if you don't know what it is, don't worry, the setup is quite easy), accessible from anywhere in the World (probably except North Korea).

Eric Brouwer (author)2017-07-08

Lovely user interface.

Thanks for sharing. I used your code to get started with my own project. But I severely lack HTML skills.

Atrion (author)2017-03-22

When trying to compile the code I get the following error

"TerraControl_v1.3:45: error: 'file' does not name a type

file.open(history.txt);"

Any suggestions as I am fairly new to NodeMCU

PraetorianCZ (author)Atrion2017-03-23

Hi, I`m sorry about that! You can delete that line and it should work ok. I forgot to delete it from this version (it is something I`m working on...). I replace the zip file in here as well with correct version.

Atrion (author)PraetorianCZ2017-03-28

NTP Does not seem to be working. Also how hard would it be to add in a screen for local info?

arcov (author)2016-11-07

hi,
this is a great project and a well written ible, so cheers to you.
I am currently working to get my hydroponics-system fully interconnected.
Do you think your project here could be adapted to this task?
I'm really not good in figuring stuff like this out, so if you could give me some hints i would be really greatful.
It needs to controll the lights automated, 2 waterpumps need to work together (first pump in then out) on a schedule. Ventilation could be manual. And optional i would like to add a watercooler consisting of a peltier element and a pump.
So a lot of tasks on a tight budget.
As i said above any hint would be greatly appreciated. Thanks and again great project.

PraetorianCZ (author)arcov2016-11-07

Hi, thank you! I think that what you are asking for is doable... You could copy the light controlling code and adjust it to control another relay where you could have both water pumps (since they have to work together, one relay should be ok) - this would replace the heat control. Then you can have 3rd and 4th relay for controlling the ventilation and watercooler.

PraetorianCZ (author)2016-11-03

Hi, this is html code for displaying HTML5 page in Internet Explorer.

JakariaHussainHemel (author)2016-08-19

It asks "Username and Password" when I visit to my ip address.

Can you show a screenshot?

Seelaub made it! (author)2016-08-05

Perfect! Just works

PraetorianCZ (author)Seelaub2016-08-09

Great job! Did you have any troubles setting it up?

About This Instructable

8,674views

78favorites

License:

Bio: Technology geek, love discovering new possibilities...
More by PraetorianCZ:Vigenere Cipher With ArduinoTerraControl V3.0 - ESP8266 + BLYNKMotion Detector With Blynk Notifications (WeMos D1 Mini + HC-SR04)
Add instructable to: