Outils pour utilisateurs

Outils du site


start:arduino:esp32:smarthome

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
start:arduino:esp32:smarthome [2025/08/29 16:27] – [Test Password avec Bouton] adminstart:arduino:esp32:smarthome [2025/08/29 21:36] (Version actuelle) – [DemoFablab] admin
Ligne 988: Ligne 988:
 #include <Wire.h> #include <Wire.h>
 #include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
 +#include "xht11.h"
 +
 //#include <analogWrite.h> //#include <analogWrite.h>
 #define fanPin1 19 #define fanPin1 19
 #define fanPin2 18 #define fanPin2 18
 #define led_y 12  //Define the yellow led pin to 12 #define led_y 12  //Define the yellow led pin to 12
 +#define btnPin 16
 +#define servoPinF 5
 +#define waterPin 34
 +#define LED_PIN    26
 +#define LED_COUNT 4
  
 +xht11 xht(17);
 +unsigned char dht[4] = {0, 0, 0, 0};//Only the first 32 bits of data are received, not the parity bits
 #ifdef __AVR__ #ifdef __AVR__
  #include <avr/power.h> // Required for 16 MHz Adafruit Trinket  #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
Ligne 998: Ligne 1007:
 // Which pin on the Arduino is connected to the NeoPixels? // Which pin on the Arduino is connected to the NeoPixels?
 // On a Trinket or Gemma we suggest changing this to 1: // On a Trinket or Gemma we suggest changing this to 1:
-#define LED_PIN    26+
 // How many NeoPixels are attached to the Arduino? // How many NeoPixels are attached to the Arduino?
-#define LED_COUNT 4+
 // Declare our NeoPixel strip object: // Declare our NeoPixel strip object:
 Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
 LiquidCrystal_I2C mylcd(0x27,16,2); LiquidCrystal_I2C mylcd(0x27,16,2);
  
-Servo myservo;  // create servo object to control a servo +Servo myservoP;   
-                // 16 servo objects can be created on the ESP32+Servo myservoF; 
    
 int pos = 0;    // variable to store the servo position int pos = 0;    // variable to store the servo position
-// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33  +int servoPinP = 13; 
-int servoPin = 13;+boolean btnFlag = 0; 
 +String password = ""; 
 + 
 +/*#include "MFRC522_I2C.h" 
 +// IIC pins default to GPIO21 and GPIO22 of ESP32 
 +// 0x28 is the i2c address of SDAif doesn't match,please check your address with i2c. 
 +MFRC522_I2C mfrc522(0x28) */
  
 void setup() { void setup() {
Ligne 1019: Ligne 1035:
 #endif #endif
   // END of Trinket-specific code.   // END of Trinket-specific code.
 +  Serial.begin(115200);  
 +  Wire.begin();  
 +   
 +  /*mfrc522.PCD_Init();  
 +  ShowReaderDetails();  
 +  Serial.println(F("Scan PICC to see UID, type, and data blocks..."));   
 +  pinMode(btnPin, INPUT); 
 +  mylcd.setCursor(0, 0); 
 +  mylcd.print("Carte");*/ 
 +  
   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
   strip.show();            // Turn OFF all pixels ASAP   strip.show();            // Turn OFF all pixels ASAP
   strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)   strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
  
-  myservo.attach(servoPin);   // attaches the servo on pin 18 to the servo object+  myservoP.attach(servoPinP);   // attaches the servo on pin 13 to the servo object 
 + 
 +  pinMode(waterPin, INPUT); 
 +  myservoF.attach(servoPinF,500,2400);// Valeurs pour servo  
 +  myservoF.write(140); 
 +  delay(200);
  
 pinMode(fanPin1, OUTPUT); pinMode(fanPin1, OUTPUT);
Ligne 1043: Ligne 1073:
 servo_porte(); servo_porte();
 ledOFF(); ledOFF();
 +capt_temp();
 ventilateur001(); ventilateur001();
 ledON(); ledON();
- +affiche();  
-  // Fill along the length of the strip in various colors... +LED_RVB() ; 
-  colorWipe(strip.Color(255,   0,   0), 50); // Red +capt_temp();
-  colorWipe(strip.Color(  0, 255,   0), 50); // Green +
-  colorWipe(strip.Color(  0,   0, 255), 50); // Blue +
- +
-  // Do a theater marquee effect in various colors... +
-  theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness +
-  theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness +
-  theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness +
- +
-  rainbow(10);             // Flowing rainbow cycle along the whole strip +
-  theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant +
- +
-servo_porte();+
 ledOFF(); ledOFF();
- +affichefenetre(); 
-//ventilateur001();+fenetre(); 
 +affiche();
 } }
  
Ligne 1147: Ligne 1167:
   for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees   for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
     // in steps of 1 degree     // in steps of 1 degree
-    myservo.write(pos);              // tell servo to go to position in variable 'pos'+    myservoP.write(pos);              // tell servo to go to position in variable 'pos'
     delay(15);                       // waits 15ms for the servo to reach the position     delay(15);                       // waits 15ms for the servo to reach the position
   }   }
   for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees   for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
-    myservo.write(pos);              // tell servo to go to position in variable 'pos'+    myservoP.write(pos);              // tell servo to go to position in variable 'pos'
     delay(15);                       // waits 15ms for the servo to reach the position     delay(15);                       // waits 15ms for the servo to reach the position
   }   }
