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 [2023/04/28 18:21] – [GPIO ESP32 Et Capteurs/Actionneurs] gerardadminstart:arduino:esp32:smarthome [2023/12/10 10:26] (Version actuelle) – [GPIO ESP32 Et Capteurs/Actionneurs] gerardadmin
Ligne 16: Ligne 16:
 ===== GPIO ESP32 Et Capteurs/Actionneurs ===== ===== GPIO ESP32 Et Capteurs/Actionneurs =====
  
 +    *GPIO 05 => SERVO Fenetre
     *GPIO 12 => LED     *GPIO 12 => LED
-    *GPIO 16 => Bouton Gauche +    *GPIO 13 => SERVO Porte Avant
-    *GPIO 27 => Bouton Droit+
     *GPIO 14 => PIR(Detection presence ON=1 OFF=0)     *GPIO 14 => PIR(Detection presence ON=1 OFF=0)
-    *GPIO 25 => BUZZER +    *GPIO 16 => Bouton Gauche 
-    *GPIO 13 => SERVO Porte Avant  +    *GPIO 17 => DHT11 Temperature
-    *GPIO 05 => SERVO Fenetre +
-    *GPIO 34 => Capteur Humidite +
-    *GPIO 26 => LED Neopixel (4)+
     *GPIO 18 => Ventilateur Sens 1     *GPIO 18 => Ventilateur Sens 1
     *GPIO 19 => Ventilateur Sens 2     *GPIO 19 => Ventilateur Sens 2
 +    *GPIO 21=SDA => I2C(1)
 +    *GPIO 22=SCL => I2C(1)
     *GPIO 23 => Gaz     *GPIO 23 => Gaz
-    *GPIO 17 => DHT11 Temperature +    *GPIO 25 => BUZZER 
-    *I2C  0x27 => Afficheur +    *GPIO 26 => LED Neopixel (4 leds RVB) 
-    *I2C  0x28 => RFID , Carte = 131233147231 , Badge = 243636633+    *GPIO 27 => Bouton Droit 
 +    *GPIO 34 => Capteur Humidite 
 +    *I2C  0x27 => Afficheur : LCD 16X2  
 +    *I2C  0x28 => RFID MFRC522 , Carte = 131233147231 , Badge = 243636633 
 + 
 +{{ :start:arduino:esp32:capture_d_ecran_du_2023-12-10_10-17-41.png?direct&600 |}} 
 + 
 +{{ :start:arduino:esp32:capture_d_ecran_du_2023-12-10_10-20-32.png?direct&600 |}} 
  
 ==== Test Variation LED ==== ==== Test Variation LED ====
Ligne 592: Ligne 599:
       {       {
         boolean btn_val = digitalRead(btn1);         boolean btn_val = digitalRead(btn1);
 +        {
         if(btn_val == 1)  //If the button is released         if(btn_val == 1)  //If the button is released
           btn_count++;    //Automatically increments by 1 to count the clicked button times            btn_count++;    //Automatically increments by 1 to count the clicked button times 
Ligne 769: Ligne 777:
  
  
 +==== Test Capteur RFID ====
 +
 +<code c test_RFID.ino>
 +//**********************************************************************************
 +/*  
 + * Filename    : RFID
 + * Description : RFID reader UID
 + * Auther      : http//www.keyestudio.com
 +*/
 +#include <Wire.h>
 +#include <LiquidCrystal_I2C.h>
 +LiquidCrystal_I2C mylcd(0x27,16,2);
 +#include <ESP32_Servo.h>
 +Servo myservo;
 +#include <Wire.h>
 +#include "MFRC522_I2C.h"
 +// IIC pins default to GPIO21 and GPIO22 of ESP32
 +// 0x28 is the i2c address of SDA, if doesn't match,please check your address with i2c.
 +MFRC522 mfrc522(0x28);   // create MFRC522.
 +#define servoPin  13
 +#define btnPin 16
 +boolean btnFlag = 0;
 +
 +String password = "";
 +
 +void setup() {
 +  Serial.begin(115200);           // initialize and PC's serial communication
 +  mylcd.init();
 +  mylcd.backlight();
 +  Wire.begin();                   // initialize I2C
 +  mfrc522.PCD_Init();             // initialize MFRC522
 +  ShowReaderDetails();            // display PCD - MFRC522 read carder
 +  Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
 +  myservo.attach(servoPin,500,2400);
 +  pinMode(btnPin, INPUT);
 +  mylcd.setCursor(0, 0);
 +  mylcd.print("Carte");
 +}
 +
 +void loop() {
 +  // 
 +  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 ");
 +        myservo.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");
 +    myservo.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>
 +
 +
 +==== Test Password avec Bouton ====
 +
 +<code c Test_password_bouton.ino>
 +#include <Wire.h>
 +#include <LiquidCrystal_I2C.h>
 +LiquidCrystal_I2C mylcd(0x27,16,2);
 +#include "OneButton.h"
 +// Setup a new OneButton on pin 16.  
 +OneButton button1(16, true);
 +// Setup a new OneButton on pin 27.  
 +OneButton button2(27, true);
 +#include <ESP32_Servo.h>
 +Servo myservo;
 +int servoPin = 13;
 +String password = "";
 +String correct_p = "-.-";  //The correct password for the password door
 +
 +// setup code here, to run once:
 +void setup() {
 +  Serial.begin(115200);
 +  mylcd.init();
 +  mylcd.backlight();
 +  // link the button 1 functions.
 +  button1.attachClick(click1);
 +  button1.attachLongPressStop(longPressStop1);
 +  // link the button 2 functions.
 +  button2.attachClick(click2);
 +  button2.attachLongPressStop(longPressStop2);
 +
 +  myservo.attach(servoPin);
 +  mylcd.setCursor(0, 0);
 +  mylcd.print("Enter password");
 +}
 +
 +void loop() {
 +  // keep watching the push buttons:
 +  button1.tick();
 +  button2.tick();
 +  delay(10);
 +}
 +
 +// ----- button 1 callback functions
 +// This function will be called when the button1 was pressed 1 time (and no 2. button press followed).
 +void click1() {
 +  Serial.print(".");
 +  password = password + '.';
 +  mylcd.setCursor(0, 1);
 +  mylcd.print(password);
 +} // click1
 +
 +// This function will be called once, when the button1 is released after being pressed for a long time.
 +void longPressStop1() {
 +  Serial.print("-");
 +  password = password + '-';
 +  mylcd.setCursor(0, 1);
 +  mylcd.print(password);
 +} // longPressStop1
 +
 +// ... and the same for button 2:
 +void click2() {
 +  Serial.println(password);
 +  if(password == correct_p)
 +  {
 +    myservo.write(180);  //Open the door if the password is correct
 +    mylcd.clear();
 +    mylcd.setCursor(0, 0);
 +    mylcd.print("open");
 +  }
 +  else
 +  {
 +    mylcd.clear();
 +    mylcd.setCursor(0, 0);
 +    mylcd.print("error");
 +    delay(2000);
 +    mylcd.clear();
 +    mylcd.setCursor(0, 0);
 +    mylcd.print("input again");
 +  }
 +  password = "";
 +} // click2
 +
 +void longPressStop2() {
 +  //Serial.println("Button 2 longPress stop");
 +   myservo.write(0);  //Close the door
 +   mylcd.clear();
 +   mylcd.setCursor(0, 0);
 +   mylcd.print("close");
 +} // longPressStop2
 +</code>
  
  
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/smarthome.1682698913.txt.gz · Dernière modification : 2023/04/28 18:21 de gerardadmin