0% found this document useful (0 votes)
43 views6 pages

Project Code Innovian

The document describes an Arduino code for room automation using PIR and IR sensors to control lights and a fan. It also describes an Arduino code for an access control system using RFID reader, ultrasonic sensor and LCD to control a buzzer and lock.

Uploaded by

VirajReddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views6 pages

Project Code Innovian

The document describes an Arduino code for room automation using PIR and IR sensors to control lights and a fan. It also describes an Arduino code for an access control system using RFID reader, ultrasonic sensor and LCD to control a buzzer and lock.

Uploaded by

VirajReddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

/*Room automation code

Control of lights and fan in room by use of pir sensor


2 ir sensors and bluetooth module
*/

#define ledPin 4
#define ledPin1 5
#define fan1 6
#define irSensor 3
#define irSensor1 7
#define pirSensor 2
int state = 0;

void setup() {

pinMode(irSensor, INPUT);
pinMode(irSensor1, INPUT);
pinMode(pirSensor, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(fan1, OUTPUT);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(fan1, LOW);
Serial.begin(9600); // Default communication rate of the Bluetooth module
}

void loop() {

if(digitalRead(pirSensor))
{
digitalWrite(ledPin, HIGH);
if(digitalRead(irSensor))
{
digitalWrite(ledPin, LOW) ;

}
delay(100000);
if(!(digitalRead(pirSensor)))
digitalWrite(ledPin, LOW);
}
if(digitalRead(irSensor1))
{
digitalWrite(fan1, HIGH);
delay(2000);
if(digitalRead(irSensor1))
digitalWrite(fan1, LOW) ;
}

if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
if (state == '0') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON"); // Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == '1') {
digitalWrite(ledPin, LOW);
Serial.println("LED1 OFF");
state = 0;
}
if (state == '2') {
digitalWrite(ledPin1, HIGH);
Serial.println("LED: ON"); // Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == '3') {
digitalWrite(ledPin1, LOW);
Serial.println("LED1 OFF");
state = 0;
}
if (state == '4') {
digitalWrite(fan1, HIGH);
Serial.println("LED: ON"); // Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == '5') {
digitalWrite(fan1, LOW);
Serial.println("LED1 OFF");
state = 0;
delay(10000);
if(!(digitalRead(irSensor)||digitalRead(pirSensor)))
{
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(fan1, LOW);
}
}
}
/*
Entry security circuit using rfid reader
Ultrasonic sensor 16*2 LCD display
Relay and solenoid lock

*/

#include <LiquidCrystal.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 18
#define BUZZ_PIN 19
const int trigPin = 16;
const int echoPin = 17;
long duration;
int distance;
int Contrast=100;// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(14, 15, 5, 4, 3, 2);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT);
analogWrite(6,Contrast);
lcd.begin(16, 2);
// Print a message to the LCD.

Serial.begin(9600); // Initiate a serial communication


SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();
pinMode(BUZZ_PIN, OUTPUT);

}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
// Look for new cards
if(distance<10)
{ lcd.print("welcome");
delay(1000);//edit
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) == "06 F7 FE 1B")//change here the UID of the card/cards that you
want to give access
{
Serial.println("Authorized access");
Serial.println();
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Authorized access");
digitalWrite(BUZZ_PIN, HIGH);
delay(1000);
digitalWrite(BUZZ_PIN, LOW);
delay(3000);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("WELCOME");
}

else {
Serial.println(" Access denied");
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Access denied");
digitalWrite(BUZZ_PIN, HIGH);
delay(2000);
digitalWrite(BUZZ_PIN, LOW);
delay(3000);

}
}
}

You might also like