Gardening system DHT 11

Hello everybody,
my actual problem is delay i think. First of all i will explain what my system should do. The entire system consists of Arduino Mega, LCD shield with 6 buttons on it , 2 sensors DHT 1, DS3231, and 4 relay module + one relay . Program should looks like menu with 4 parts. In first part there is shown temperature and humidity of sensor 1 and only humidity of sensor 2, and real time from DS3231. This screen should me like main screen. Then when i press some button on shield i will enter menu where i setting up required variables. This required variables will compare with measured on sensors which is shown on main screen. If there is difference between them it will turn on some of relay. So that menu of required variables should consist :

in first menu: -1.)i set up required humidity in % and 2.) time how often (in hours) i turn one of relays on
in second menu: - set up 1.)minimum 2.)maximum temperature of sensor 1 and 3.)maximum humidity of sens2
in third menu: -1.)time when to turn on other relay and 2.)for how long it should be on

So in fact :

  • if required humidity(set up in first menu)is different from measured on sensor 2 turn on relay1 for 2 seconds and wait 5 minutes and measure+compare again
  • if expire time (set up in first menu) it will turn on relay2 for 2 sencond and repeat
    -if temperature from sensor1 is lower than required minimum temp. (set up in second menu) turn on relay3 for 10 second then repeat
    -if temperature from sensor1 is higher than required maximum temp. (set up in second menu) turn on relay4 for 5 second then repeat
    -if humidity from sensor1 is lower than required minimum temp. (set up in second menu) also turn on relay4 for 5 second then repeat
  • if time (set up in third menu 1.)) is equal of real time turn on relay5 for time set up in third menu 2.)

I found myself stuck in code with delay. There is many readings and turning on for some time so i can't use delay. I tried do it with some classes but i can't continue.

If you don't understand something from what i writed please ask me and i will try to explain it more with my poor english for what i am sorry :slight_smile:

in attachment is my actual code where i tried use class.

So in the end i will be very very pleased if you can help me with this or suggest some solution.

Thank you and wish you Merry Christmas and happy New year! :slight_smile:

Cely_program_zaloha_.ino (8.22 KB)

I also want to be all of this accesible via internet.I have ESP8266 and NodeMCU. So i was thinking if it's possible to sharing variables on Arduino Mega with Nodemcu. If it's possible to have Arduino+shield+2sensors and time module for gathering values and showing them locally on lcd display and then Nodemcu with connected relay modules will compare and turning on relays. And what i can manage locally i also want manage remotelly via internet.

My question is how can i comunicate between Arduino and Nodemcu and sharing data.

Flixon:
My question is how can i comunicate between Arduino and Nodemcu and sharing data.

Assuming they're placed physically close together and can be wired: SPI, Serial or I2C.

Yes, they will be close. It's possible they can have both same variables to working with? That variables can be managable via lcd shield and via internet(Nodemcu,ESP8266)?

Why do you need the Mega? Why not just use the Node or ESP for everything?

Because i need to have lcd shield for showing information on lcd display locally and buttons on this shield for local setting variables. +2 sensors DHT11, real time module, and relay module. It's many pins and i think noode or ESP don't have that much pins as Mega.

I don't see the problem. A Node has 10 GPIO. Your RTC and an I2C LCD (with buttons) will share 2. Your DHT11 sensors will use 2. That leaves 6. How many does the relay module need?

I need only 5 relays but if i want use Nodemcu for everything i cant use that lcd shield with buttons what i have now. I must change it for classic display for sharing pins with time module. I have that display but anyway i must use classic buttons instead shield and there is first problem. And the second and main problem still presist and it's delay function what was my problem on Mega. I wanted use nodemcu alone for relay control so i can lighten Mega and i still can use delay function. Mega will be only for measuring and showing that values on display and setting variables locally and Nodemcu will compare, do some if's and turn relays on and show everything on website and offer posibility of changing that values remotely too.

There are very few reasons to use delay or related functions. I rarely use it for more than 1-2 ms which is when doing precision timing (where the events are usually in the µs range). Any longer delays can be handled by proper coding. NodeMCU is a lot faster than Arduino to boot (5x higher clock, 32-bit instead of 8-bit processor).

By the way, the NodeMCU has 11 GPIO and one analog input, and it should be possible to free up two more (normally in use by internal flash). That leaves two pins plus the analog in, allowing you to read three buttons. Not much indeed, and no way I can think of to multiplex with so few pins.

Flixon:
...if i want use Nodemcu for everything i cant use that lcd shield with buttons what i have now. I must change it for classic display for sharing pins with time module. I have that display but anyway i must use classic buttons instead shield and there is first problem.

I don't understand this. What LCD shield with buttons do you want to use? Post a link to the product page or datasheet. Why not use something like this...an I2C LCD shield with buttons?