bonjour
j'ai réalisé ce montage https://www.instructables.com/id/Aut...-Arduino-Nano/
avec ce code
je voudrais ajouter un afficheur OLED 1306 I2C 128x32 j'ai fait des recherches sur le netCode HTML:// BATHROOM FAN CONTROL // 2: SIG DHT22 // D13: SIG Relay // measurement in every 15 seconds // average of 3 last measurements provides the trigger // to turn on: average must be above 65% // to turn off: average must be below 65 % // minimum relay time when turned ON is 60 seconds // minimum relay off time after turning off is 300 seconds // #include <avr/wdt.h> #include "DHT.h" #define DHTPIN 2 // what pin we're connected to #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); // PARAMETERS int hON = 68; // Turn Off the fan at humidity int hOFF = 68; // Turn Off the fan at humidity unsigned long MinOFFTime = 300000; // minimum time after switch Off to turn back ON again // VARIABLES unsigned long lastmeasurement = 0; unsigned long switchedonmillis = 0; unsigned long switchedoffmillis = 0; float t = 0; float h = 0; float hone = 0; float htwo = 0; float hthree = 0; byte counter = 0; float haverage = 0; byte fan = 0; void setup() { Serial.begin(9600); pinMode(13, OUTPUT); dht.begin(); wdt_enable(WDTO_8S); // Start the watchdog timer with 8 seconds } void measurement() { if (counter >= 3) {counter = 0;} counter++; h = dht.readHumidity(); t = dht.readTemperature(); if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } Serial.println(counter); if (counter == 1) {hone = h;} if (counter == 2) {htwo = h;} if (counter == 3) {hthree = h;} haverage = (hone+htwo+hthree)/3; lastmeasurement = millis(); } void fanon() { digitalWrite(13, HIGH); switchedonmillis = millis(); // eg. 60 seconds - 600000 ms switchon time Serial.println("FAN ON"); fan = 1; } void fanoff() { digitalWrite(13, LOW); Serial.println("FAN OFF"); switchedoffmillis = millis(); fan = 0; } void loop() { wdt_reset(); // reset the Watchdog Timer - it starts from 0 again, if it exceeds 8 sec, node will reset if ((millis() > 15001) && ((millis()-15000) > lastmeasurement)) { measurement(); Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" *C"); Serial.println(hone); Serial.println(htwo); Serial.println(hthree); Serial.print("h average last 3 measurements: "); Serial.println(haverage); if (fan == 0) // if it's OFF { // CHECK IF IT WAS OFF FOR AT LEAST 120 seconds AND IF it was turned OFF at all if ((switchedoffmillis > MinOFFTime) && ((millis()-switchedoffmillis) > MinOFFTime) && (haverage >= hON) && (haverage < 150)) { fanon(); } // IF NOT YET SWITCHED OFF FROM ON (switchedoffmillis is 0 or less than 2 minutes) AND PARAMETERS MET if ((switchedoffmillis < MinOFFTime) && (haverage >= hON) && (haverage < 150)) { fanon(); } } // if it's working if (fan ==1) { if (((millis()-switchedonmillis) > 60000) && (haverage <= hOFF)) // KEEP IT FOR MINIMUM 60 seconds { fanoff(); } } // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to A0 seconds 'old' (its a very slow sensor) // h = h+6; // t = t-2; // check if returns are valid, if they are NaN (not a number) then something went wrong! } }
je rame, je patauge je lis je cherche je n'arrive a rien
quelqu'un aurais il pitié d'un vieux plomb?
maintenant j'ai deux codes qui fonctionne bien individuellement: BATHROOM_FAN_CONTROL.ino et oled.ino
comment les mixer, fusionner, compiler? avec l'IDE? pouvez vous me le faire?Code HTML:#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <DHT.h> #define DHTPIN 2 // what pin we're connected to //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); // Initialize DHT sensor for normal 16mhz Arduino DHT dht(DHTPIN, DHTTYPE); void setup() { Wire.begin(); dht.begin(); // initialize dht display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// initialize with the I2C addr 0x3C (for the 128x32)(initializing the display) Serial.begin(9600); } void displayTempHumid(){ delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius float t = dht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) ) { display.clearDisplay(); // clearing the display display.setTextColor(WHITE); //setting the color display.setTextSize(1); //set the font size display.setCursor(5,0); //set the cursor coordinates display.print("Failed to read from DHT sensor!"); return; } display.clearDisplay(); display.setTextColor(WHITE); display.setTextSize(1); display.setCursor(0,0); display.print("Humidity: "); display.print(h); display.print(" %\t"); display.setCursor(0,10); display.print("Temperature: "); display.print(t); display.print(" C"); } void loop() { displayTempHumid(); display.display(); }
par avance Merci
-----