#include #include #include #include #include "xht11.h" //#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 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 // 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 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?")); } } */