start:arduino:esp32:smarthome
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:arduino:esp32:smarthome [2023/04/28 13:12] – [Test Afficheur] gerardadmin | start:arduino:esp32:smarthome [2025/08/29 21:36] (Version actuelle) – [DemoFablab] admin | ||
|---|---|---|---|
| Ligne 13: | Ligne 13: | ||
| | | ||
| * Tutoriel-Télécharger👉https:// | * Tutoriel-Télécharger👉https:// | ||
| + | * [[https:// | ||
| ===== GPIO ESP32 Et Capteurs/ | ===== GPIO ESP32 Et Capteurs/ | ||
| + | *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 | ||
| - | *I2C 0x27 => Afficheur | + | |
| + | *GPIO 22=SCL => I2C(1) | ||
| + | *GPIO 23 => Gaz | ||
| + | *GPIO 25 => BUZZER | ||
| + | *GPIO 26 => LED Neopixel (4 leds RVB) | ||
| + | *GPIO 27 => Bouton Droit | ||
| + | *GPIO 34 => Capteur Humidite | ||
| + | | ||
| + | *I2C 0x28 => RFID MFRC522 , Carte = 131233147231 , Badge = 243636633 | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | [[start: | ||
| ==== Test Variation LED ==== | ==== Test Variation LED ==== | ||
| Ligne 239: | Ligne 253: | ||
| <code c test-Servo_porte-Avant.ino> | <code c test-Servo_porte-Avant.ino> | ||
| - | #include <ESP32_Servo.h> | + | #include <ESP32Servo.h> |
| Servo myservo; | Servo myservo; | ||
| // 16 servo objects can be created on the ESP32 | // 16 servo objects can be created on the ESP32 | ||
| Ligne 269: | Ligne 283: | ||
| <code c Test-Servo-Fenetre_Test_Capt-Humidite.ino> | <code c Test-Servo-Fenetre_Test_Capt-Humidite.ino> | ||
| - | #include <ESP32_Servo.h> | + | #include <ESP32Servo.h> |
| Servo myservo; | Servo myservo; | ||
| #define servoPin 5 | #define servoPin 5 | ||
| Ligne 589: | Ligne 603: | ||
| { | { | ||
| 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++; | btn_count++; | ||
| Ligne 718: | Ligne 733: | ||
| </ | </ | ||
| + | ==== Test Capteur_Temp ==== | ||
| + | <code c Test_Capteur_Temp_DHT11.ino> | ||
| + | // | ||
| + | / | ||
| + | * Filename | ||
| + | * Description : Read the temperature and humidity values of XHT11. | ||
| + | * Auther | ||
| + | */ | ||
| + | #include < | ||
| + | #include < | ||
| + | LiquidCrystal_I2C mylcd(0x27, | ||
| + | #include " | ||
| + | xht11 xht(17); | ||
| + | |||
| + | unsigned char dht[4] = {0, 0, 0, 0};//Only the first 32 bits of data are received, not the parity bits | ||
| + | void setup() { | ||
| + | Serial.begin(9600);// | ||
| + | mylcd.init(); | ||
| + | mylcd.backlight(); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | if (xht.receive(dht)) { //Returns true when checked correctly | ||
| + | Serial.print(" | ||
| + | Serial.print(dht[0]); | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | Serial.print(dht[2]); | ||
| + | Serial.println(" | ||
| + | | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | mylcd.print(dht[2]); | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | mylcd.print(dht[0]); | ||
| + | // | ||
| + | delay(200); | ||
| + | } else { //Read error | ||
| + | Serial.println(" | ||
| + | } | ||
| + | delay(1000); | ||
| + | } | ||
| + | // | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Test Capteur RFID ==== | ||
| + | |||
| + | <code c test_RFID.ino> | ||
| + | // | ||
| + | / | ||
| + | * Filename | ||
| + | * Description : RFID reader UID | ||
| + | * Auther | ||
| + | */ | ||
| + | #include < | ||
| + | #include < | ||
| + | LiquidCrystal_I2C mylcd(0x27, | ||
| + | #include < | ||
| + | Servo myservo; | ||
| + | #include < | ||
| + | #include " | ||
| + | // IIC pins default to GPIO21 and GPIO22 of ESP32 | ||
| + | // 0x28 is the i2c address of SDA, if doesn' | ||
| + | MFRC522 mfrc522(0x28); | ||
| + | #define servoPin | ||
| + | #define btnPin 16 | ||
| + | boolean btnFlag = 0; | ||
| + | |||
| + | String password = ""; | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | mylcd.init(); | ||
| + | mylcd.backlight(); | ||
| + | Wire.begin(); | ||
| + | mfrc522.PCD_Init(); | ||
| + | ShowReaderDetails(); | ||
| + | Serial.println(F(" | ||
| + | myservo.attach(servoPin, | ||
| + | pinMode(btnPin, | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | } | ||
| + | |||
| + | 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(" | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | myservo.write(0); | ||
| + | btnFlag = 0; | ||
| + | } | ||
| + | } | ||
| + | return; | ||
| + | } | ||
| + | | ||
| + | // select one of door cards. UID and SAK are mfrc522.uid. | ||
| + | | ||
| + | // save UID | ||
| + | Serial.print(F(" | ||
| + | for (byte i = 0; i < mfrc522.uid.size; | ||
| + | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); | ||
| + | // | ||
| + | Serial.print(mfrc522.uid.uidByte[i]); | ||
| + | password = password + String(mfrc522.uid.uidByte[i]); | ||
| + | } | ||
| + | // | ||
| + | if(password == " | ||
| + | { | ||
| + | Serial.println(" | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.clear(); | ||
| + | mylcd.print(" | ||
| + | myservo.write(180); | ||
| + | password = ""; | ||
| + | btnFlag = 1; | ||
| + | } | ||
| + | else //The card number is wrong,LCD displays error | ||
| + | { | ||
| + | password = ""; | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | } | ||
| + | // | ||
| + | } | ||
| + | |||
| + | void ShowReaderDetails() { | ||
| + | // attain the MFRC522 software | ||
| + | byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); | ||
| + | Serial.print(F(" | ||
| + | Serial.print(v, | ||
| + | if (v == 0x91) | ||
| + | Serial.print(F(" | ||
| + | else if (v == 0x92) | ||
| + | Serial.print(F(" | ||
| + | else | ||
| + | Serial.print(F(" | ||
| + | Serial.println("" | ||
| + | // when returning to 0x00 or 0xFF, may fail to transmit communication signals | ||
| + | if ((v == 0x00) || (v == 0xFF)) { | ||
| + | Serial.println(F(" | ||
| + | } | ||
| + | } | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Test Password avec Bouton ==== | ||
| + | |||
| + | <code c Test_password_bouton.ino> | ||
| + | #include < | ||
| + | #include < | ||
| + | LiquidCrystal_I2C mylcd(0x27, | ||
| + | #include " | ||
| + | // Setup a new OneButton on pin 16. | ||
| + | OneButton button1(16, true); | ||
| + | // Setup a new OneButton on pin 27. | ||
| + | OneButton button2(27, true); | ||
| + | #include < | ||
| + | Servo myservo; | ||
| + | int servoPin = 13; | ||
| + | String password = ""; | ||
| + | String correct_p = " | ||
| + | |||
| + | // 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, | ||
| + | mylcd.print(" | ||
| + | } | ||
| + | |||
| + | 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, | ||
| + | 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, | ||
| + | mylcd.print(password); | ||
| + | } // longPressStop1 | ||
| + | |||
| + | // ... and the same for button 2: | ||
| + | void click2() { | ||
| + | Serial.println(password); | ||
| + | if(password == correct_p) | ||
| + | { | ||
| + | myservo.write(180); | ||
| + | mylcd.clear(); | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | mylcd.clear(); | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | delay(2000); | ||
| + | mylcd.clear(); | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | } | ||
| + | password = ""; | ||
| + | } // click2 | ||
| + | |||
| + | void longPressStop2() { | ||
| + | // | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | } // longPressStop2 | ||
| + | </ | ||
| + | ==== DemoFablab ==== | ||
| + | |||
| + | <code c demofablab.ino> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include " | ||
| + | |||
| + | //#include < | ||
| + | #define fanPin1 19 | ||
| + | #define fanPin2 18 | ||
| + | #define led_y 12 //Define the yellow led pin to 12 | ||
| + | #define btnPin 16 | ||
| + | #define servoPinF 5 | ||
| + | #define waterPin 34 | ||
| + | #define LED_PIN | ||
| + | #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__ | ||
| + | # | ||
| + | #endif | ||
| + | // Which pin on the Arduino is connected to the NeoPixels? | ||
| + | // On a Trinket or Gemma we suggest changing this to 1: | ||
| + | |||
| + | // How many NeoPixels are attached to the Arduino? | ||
| + | |||
| + | // Declare our NeoPixel strip object: | ||
| + | Adafruit_NeoPixel strip(LED_COUNT, | ||
| + | LiquidCrystal_I2C mylcd(0x27, | ||
| + | |||
| + | Servo myservoP; | ||
| + | Servo myservoF; | ||
| + | |||
| + | |||
| + | int pos = 0; // variable to store the servo position | ||
| + | int servoPinP = 13; | ||
| + | boolean btnFlag = 0; | ||
| + | String password = ""; | ||
| + | |||
| + | /*#include " | ||
| + | // IIC pins default to GPIO21 and GPIO22 of ESP32 | ||
| + | // 0x28 is the i2c address of SDA, if doesn' | ||
| + | MFRC522_I2C mfrc522(0x28); | ||
| + | |||
| + | void setup() { | ||
| + | // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. | ||
| + | // Any other board, you can remove this part (but no harm leaving it): | ||
| + | #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) | ||
| + | clock_prescale_set(clock_div_1); | ||
| + | #endif | ||
| + | // END of Trinket-specific code. | ||
| + | Serial.begin(115200); | ||
| + | Wire.begin(); | ||
| + | | ||
| + | / | ||
| + | ShowReaderDetails(); | ||
| + | Serial.println(F(" | ||
| + | pinMode(btnPin, | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | | ||
| + | strip.begin(); | ||
| + | strip.show(); | ||
| + | strip.setBrightness(50); | ||
| + | |||
| + | myservoP.attach(servoPinP); | ||
| + | |||
| + | pinMode(waterPin, | ||
| + | myservoF.attach(servoPinF, | ||
| + | myservoF.write(140); | ||
| + | delay(200); | ||
| + | |||
| + | pinMode(fanPin1, | ||
| + | pinMode(fanPin2, | ||
| + | |||
| + | mylcd.init(); | ||
| + | mylcd.backlight(); | ||
| + | |||
| + | pinMode(led_y, | ||
| + | } | ||
| + | |||
| + | |||
| + | // loop() function -- runs repeatedly as long as board is on --------------- | ||
| + | |||
| + | void loop() { | ||
| + | ledON(); | ||
| + | affiche(); | ||
| + | servo_porte(); | ||
| + | ledOFF(); | ||
| + | capt_temp(); | ||
| + | ventilateur001(); | ||
| + | ledON(); | ||
| + | affiche(); | ||
| + | LED_RVB() ; | ||
| + | capt_temp(); | ||
| + | ledOFF(); | ||
| + | affichefenetre(); | ||
| + | fenetre(); | ||
| + | affiche(); | ||
| + | } | ||
| + | |||
| + | |||
| + | // Some functions of our own for creating animated effects ----------------- | ||
| + | |||
| + | // Fill strip pixels one after another with a color. Strip is NOT cleared | ||
| + | // first; anything there will be covered pixel by pixel. Pass in color | ||
| + | // (as a single ' | ||
| + | // strip.Color(red, | ||
| + | // and a delay time (in milliseconds) between pixels. | ||
| + | void colorWipe(uint32_t color, int wait) { | ||
| + | for(int i=0; i< | ||
| + | strip.setPixelColor(i, | ||
| + | strip.show(); | ||
| + | delay(wait); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Theater-marquee-style chasing lights. Pass in a color (32-bit value, | ||
| + | // a la strip.Color(r, | ||
| + | // between frames. | ||
| + | void theaterChase(uint32_t color, int wait) { | ||
| + | for(int a=0; a<10; a++) { // Repeat 10 times... | ||
| + | for(int b=0; b<3; b++) { // ' | ||
| + | strip.clear(); | ||
| + | // ' | ||
| + | for(int c=b; c< | ||
| + | strip.setPixelColor(c, | ||
| + | } | ||
| + | strip.show(); | ||
| + | delay(wait); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Rainbow cycle along whole strip. Pass delay time (in ms) between frames. | ||
| + | void rainbow(int wait) { | ||
| + | // Hue of first pixel runs 5 complete loops through the color wheel. | ||
| + | // Color wheel has a range of 65536 but it's OK if we roll over, so | ||
| + | // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time | ||
| + | // means we'll make 5*65536/256 = 1280 passes through this outer loop: | ||
| + | for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) { | ||
| + | for(int i=0; i< | ||
| + | // Offset pixel hue by an amount to make one full revolution of the | ||
| + | // color wheel (range of 65536) along the length of the strip | ||
| + | // (strip.numPixels() steps): | ||
| + | int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); | ||
| + | // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or | ||
| + | // optionally add saturation and value (brightness) (each 0 to 255). | ||
| + | // Here we're using just the single-argument hue variant. The result | ||
| + | // is passed through strip.gamma32() to provide ' | ||
| + | // before assigning to each pixel: | ||
| + | strip.setPixelColor(i, | ||
| + | } | ||
| + | strip.show(); | ||
| + | delay(wait); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames. | ||
| + | void theaterChaseRainbow(int wait) { | ||
| + | int firstPixelHue = 0; // First pixel starts at red (hue 0) | ||
| + | for(int a=0; a<30; a++) { // Repeat 30 times... | ||
| + | for(int b=0; b<3; b++) { // ' | ||
| + | strip.clear(); | ||
| + | // ' | ||
| + | for(int c=b; c< | ||
| + | // hue of pixel ' | ||
| + | // revolution of the color wheel (range 65536) along the length | ||
| + | // of the strip (strip.numPixels() steps): | ||
| + | int hue = firstPixelHue + c * 65536L / strip.numPixels(); | ||
| + | uint32_t color = strip.gamma32(strip.ColorHSV(hue)); | ||
| + | strip.setPixelColor(c, | ||
| + | } | ||
| + | strip.show(); | ||
| + | delay(wait); | ||
| + | firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void servo_porte(){ | ||
| + | for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees | ||
| + | // in steps of 1 degree | ||
| + | myservoP.write(pos); | ||
| + | delay(15); | ||
| + | } | ||
| + | for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees | ||
| + | myservoP.write(pos); | ||
| + | delay(15); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | void ventilateur001(){ | ||
| + | digitalWrite(fanPin1, | ||
| + | analogWrite(fanPin2, | ||
| + | delay(1000); | ||
| + | digitalWrite(fanPin1, | ||
| + | digitalWrite(fanPin2, | ||
| + | delay(1000); | ||
| + | digitalWrite(fanPin1, | ||
| + | analogWrite(fanPin2, | ||
| + | delay(1000); | ||
| + | digitalWrite(fanPin1, | ||
| + | digitalWrite(fanPin2, | ||
| + | delay(1000); | ||
| + | digitalWrite(fanPin1, | ||
| + | analogWrite(fanPin2, | ||
| + | delay(1000); | ||
| + | | ||
| + | / | ||
| + | analogWrite(fanPin2, | ||
| + | delay(1000); | ||
| + | digitalWrite(fanPin1, | ||
| + | digitalWrite(fanPin2, | ||
| + | delay(1000); | ||
| + | } | ||
| + | |||
| + | void affiche(){ | ||
| + | mylcd.clear(); | ||
| + | mylcd.setCursor(2, | ||
| + | mylcd.print(" | ||
| + | mylcd.setCursor(3, | ||
| + | mylcd.print(" | ||
| + | } | ||
| + | |||
| + | void ledON(){ | ||
| + | digitalWrite(led_y, | ||
| + | delay(2000); | ||
| + | } | ||
| + | |||
| + | void ledOFF(){ | ||
| + | digitalWrite(led_y, | ||
| + | delay(2000); | ||
| + | } | ||
| + | |||
| + | void capt_temp(){ | ||
| + | | ||
| + | if (xht.receive(dht)) { //Returns true when checked correctly | ||
| + | Serial.print(" | ||
| + | Serial.print(dht[0]); | ||
| + | Serial.print(" | ||
| + | Serial.print(" | ||
| + | Serial.print(dht[2]); | ||
| + | Serial.println(" | ||
| + | |||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | mylcd.print(dht[2]); | ||
| + | mylcd.print(" | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | mylcd.print(dht[0]); | ||
| + | mylcd.print(" | ||
| + | |||
| + | delay(200); | ||
| + | } else { //Read error | ||
| + | Serial.println(" | ||
| + | } | ||
| + | delay(1000); | ||
| + | } | ||
| + | |||
| + | 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, | ||
| + | mylcd.print(" | ||
| + | mylcd.setCursor(3, | ||
| + | mylcd.print(water_val); | ||
| + | delay(2000); | ||
| + | } | ||
| + | |||
| + | void LED_RVB(){// | ||
| + | colorWipe(strip.Color(255, | ||
| + | colorWipe(strip.Color( | ||
| + | colorWipe(strip.Color( | ||
| + | |||
| + | // Do a theater marquee effect in various colors... | ||
| + | theaterChase(strip.Color(127, | ||
| + | theaterChase(strip.Color(127, | ||
| + | theaterChase(strip.Color( | ||
| + | |||
| + | rainbow(10); | ||
| + | theaterChaseRainbow(50); | ||
| + | } | ||
| + | /* | ||
| + | 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(" | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | myservoP.write(0); | ||
| + | btnFlag = 0; | ||
| + | } | ||
| + | } | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | // select one of door cards. UID and SAK are mfrc522.uid. | ||
| + | |||
| + | // save UID | ||
| + | Serial.print(F(" | ||
| + | for (byte i = 0; i < mfrc522.uid.size; | ||
| + | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); | ||
| + | // | ||
| + | Serial.print(mfrc522.uid.uidByte[i]); | ||
| + | password = password + String(mfrc522.uid.uidByte[i]); | ||
| + | } | ||
| + | // | ||
| + | if(password == " | ||
| + | { | ||
| + | Serial.println(" | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.clear(); | ||
| + | mylcd.print(" | ||
| + | myservoP.write(180); | ||
| + | password = ""; | ||
| + | btnFlag = 1; | ||
| + | } | ||
| + | else //The card number is wrong,LCD displays error | ||
| + | { | ||
| + | password = ""; | ||
| + | mylcd.setCursor(0, | ||
| + | mylcd.print(" | ||
| + | } | ||
| + | // | ||
| + | } | ||
| + | |||
| + | void ShowReaderDetails() { | ||
| + | // attain the MFRC522 software | ||
| + | byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); | ||
| + | Serial.print(F(" | ||
| + | Serial.print(v, | ||
| + | if (v == 0x91) | ||
| + | Serial.print(F(" | ||
| + | else if (v == 0x92) | ||
| + | Serial.print(F(" | ||
| + | else | ||
| + | Serial.print(F(" | ||
| + | Serial.println("" | ||
| + | // when returning to 0x00 or 0xFF, may fail to transmit communication signals | ||
| + | if ((v == 0x00) || (v == 0xFF)) { | ||
| + | Serial.println(F(" | ||
| + | } | ||
| + | } | ||
| + | */ | ||
| + | |||
| + | </ | ||
| + | ====== SmartHome MicroPython3 ====== | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/smarthome.1682680365.txt.gz · Dernière modification : de gerardadmin
