#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 5 //define green LED pin
#define LED_R 4 //define red LED
#define BUZZER 2 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int x;
int y;
int z;
int pushButton = 2;
boolean park = false;
int redPin = 7; // R petal on RGB LED module connected to digital pin 11
int greenPin = 8; // G petal on RGB LED module connected to digital pin 9
int bluePin = 6;
Servo myServo; //define servo name
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
myServo.attach(3); //servo pin
myServo.write(50); //servo start position
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(BUZZER, OUTPUT);
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT);
// pinMode(5, OUTPUT);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
pinMode(4, OUTPUT);
noTone(BUZZER);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
Serial.println("Put your card to the reader...");
Serial.println();
}
void loop()
{
if (Serial.available() > 0)
{
int data = Serial.read();
Serial.println(data);
switch (data)
{
case 66:
Serial.println("data2");
digitalWrite(redPin,HIGH);
break;
case 65:
Serial.println("data1");
digitalWrite(redPin,LOW);
digitalWrite(bluePin,LOW);
digitalWrite(greenPin,LOW);
break;
case 67:
digitalWrite(bluePin,HIGH);
break;
case 68:
digitalWrite(greenPin,HIGH);
break;
case 69:
digitalWrite(bluePin,HIGH);
delay(1000);
digitalWrite(greenPin,HIGH);
delay(500);
digitalWrite(redPin,HIGH);
delay(500);
digitalWrite(redPin,LOW);
digitalWrite(bluePin,LOW);
digitalWrite(greenPin,LOW);
delay(800);
color(128,0,255);
delay(800);
color(255,0,0);
delay(800);
color(255,255,0);
delay(800);
color(255,255,255);
delay(800);
digitalWrite(bluePin,HIGH);
delay(1000);
digitalWrite(greenPin,HIGH);
delay(500);
digitalWrite(redPin,HIGH);
delay(1500);
digitalWrite(redPin,LOW);
digitalWrite(bluePin,LOW);
digitalWrite(greenPin,LOW);
delay(1000);
color(128,0,255);
delay(1000);
color(255,0,0);
delay(1500);
color(255,255,0);
delay(1000);
color(255,255,255);
delay(800);
digitalWrite(redPin,LOW);
digitalWrite(bluePin,LOW);
digitalWrite(greenPin,LOW);
break;
}
}
int buttonState = digitalRead(pushButton);
if (buttonState == 1)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Soil dry , water ");
lcd.setCursor(0,1);
lcd.print("system activated");
digitalWrite(5, LOW);
}
else if (buttonState == 0)
{
lcd.clear();
digitalWrite(5, HIGH);
}
if (analogRead(A3) > 726)
{
lcd.clear();
lcd.setCursor(0, 0);
digitalWrite(4,HIGH);
lcd.print("THEFT ALARM");//
delay(500);
digitalWrite(4,LOW);
delay(200);
digitalWrite(4,HIGH);
delay(200);
digitalWrite(4,LOW);
delay(200);
digitalWrite(4,HIGH);
delay(200);
digitalWrite(4,LOW);
delay(200);
digitalWrite(4,HIGH);
delay(500);
digitalWrite(4,LOW);
delay(200);
digitalWrite(4,HIGH);
delay(200);
digitalWrite(4,LOW);
delay(200);
digitalWrite(4,HIGH);
delay(200);
digitalWrite(4,LOW);
lcd.clear();
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "84 C9 90 79") //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Welcome to the");
lcd.setCursor(0, 1); // set the cursor to column 0, line 0
lcd.print("Smart Society");
Serial.println();
myServo.write(180);
delay(3000);
myServo.write(50);
lcd.clear();
//digitalWrite(LED_G, LOW);
park = true;
}
else {
Serial.println(" Access denied");
digitalWrite(4,HIGH);
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Access denied");//
delay(1500);
digitalWrite(4,LOW);
delay(1500);
lcd.clear();
}
if (analogRead(A0) > 900)
{
x = 0 ;
}
else {
x = 1;
}
if (analogRead(A1) > 900)
{
y = 0 ;
}
else {
y = 1;
}
if (analogRead(A2) > 900)
{
z = 0 ;
}
else {
z = 1;
}
if (x == 0 && y == 0 && z == 0 )
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1500);
lcd.setCursor(0,1); // set the cursor to column 0, line 0
lcd.print("A1");
lcd.setCursor(5,1); // set the cursor to column 0, line 0
lcd.print("A2");
lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
lcd.print("A3");
delay(4500);
lcd.clear();
}
else if (x == 0 && y == 1 && z == 1)
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1800);
lcd.setCursor(0,1); // set the cursor to column 0, line 0
lcd.print("A1");
// lcd.setCursor(5,1); // set the cursor to column 0, line 0
// lcd.print("A2");
//
// lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
// lcd.print("A3");
delay(3800);
lcd.clear();
}
else if (x == 0 && y == 1 && z == 0 )
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1800);
lcd.setCursor(0,1); // set the cursor to column 0, line 0
lcd.print("A1");
// lcd.setCursor(5,1); // set the cursor to column 0, line 0
// lcd.print("A2");
lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
lcd.print("A3");
delay(3800);
lcd.clear();
}
else if (x == 1 && y == 1 && z == 0 )
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1800);
// lcd.setCursor(0,1); // set the cursor to column 0, line 0
// lcd.print("A1");
//
// lcd.setCursor(5,1); // set the cursor to column 0, line 0
// lcd.print("A2");
lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
lcd.print("A3");
delay(3800);
lcd.clear();
}
else if (x == 0 && y == 0 && z == 1 )
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1800);
lcd.setCursor(0,1); // set the cursor to column 0, line 0
lcd.print("A1");
lcd.setCursor(5,1); // set the cursor to column 0, line 0
lcd.print("A2");
// lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
// lcd.print("A3");
delay(3800);
lcd.clear();
}
else if (x == 1 && y == 1 && z == 1 )
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1800);
lcd.setCursor(0,1); // set the cursor to column 0, line 0
lcd.print("none");
// lcd.setCursor(5,1); // set the cursor to column 0, line 0
// lcd.print("A2");
//
// lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
// lcd.print("A3");
delay(3800);
lcd.clear();
}
else if (x == 1 && y == 0 && z == 0 )
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1800);
// lcd.setCursor(0,1); // set the cursor to column 0, line 0
// lcd.print("A1");
lcd.setCursor(5,1); // set the cursor to column 0, line 0
lcd.print("A2");
lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
lcd.print("A3");
delay(3800);
lcd.clear();
}
else if (x == 1 && y == 0 && z == 1 )
{
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Slots free : ");
delay(1800);
// lcd.setCursor(0,1); // set the cursor to column 0, line 0
// lcd.print("A1");
lcd.setCursor(5,1); // set the cursor to column 0, line 0
lcd.print("A2");
//lcd.setCursor(10,1 ); // set the cursor to column 0, line 0
// lcd.print("A3");
delay(3800);
lcd.clear();
}
}
void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function
{
analogWrite(redPin, 255-red); // PWM signal output
analogWrite(greenPin, 255-green); // PWM signal output
analogWrite(bluePin, 255-blue); // PWM signal output
}
Comments