Chatière Electronique - Arduino Nano LCD RFID Sécurité Porte

Tout nos projets

Chatière electronique - Arduino Nano LCD RFID Sécurité porte

Chatière éléctronique, produits et premier test

Comment peut on facilement réaliser un projet électronique avec Arduino pour créer une chatière permettant la sortie et l'entrée de votre chat mais pas celui du voisin! Une nouvelle version sera mise à jour bienôt! Objets utilisés pour ce projet: 2 LEDs coloriés. Lecteur de carte RFID d'induction. 1 servo moteur. 1 carte de dévéloppement Arduino. 1 d'extension ProtoShield. 2 platines d'experimentation. Des resitences, des cables jump et 1 cable d'alimentation USB.

Produit final, test en ligne

Ce produit est une invention, ne copiez pas sans précisez l'origine et l'inventeur du produit. La viédo est mise à titre éducative et toute copie à titre commerciale du produit sera poursuivie. Seules les copies à titre personnel sont permises.

Code source complet:

#include <SPI.h> #include <MFRC522.h> #include <Servo.h> #include <Stepper.h> #include <LiquidCrystal_I2C.h> #include <Wire.h> #define I2C_ADDR 0x27 // <<- Add your address here. #define Rs_pin 0 #define Rw_pin 1 #define En_pin 2 #define BACKLIGHT_PIN 3 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); Servo myservo; #define RST_PIN 9 // #define SS_PIN 10 // MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance String read_rfid; String ok_rfid_1="c4b256f"; String ok_rfid_n=""; int peezo = 5; int ledPin1 = 7; int ledPin2 = 6,butPin=8; int servopin = 4; int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin int posClosed=30; int posOpened=120; int pos = 0,newcard=0; //stepper #define STEPS 32 // Number of steps per revolution of Internal shaft int Steps2Take; // 2048 = 1 Revolution // In1, In2, In3, In4 in the sequence 1-3-2-4 //Stepper small_stepper(STEPS, 2,3,4,5); void setup() { Serial.begin(9600); // Initialize serial communications with the PC while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details //Serial.println(F("Scan PICC to see UID, type, and data blocks...")); pinMode(ledPin1,OUTPUT); pinMode(ledPin2,OUTPUT); pinMode(peezo, OUTPUT); digitalWrite(peezo, LOW); pinMode(butPin, INPUT); digitalWrite(butPin, LOW); myservo.attach(servopin); myservo.write(posClosed); lcd.clear(); lcd.begin (7,2); // LCD Backlight ON lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.home (); lcd.print("Chatiere ready"); flashg(2,200); } void dump_byte_array(byte *buffer,byte bufferSize){ read_rfid=""; for(byte i=0;i<bufferSize;i++){ read_rfid=read_rfid+String(buffer[i],HEX); } } void flashg(int howmany,int temps){ for (int i=0;i<howmany;i++){ digitalWrite(ledPin2,HIGH);digitalWrite(peezo,HIGH);delay(temps);digitalWrite(ledPin2,LOW);digitalWrite(peezo,LOW);delay(temps); } } void flashr(int howmany,int temps){ for (int i=0;i<howmany;i++){ digitalWrite(ledPin1,HIGH);digitalWrite(peezo,HIGH);delay(temps);digitalWrite(ledPin1,LOW);digitalWrite(peezo,LOW);delay(temps); } } void open_lock(){ flashg(2,100); myservo.write(posOpened); delay(6000);myservo.write(posClosed); } void dont_open(){ flashr(2,300); myservo.write(posClosed); //small_stepper.setSpeed(700); //Max seems to be 700 //Steps2Take = 200; // Rotate CW //small_stepper.step(Steps2Take); } void loop() { if(digitalRead(butPin)==HIGH){ if(newcard==0){ newcard=1; lcd.clear(); lcd.setCursor (0,0); lcd.print("New card?"); lcd.setCursor (0,1); lcd.print("scan it now"); }else{ ok_rfid_1=ok_rfid_n; lcd.clear(); lcd.setCursor (0,0); lcd.print("New card"); lcd.setCursor (0,1); lcd.print("successfully saved"); newcard=0; } flashg(1,100); } // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } dump_byte_array(mfrc522.uid.uidByte,mfrc522.uid.size); Serial.println(read_rfid); // Dump debug info about the card; PICC_HaltA() is automatically called //mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //Serial.println(read_rfid); if(newcard==1){ lcd.clear(); lcd.setCursor (0,0); lcd.print("Card nb ");lcd.print(read_rfid); lcd.setCursor (0,1); lcd.print("Save it?"); ok_rfid_n=read_rfid; } if(read_rfid==ok_rfid_1){ if(newcard==0){ lcd.clear(); lcd.setCursor (0,0); lcd.print("Card accepted"); lcd.setCursor (0,1); lcd.print("Opening door!"); open_lock(); flashg(1,100); } } else{ if(newcard==0){ lcd.clear(); lcd.setCursor (0,0); lcd.print("Card rejected"); lcd.setCursor (0,1); lcd.print("not accepted"); dont_open(); flashr(1,100); }else{ flashg(1,100); lcd.clear(); lcd.setCursor (0,0); lcd.print("Card nb ");lcd.print(read_rfid); lcd.setCursor (0,1); lcd.print("Save it?"); ok_rfid_n=read_rfid; } } } void ShowReaderDetails() { // Get the MFRC522 software version 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 0x00 or 0xFF is returned, communication probably failed if ((v == 0x00) || (v == 0xFF)) { Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); } }

Tag » Arduino Puce Rfid Chat