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édente | |||
start:arduino:esp32:smarthome [2025/08/29 16:29] – [DemoFablab] admin | start:arduino:esp32:smarthome [2025/08/29 21:36] (Version actuelle) – [DemoFablab] admin | ||
---|---|---|---|
Ligne 988: | Ligne 988: | ||
#include < | #include < | ||
#include < | #include < | ||
+ | #include " | ||
+ | |||
//#include < | //#include < | ||
#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 | ||
+ | #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__ | ||
# | # | ||
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 | + | |
// 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, | Adafruit_NeoPixel strip(LED_COUNT, | ||
LiquidCrystal_I2C mylcd(0x27, | LiquidCrystal_I2C mylcd(0x27, | ||
- | Servo myservo; | + | 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, | + | int servoPinP = 13; |
- | int servoPin = 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() { | void setup() { | ||
Ligne 1019: | Ligne 1035: | ||
#endif | #endif | ||
// END of Trinket-specific code. | // END of Trinket-specific code. | ||
+ | Serial.begin(115200); | ||
+ | Wire.begin(); | ||
+ | |||
+ | / | ||
+ | ShowReaderDetails(); | ||
+ | Serial.println(F(" | ||
+ | pinMode(btnPin, | ||
+ | mylcd.setCursor(0, | ||
+ | mylcd.print(" | ||
+ | | ||
strip.begin(); | strip.begin(); | ||
strip.show(); | strip.show(); | ||
strip.setBrightness(50); | strip.setBrightness(50); | ||
- | | + | |
+ | |||
+ | pinMode(waterPin, | ||
+ | myservoF.attach(servoPinF, | ||
+ | myservoF.write(140); | ||
+ | delay(200); | ||
pinMode(fanPin1, | pinMode(fanPin1, | ||
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, | + | capt_temp(); |
- | | + | |
- | 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); | + | |
- | + | ||
- | servo_porte(); | + | |
ledOFF(); | ledOFF(); | ||
- | + | affichefenetre(); | |
- | // | + | 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 | ||
- | | + | |
delay(15); | delay(15); | ||
} | } | ||
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 | ||
- | | + | |
delay(15); | delay(15); | ||
} | } | ||
Ligne 1183: | Ligne 1203: | ||
void affiche(){ | void affiche(){ | ||
+ | mylcd.clear(); | ||
mylcd.setCursor(2, | mylcd.setCursor(2, | ||
mylcd.print(" | mylcd.print(" | ||
mylcd.setCursor(3, | mylcd.setCursor(3, | ||
mylcd.print(" | mylcd.print(" | ||
- | // | ||
} | } | ||
Ligne 1199: | Ligne 1219: | ||
delay(2000); | 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 ====== | ====== SmartHome MicroPython3 ====== |
/home/chanteri/www/fablab37110/data/pages/start/arduino/esp32/smarthome.txt · Dernière modification : de admin