Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

“Pametna kuća”

#include "dht.h"
#define dht_apin A1 // Analog Pin sensor is connected to

dht DHT;

int ventilator=32;
int ledica=22;
int fotootpornik=A0;
int trig=24;
int eho=26;
int udaljenost;
int vrijeme;
int led1=53,led2=51,led3=49;
void setup(){

pinMode(ventilator,OUTPUT);
pinMode(fotootpornik,INPUT);
pinMode(ledica,OUTPUT);
pinMode(eho,INPUT);
pinMode(trig,OUTPUT);
Serial.begin(9600);

delay(500);//Delay to let system boot


Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor

}//end "setup()"
int potencijal;
void loop(){
//Start of Program

DHT.read11(dht_apin);

potencijal=analogRead(fotootpornik);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
Serial.print("Potencijal = ");
Serial.print(potencijal);
Serial.println(" ");

digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
vrijeme=pulseIn(eho,HIGH);
udaljenost=vrijeme*0.034/2;
Serial.print("Udaljenost je ");
Serial.println(udaljenost);
if(DHT.temperature>25){
digitalWrite(ventilator,HIGH);
}else{
digitalWrite(ventilator,LOW);
}
if(udaljenost<10){
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}else if(udaljenost>10 && udaljenost<20){
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
}else if(udaljenost>20 && udaljenost<30){
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
}else{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}
if(potencijal>900){
digitalWrite(ledica,HIGH);
}else{
digitalWrite(ledica,LOW);
}

delay(30);

}
“Pametna vrata”
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27,16,2);
Servo servo;

#define Password_Length 5 // the length of the password, if the


password is 4 digits long set this to 5
char Incoming_value = 0;

int Position = 10; // position of the servo


char Particular[Password_Length]; // the password length
char Specific[Password_Length] = "1234"; // the password which is
called specific in the code, change this to anything you want with the
numbers 0-9 and the letters A-D
byte Particular_Count = 0, Specific_Count = 0; // counts the amount of
digits and and checks to see if the password is correct
char Key;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}
};
bool SmartDoor = true; // the servo

byte rowPins[ROWS] = {22, 24, 26, 28};


byte colPins[COLS] = {30, 32, 34, 36};
Keypad myKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //
gets the data from the keypad

// locked charcater
byte Locked[8] = {
B01110,
B10001,
B10001,
B11111,
B11011,
B11011,
B11011,
B11111
};
// open character
byte Opened[8] = {
B01110,
B00001,
B00001,
B11111,
B11011,
B11011,
B11011,
B11111
};

int gate=13;
int prekidac=12;
int stanje;
void setup()
{

Serial.begin(9600);
pinMode(gate,OUTPUT);
pinMode(prekidac,INPUT);

servo.attach(46);
ServoClose();
servo.detach();
lcd.init();
lcd.backlight();
lcd.clear();

void loop()
{
if (Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("/n");
if (Incoming_value == '1')
digitalWrite(gate,HIGH);
else //if(Incoming_value == '0')
digitalWrite(gate,LOW);
}
if (SmartDoor == 0) // opens the smart door
{
Key = myKeypad.getKey(); // the word key = myKeypad which gets the
value

if (Key == '#') // when the '#' key is pressed

{
servo.attach(46);
lcd.clear();
ServoClose();
servo.detach();
lcd.setCursor(2,0);
lcd.print("Door Closed");
lcd.createChar(0, Locked); // prints the locked character
lcd.setCursor(14,0);
lcd.write(0); // prints the first character when you are on the
door closed page
delay(3000);
SmartDoor = 1; // closes the door
}
}

else Open(); // keeps the door open


}

void clearData()
{
while (Particular_Count != 0) // counts the digits pressed
{
Particular[Particular_Count--] = 0; // counts how many digits
}
return;
}

void ServoOpen()
{
servo.attach(46);
for (Position = 10; Position <= 100; Position += 5) {
servo.write(Position);
delay(15);
}
servo.detach();
}

void ServoClose()
{
servo.attach(46);
for (Position = 100; Position >= 10; Position -= 5) {
servo.write(Position);
delay(15);
}
servo.detach();
}

void Open()
{
lcd.setCursor(1,0);
lcd.print("Enter Password:");
Key = myKeypad.getKey(); // gets the keys you press from the keypad
if (Key)
{
Particular[Particular_Count] = Key;
lcd.setCursor(Particular_Count, 1);
lcd.print("*"); // prints '*' instead of the password
Particular_Count++; // counts the length of the password
}

if (Particular_Count == Password_Length - 1) // gets the length of


the password
{
if (!strcmp(Particular, Specific)) // counts the length and checks
to see if the password is correct
{
lcd.clear();
ServoOpen();
lcd.setCursor(2,0);
lcd.print("Door Opened");
lcd.createChar(1, Opened);
lcd.setCursor(14,0);
lcd.write(1);
lcd.setCursor(0,1);
lcd.print("Press # to Close");
SmartDoor = 0;
}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Wrong Password");
lcd.setCursor(0,1);
lcd.print("Try Again");
delay(1000);
lcd.clear();
SmartDoor = 1; // closes the smart door
}
clearData();
}
}

“Modul”
char Incoming_value = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(12,OUTPUT);
zvibpinMode(13,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("/n");
if (Incoming_value == '1')
digitalWrite(12,HIGH);
else if(Incoming_value == '0')
digitalWrite(12,LOW);
else if(Incoming_value == '2')
digitalWrite(13,HIGH);
else if(Incoming_value == '3')
digitalWrite(13,LOW);
}
}

You might also like