Ligne 1183: Ligne 1203:
  
 void affiche(){ void affiche(){
 +  mylcd.clear();
   mylcd.setCursor(2, 0);   mylcd.setCursor(2, 0);
   mylcd.print("Bienvenue au");   mylcd.print("Bienvenue au");
   mylcd.setCursor(3, 1);   mylcd.setCursor(3, 1);
   mylcd.print("Castellab");   mylcd.print("Castellab");
-  //mylcd.clear(); 
 } }
  
Ligne 1199: Ligne 1219:
   delay(2000);   delay(2000);
   }   }
 +
 +  void capt_temp(){
 +     mylcd.clear();  
 +  if (xht.receive(dht)) { //Returns true when checked correctly
 +    Serial.print("RH:");
 +    Serial.print(dht[0]); //The integral part of humidity, DHT [1] is the fractional part
 +    Serial.print(" ");
 +    Serial.print("Temp:");
 +    Serial.print(dht[2]); //The integral part of temperature, DHT [3] is the fractional part
 +    Serial.println("C");
 + 
 +    mylcd.setCursor(0, 0);
 +    mylcd.print("T = ");
 +    mylcd.print(dht[2]);
 +    mylcd.print(" degres ");
 +    mylcd.setCursor(0, 1);
 +    mylcd.print("H = ");
 +    mylcd.print(dht[0]);
 +    mylcd.print(" % ");
 +   
 +    delay(200);
 +  } else {    //Read error
 +    Serial.println("sensor error");
 +  }
 +  delay(1000);  //It takes 1000ms to wait for the device to read
 +}  
 +
 +void fenetre(){
 +  int water_val = analogRead(waterPin);
 +  Serial.println(water_val);
 +  if(water_val > 1500) {
 +    myservoF.write(0);
 +    delay(200);
 +  }
 +  else {
 +    myservoF.write(140);
 +    delay(200);
 +  }
 +  delay(2000);
 +}
 +
 +void affichefenetre(){
 +  int water_val = analogRead(waterPin);
 +  mylcd.clear();
 +  mylcd.setCursor(2, 0);
 +  mylcd.print("capteur Pluie");
 +  mylcd.setCursor(3, 1);
 +  mylcd.print(water_val);
 +  delay(2000);
 +}
 +
 +void LED_RVB(){// Fill along the length of the strip in various colors...
 +  colorWipe(strip.Color(255,   0,   0), 50); // Red
 +  colorWipe(strip.Color(  0, 255,   0), 50); // Green
 +  colorWipe(strip.Color(  0,   0, 255), 50); // Blue
 +
 +  // Do a theater marquee effect in various colors...
 +  theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
 +  theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
 +  theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness
 +
 +  rainbow(10);             // Flowing rainbow cycle along the whole strip
 +  theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
 +}
 +/*
 +void RFID(){
 +  // 
 +  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
 +    delay(50);
 +    password = "";
 +    if(btnFlag == 1)
 +    {
 +      boolean btnVal = digitalRead(btnPin);
 +      if(btnVal == 0)  //Swipe the card to open the door and click button 1 to close the door
 +      {
 +        Serial.println("ferme");
 +        mylcd.setCursor(0, 0);
 +        mylcd.print("ferme ");
 +        myservoP.write(0);
 +        btnFlag = 0;
 +      }
 +    }
 +    return;
 +  }
 + 
 +  // select one of door cards. UID and SAK are mfrc522.uid.
 + 
 +  // save UID
 +  Serial.print(F("Card UID:"));
 +  for (byte i = 0; i < mfrc522.uid.size; i++) {
 +    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
 +    //Serial.print(mfrc522.uid.uidByte[i], HEX);
 +    Serial.print(mfrc522.uid.uidByte[i]);
 +    password = password + String(mfrc522.uid.uidByte[i]);
 +  }
 +  //if(password == "131233147231" //Carte
 +  if(password == "243636633"    //badge
 +  {
 +    Serial.println("open");
 +    mylcd.setCursor(0, 0);
 +    mylcd.clear();
 +    mylcd.print("ouvert");
 +    myservoP.write(180);
 +    password = "";
 +    btnFlag = 1;
 +  }
 +  else   //The card number is wrong,LCD displays error
 +  {
 +    password = "";
 +    mylcd.setCursor(0, 0);
 +    mylcd.print("erreur ");
 +  }
 +  //Serial.println(password);
 +}
 +
 +void ShowReaderDetails() {
 +  //  attain the MFRC522 software
 +  byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
 +  Serial.print(F("MFRC522 Software Version: 0x"));
 +  Serial.print(v, HEX);
 +  if (v == 0x91)
 +    Serial.print(F(" = v1.0"));
 +  else if (v == 0x92)
 +    Serial.print(F(" = v2.0"));
 +  else
 +    Serial.print(F(" (unknown)"));
 +  Serial.println("");
 +  // when returning to 0x00 or 0xFF, may fail to transmit communication signals
 +  if ((v == 0x00) || (v == 0xFF)) {
 +    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
 +  }
 +}
 +*/
 +
 </code> </code>
 ====== SmartHome MicroPython3 ====== ====== SmartHome MicroPython3 ======
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/smarthome.1756477666.txt.gz · Dernière modification : de admin