Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- zadnje_ocitanje=millis();
- void readLIGHT()
- {
- if ((millis()-zadnje_ocitanje)>8000)
- {
- zadnje_ocitanje=millis();
- String string1 = "Lighting percentage: ";
- String string2 = string1 + light;
- int value_pir = digitalRead(PIR);
- String string3 = "Motion detector: ";
- String string4 = string3 + value_pir;
- light = map(analogRead(ldrPin) , 0 , 1024 , 1 , 100);
- Serial.println(string2);
- Serial.println(string4);
- if ((light < 60) && ( value_pir == HIGH) )
- {
- digitalWrite(lightingOutput, HIGH);
- Serial.println("Lighting ON");
- }
- else
- {
- digitalWrite(lightingOutput, LOW);
- Serial.println("Lighting OFF");
- }
- }
- }
- #include <Servo.h>
- #include "DHT.h"
- #include <SPI.h>
- #include <MFRC522.h>
- #include <Wire.h>
- #define SERVO_PIN 8
- #define SS_PIN 10
- #define RST_PIN 9
- #define lightingOutput A2
- #define ldrPin A0
- #define PIR 7
- #define ledGrn 6
- #define heatingOutput A3
- #define coolingOutput A4
- #define DHTPIN 2
- #define DHTTYPE DHT11
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create instance of our reader
- Servo myservo; // Create instance of our motor /// create servo object to control a servo
- DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
- int pos;
- int light;
- float h, t;
- int soundSensor=A1;
- int LED=5;
- boolean LEDStatus=false;
- const int buzzer = 4;
- long zadnje_ocitanje=0;
- void setup()
- {
- Serial.begin(9600);
- dht.begin();
- SPI.begin();
- mfrc522.PCD_Init();
- myservo.attach(SERVO_PIN);
- myservo.write(0);
- pinMode(heatingOutput, OUTPUT);
- pinMode(coolingOutput, OUTPUT);
- pinMode(ledGrn, OUTPUT);
- pinMode(soundSensor,INPUT);
- pinMode(LED,OUTPUT);
- pinMode(lightingOutput, OUTPUT);
- zadnje_ocitanje=millis();
- }
- void loop() {
- Serial.println("nHOME AUTOMATIONn");
- readSOUND();
- readRFID();
- readDHT();
- readLIGHT();
- delay(1000);
- }
- ////////////////////////////////////////////
- void readRFID()
- {
- //Look for new cards
- if ( ! mfrc522.PICC_IsNewCardPresent() ) {
- return;
- }
- if ( ! mfrc522.PICC_ReadCardSerial() ) {
- return;
- }
- // If a card is detected, execute the following:
- Serial.println("Time to open");
- // Print the card's ID
- String content = "";
- byte letter;
- for ( byte i = 0; i < mfrc522.uid.size; i++ ) {
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- if ( i < mfrc522.uid.size - 1 ) content += "-";
- }
- content.toUpperCase();
- Serial.println();
- Serial.println("UID tag :’" + content + "‘");
- if (content == "C0-E5-86-25") {
- Serial.println("Authorized access");
- digitalWrite(ledGrn, HIGH);
- for (pos = 0; pos <= 90; pos += 1) {
- myservo.write(pos);
- delay(25);
- }
- for (pos = 90; pos >= 0; pos -= 1) {
- myservo.write(pos);
- delay(70);
- digitalWrite(ledGrn, LOW);
- }
- }
- else {
- Serial.println("Access Denied");
- tone(buzzer, 1000, 6000);
- }
- }
- //////////////////////////////////////////////////////
- void readDHT()
- {
- h = dht.readHumidity();
- t = dht.readTemperature();
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %t");
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.print(" *C ");
- Serial.println();
- if (t < 18) //if temperature is less than 18 celcius
- {
- digitalWrite(heatingOutput, HIGH);
- Serial.print("Heating activatedn");
- }
- else
- {
- digitalWrite(heatingOutput, LOW);
- }
- if (t > 22) //if temperature is more than 22 celcius
- {
- digitalWrite(coolingOutput, HIGH);
- Serial.print("Cooling activatedn");
- }
- else
- {
- digitalWrite(coolingOutput, LOW);
- }
- }
- //////////////////////////////////////////////////////
- void readLIGHT()
- {
- if ((millis()-zadnje_ocitanje)>6000)
- {
- zadnje_ocitanje=millis();
- // sadasnje vrijeme postaje zadnje ocitanje
- String string1 = "Lighting percentage: ";
- String string2 = string1 + light;
- int value_pir = digitalRead(PIR);
- String string3 = "Motion detector: ";
- String string4 = string3 + value_pir;
- light = map(analogRead(ldrPin) , 0 , 1024 , 1 , 100);
- Serial.println(string2);
- Serial.println(string4);
- if ((light < 50) && ( value_pir == HIGH) )
- {
- digitalWrite(lightingOutput, HIGH);
- Serial.println("Lighting ON");
- }
- else
- {
- digitalWrite(lightingOutput, LOW);
- Serial.println("Lighting OFF");
- }
- }
- }
- //////////////////////////////////////////////////////////////
- void readSOUND()
- {
- int SensorData=analogRead(soundSensor);
- if(SensorData>600){
- if(LEDStatus==false){
- LEDStatus=true;
- digitalWrite(LED,HIGH);
- }
- else{
- LEDStatus=false;
- digitalWrite(LED,LOW);
- }
- delay(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement