air recovery - (DHT-22 variables)

Hello,
i started work on module for my home air recovery where i will have some DHT-22 sensors (for air damper). Main code is fine, problem is with variables, i want sent some variable to arduino and this variable should keep it until he will receive another update. For this i created this code (working fine) but when i will send some data from external program (VB.net) then arduino take it only one time :confused:

Arduino

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"

#define DHT1PIN 2   
#define DHT2PIN 7
#define DHT3PIN 53 
#define DHT4PIN 22

#define DHT1TYPE DHT22   
#define DHT2TYPE DHT22
#define DHT3TYPE DHT22
#define DHT4TYPE DHT22

DHT dht1(DHT1PIN, DHT1TYPE); 
DHT dht2(DHT2PIN, DHT2TYPE);
DHT dht3(DHT3PIN, DHT3TYPE); 
DHT dht4(DHT4PIN, DHT4TYPE);
int modul1 = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("AAA");
  
  
  dht1.begin();
  dht2.begin();
  dht3.begin();
  dht4.begin();
}

void loop(){
    delay(2000);


//definovani teploty a vlhkosti pro 4 senzory
 float t1 = dht1.readTemperature();
 float h1 = dht1.readHumidity(); 
 float t2 = dht2.readTemperature();
 float h2 = dht2.readHumidity();
 float t3 = dht3.readTemperature();
 float h3 = dht3.readHumidity();
 float t4 = dht4.readTemperature();
 float h4 = dht4.readHumidity();
 
 float temp; 
Serial.println("------------------------------------------------------------------------------------------------");
red = Serial.read();

if ( modul1 = 1){
if (isnan(t1) || isnan(h1)) 
      {
        Serial.println("K pripojeni cidlu 1 nebylo navazano");
      } else 
      {
        float hic1 = dht1.computeHeatIndex(t1, h1);
        Serial.print("Cidlo1 - Vlhkost vzduchu: ");
        Serial.print(h1);
        Serial.print(" %\t");
        Serial.print("Teplota: ");
        Serial.print(t1);
        Serial.println(" C");
       
 }
}
 else{
  Serial.println("Cidlo uzavreno");
 }
  
if (isnan(t2) || isnan(h2)) {
Serial.println("K pripojeni cidlu 2 nebylo navazano");
 } else {
  float hic2 = dht2.computeHeatIndex(t2, h2);
  Serial.print("Cidlo2 - Vlhkost vzduchu: ");
  //kalibrace vlhkosti + 2.7
  Serial.print(h2+2.7);
  Serial.print(" %\t");
  Serial.print("Teplota: ");
  // kalibrace teploty -0.5
  Serial.print(t2-0.5);
  Serial.println(" C ");
}

if (isnan(t3) || isnan(h3)) {
Serial.println("K pripojeni cidlu 3 nebylo navazano");
 } else {
  float hic3 = dht3.computeHeatIndex(t3, h3);
  Serial.print("Cidlo3 - Vlhkost vzduchu: ");
  Serial.print(h3);
  Serial.print(" %\t");
  Serial.print("Teplota: ");
  Serial.print(t3);
  Serial.println(" C ");
}

if (isnan(t4) || isnan(h4)) {
Serial.println("K pripojeni cidlu 2 nebylo navazano");
 } else {
  float hic4 = dht4.computeHeatIndex(t4, h4);
  Serial.print("Cidlo4 - Vlhkost vzduchu: ");
  Serial.print(h4);
  Serial.print(" %\t");
  Serial.print("Teplota: ");
  Serial.print(t4);
  Serial.println(" C ");
}
Serial.flush(); // clear serial port
}

part of code for send data (VB.NET)

SerialPort.Open()
SerialPort.Write("0")
SerialPort.Close()

thx

if ( modul1 = 1){

Why bother with a conditional?

ok i can do it by CASE, but i want turn on/off each sensor, but still i want see output each 2seconds, for this i first try it by if :confused: ...

Look at it again.
Carefully.

ok i am stupid idiot
red = Serial.read(); -> modul1 = Serial.read();
anyway, no change :confused: ...

No, seriously, have another look at reply #1.
Just the quoted code - forget my comment.

if ( modul1 == 1)
better? but still this will not save variable for each new loop

It's certainly not worse, is it?

and now figure out problem with stored variable ... each impulse from VB.net is only for one loop ... i tried modul1= Serial.parseInt(); with same result - update only for one loop

Let's see the code as it is now

Still i dont see nothing ...

Me neither.

So in arduino, there is no chance to keep variable? Save it in rom?

You can store variables in RAM.
You can save variable values in EEPROM, but you can't use EEPROM directly as variable storage.