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/05/01 16:23] – [GPIO ESP32 Et Capteurs/Actionneurs] gerardadminstart:arduino:esp32:smarthome [2025/08/29 21:36] (Version actuelle) – [DemoFablab] admin
Ligne 13: Ligne 13:
          
     * Tutoriel-Télécharger👉https://fs.keyestudio.com/KS5009     * Tutoriel-Télécharger👉https://fs.keyestudio.com/KS5009
 +    * [[https://docs.keyestudio.com/projects/KS5009/en/latest/|KS5009 KeyesStudio FR]]
  
 ===== 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 23 => Gaz 
-    *GPIO 17 => DHT11 Temperature 
     *GPIO 21=SDA => I2C(1)     *GPIO 21=SDA => I2C(1)
     *GPIO 22=SCL => I2C(1)     *GPIO 22=SCL => I2C(1)
-    *I2C  0x27 => Afficheur +    *GPIO 23 => Gaz 
-    *I2C  0x28 => RFID , Carte = 131233147231 , Badge = 243636633+    *GPIO 25 => BUZZER 
 +    *GPIO 26 => LED Neopixel (4 leds RVB) 
 +    *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 |}} 
 + 
 + 
 +[[start:arduino:esp32:smart:micropython|Programmes en Micropython]] 
  
 ==== Test Variation LED ==== ==== Test Variation LED ====
Ligne 244: 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;  // create servo object to control a servo Servo myservo;  // create servo object to control a servo
                 // 16 servo objects can be created on the ESP32                 // 16 servo objects can be created on the ESP32
Ligne 274: 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 594: 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++;    //Automatically increments by 1 to count the clicked button times            btn_count++;    //Automatically increments by 1 to count the clicked button times 
Ligne 971: Ligne 981:
 } // longPressStop2 } // longPressStop2
 </code> </code>
 +==== DemoFablab ====
 +
 +<code c demofablab.ino>
 +#include <Adafruit_NeoPixel.h>
 +#include <ESP32Servo.h>
 +#include <Wire.h>
 +#include <LiquidCrystal_I2C.h>
 +#include "xht11.h"
 +
 +//#include <analogWrite.h>
 +#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    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__
 + #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
 +#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, LED_PIN, NEO_GRB + NEO_KHZ800);
 +LiquidCrystal_I2C mylcd(0x27,16,2);
 +
 +Servo myservoP;  
 +Servo myservoF;
 +
 + 
 +int pos = 0;    // variable to store the servo position
 +int servoPinP = 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 SDA, if doesn't match,please check your address with i2c.
 +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(); 
 +  
 +  /*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.show();            // Turn OFF all pixels ASAP
 +  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
 +
 +  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(fanPin2, OUTPUT);
 +
 +mylcd.init();
 +mylcd.backlight();
 +
 +pinMode(led_y, OUTPUT);  //Set pin to output mode
 +}
 +
 +
 +// 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 'packed' 32-bit value, which you can get by calling
 +// strip.Color(red, green, blue) as shown in the loop() function above),
 +// and a delay time (in milliseconds) between pixels.
 +void colorWipe(uint32_t color, int wait) {
 +  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
 +    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
 +    strip.show();                          //  Update strip to match
 +    delay(wait);                           //  Pause for a moment
 +  }
 +}
 +
 +// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
 +// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
 +// 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++) { //  'b' counts from 0 to 2...
 +      strip.clear();         //   Set all pixels in RAM to 0 (off)
 +      // 'c' counts up from 'b' to end of strip in steps of 3...
 +      for(int c=b; c<strip.numPixels(); c += 3) {
 +        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
 +      }
 +      strip.show(); // Update strip with new contents
 +      delay(wait);  // Pause for a moment
 +    }
 +  }
 +}
 +
 +// 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<strip.numPixels(); i++) { // For each pixel in strip...
 +      // 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 'truer' colors
 +      // before assigning to each pixel:
 +      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
 +    }
 +    strip.show(); // Update strip with new contents
 +    delay(wait);  // Pause for a moment
 +  }
 +}
 +
 +// 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++) { //  'b' counts from 0 to 2...
 +      strip.clear();         //   Set all pixels in RAM to 0 (off)
 +      // 'c' counts up from 'b' to end of strip in increments of 3...
 +      for(int c=b; c<strip.numPixels(); c += 3) {
 +        // hue of pixel 'c' is offset by an amount to make one full
 +        // 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)); // hue -> RGB
 +        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
 +      }
 +      strip.show();                // Update strip with new contents
 +      delay(wait);                 // Pause for a moment
 +      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);              // tell servo to go to position in variable 'pos'
 +    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
 +    myservoP.write(pos);              // tell servo to go to position in variable 'pos'
 +    delay(15);                       // waits 15ms for the servo to reach the position
 +  }
 +}
 +
 +
 +void ventilateur001(){
 +  digitalWrite(fanPin1, LOW); //pwm = 0
 +  analogWrite(fanPin2, 90);
 +  delay(1000);
 +  digitalWrite(fanPin1, LOW);
 +  digitalWrite(fanPin2, LOW);
 +  delay(1000);
 +  digitalWrite(fanPin1, LOW); //pwm = 0
 +  analogWrite(fanPin2, 50);
 +  delay(1000);
 +  digitalWrite(fanPin1, LOW);
 +  digitalWrite(fanPin2, LOW);
 +  delay(1000);
 +  digitalWrite(fanPin1, LOW); //pwm = 0
 +  analogWrite(fanPin2, 10);
 +  delay(1000);
 +  
 +  /*digitalWrite(fanPin1,LOW); //pwm = 255
 +  analogWrite(fanPin2, 100);
 +  delay(1000);
 +  digitalWrite(fanPin1, LOW);
 +  digitalWrite(fanPin2, LOW);
 +  delay(1000);*/
 +}
 +
 +void affiche(){
 +  mylcd.clear();
 +  mylcd.setCursor(2, 0);
 +  mylcd.print("Bienvenue au");
 +  mylcd.setCursor(3, 1);
 +  mylcd.print("Castellab");
 +}
 +
 +void ledON(){     //The code inside the loop function will always run in a loop
 +  digitalWrite(led_y, HIGH);  //Light up the LED
 +  delay(2000);     //Delay statement, in ms
 +}
 +
 +void ledOFF(){
 +  digitalWrite(led_y, LOW);   //Close the LED
 +  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>
 +====== SmartHome MicroPython3 ======
  
  
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/smarthome.1682951035.txt.gz · Dernière modification : de gerardadmin