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 ![]()
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