Stap 3: De Code
#include
dht DHT;
#define Rel 7 #define Buttn 4 #define onTime A1 #define trashold A0 #define DHT22_PIN 5
long sensCount = millis ();
void setup() { Serial.begin(9600); pinMode (Rel, OUTPUT); pinMode (Buttn, INPUT);
}
void loop {/ / gegevens lezen als (millis () < sensCount) {sensCount = millis (); void loop() { // READ DATA if (millis () < sensCount) { sensCount = millis (); } /* millis() resets every 50 days or so */ if (millis () >= sensCount + 5000) { Serial.print("DHT22, \t"); int chk = DHT.read22(DHT22_PIN); switch (chk) { case DHTLIB_OK: Serial.print ("OK,\t"); Serial.print (DHT.humidity,1); Serial.print (",\t"); Serial.print (DHT.temperature, 1); Serial.print (",\t"); Serial.println (map (analogRead (trashold), 1, 1023, 45, 95)); break; case DHTLIB_ERROR_CHECKSUM: Serial.println ("Checksum error,\t"); break; case DHTLIB_ERROR_TIMEOUT: Serial.println ("Time out error,\t"); break; default: Serial.println ("Unknown error,\t"); break; } sensCount = millis (); } if (DHT.humidity >= map (analogRead (trashold), 1, 1023, 45, 95)) { digitalWrite (Rel, HIGH); } else digitalWrite (Rel, LOW); / * millis() reset elke 50 dagen of zo * / als (millis () > = sensCount + 5000) {Serial.print ("DHT22, \t"); int chk = DHT.read22(DHT22_PIN); schakelen (chk) {DHTLIB_OK kast: Serial.print ("OK, \t"); Serial.Print (DHT.humidity,1); Serial.Print (", \t"); Serial.Print (DHT.temperature, 1); Serial.Print (", \t"); Serial.println (kaart (analogRead (trashold), 1, 1023, 45, 95)); breken; kast DHTLIB_ERROR_CHECKSUM: Serial.println ("Checksum error fout,, \t"); breken; kast DHTLIB_ERROR_TIMEOUT: Serial.println ("time-out fout, \t"); breken; standaard: Serial.println ("Unknown error, \t"); breken; /* Manual Ignition */ if (digitalRead (Buttn) == HIGH) { long delayButtn = map (analogRead (onTime), 0, 1023, 1, 61) * 6000; long startTime = millis (); digitalWrite (Rel, HIGH); /* Delay Loop */ while (millis () <= delayButtn + startTime) { Serial.println (map (delayButtn + startTime - millis (), 0, 3600000, 1, 60)); if (startTime > millis () ) { /* millis() resets every 50 days or so */ startTime = millis (); } delayButtn = map (analogRead (onTime), 0, 1023, 1, 61) * 60000; } digitalWrite (Rel, LOW); } } // // END OF FILE // sensCount = millis ();Als (DHT.humidity > = kaart (analogRead (trashold), 1, 1023, 45, 95)) {digitalWrite (Rel, hoge);
/ * Handmatige ontsteking * / als (digitalRead (Buttn) == HIGH) {lange delayButtn = kaart (analogRead (onTime), 0, 1023, 1, 61) * 6000; lang startTime = millis (); digitalWrite (Rel, hoge); / * vertraging lus * / terwijl (millis () < = delayButtn + startTime) {Serial.println (kaart (delayButtn + startTime - millis Akumb 3600000, 1, 0, 60)); als (startTime > millis ()) {/ * millis() reset elke 50 dagen of zo * / startTime = millis ();delayButtn = kaart (analogRead (onTime), 0, 1023, 1, 61) * 60000;digitalWrite (Rel, laag);