SHARE
TWEET

Untitled

a guest Jul 16th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. zadnje_ocitanje=millis();
  2.  
  3. void readLIGHT()
  4.  
  5. {
  6.  
  7. if ((millis()-zadnje_ocitanje)>8000)
  8.  
  9. {
  10.  
  11. zadnje_ocitanje=millis();
  12.  
  13. String string1 = "Lighting percentage: ";
  14.  
  15. String string2 = string1 + light;
  16.  
  17. int value_pir = digitalRead(PIR);
  18.  
  19. String string3 = "Motion detector: ";
  20.  
  21. String string4 = string3 + value_pir;
  22.  
  23. light = map(analogRead(ldrPin) , 0 , 1024 , 1 , 100);
  24.  
  25. Serial.println(string2);
  26.  
  27. Serial.println(string4);
  28.  
  29. if ((light < 60) && ( value_pir == HIGH) )
  30.  
  31. {
  32.  
  33. digitalWrite(lightingOutput, HIGH);
  34.  
  35. Serial.println("Lighting ON");
  36.  
  37. }
  38.  
  39. else
  40.  
  41. {
  42.  
  43. digitalWrite(lightingOutput, LOW);
  44.  
  45. Serial.println("Lighting OFF");
  46.  
  47. }
  48.  
  49. }
  50.  
  51. }
  52.      
  53. #include <Servo.h>
  54. #include "DHT.h"
  55. #include <SPI.h>
  56. #include <MFRC522.h>
  57. #include <Wire.h>
  58.  
  59.  
  60. #define SERVO_PIN 8
  61. #define SS_PIN 10
  62. #define RST_PIN 9
  63.  
  64. #define lightingOutput A2
  65. #define ldrPin A0
  66. #define PIR 7
  67.  
  68. #define ledGrn 6
  69.  
  70. #define heatingOutput A3
  71. #define coolingOutput A4
  72.  
  73. #define DHTPIN 2
  74. #define DHTTYPE DHT11
  75.  
  76.  
  77. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create instance of our reader
  78. Servo myservo; // Create instance of our motor /// create servo object to control a servo
  79.  
  80. DHT dht(DHTPIN, DHTTYPE);     //// Initialize DHT sensor for normal 16mhz Arduino
  81.  
  82.  
  83. int pos;
  84. int light;
  85. float h, t;
  86. int soundSensor=A1;
  87. int LED=5;
  88. boolean LEDStatus=false;
  89. const int buzzer = 4;
  90.  
  91. long zadnje_ocitanje=0;  
  92.  
  93.  
  94. void setup()
  95. {
  96.  
  97.   Serial.begin(9600);
  98.   dht.begin();
  99.   SPI.begin();
  100.   mfrc522.PCD_Init();
  101.   myservo.attach(SERVO_PIN);
  102.   myservo.write(0);
  103.  
  104.  
  105.   pinMode(heatingOutput, OUTPUT);
  106.   pinMode(coolingOutput, OUTPUT);
  107.   pinMode(ledGrn, OUTPUT);
  108.   pinMode(soundSensor,INPUT);
  109.   pinMode(LED,OUTPUT);
  110.   pinMode(lightingOutput, OUTPUT);
  111.  
  112.   zadnje_ocitanje=millis();
  113.  
  114. }
  115. void loop() {
  116.  
  117.   Serial.println("nHOME AUTOMATIONn");
  118.  
  119.  
  120.   readSOUND();
  121.   readRFID();
  122.   readDHT();
  123.   readLIGHT();
  124.  
  125. delay(1000);
  126.  
  127. }
  128.  
  129.  
  130. ////////////////////////////////////////////
  131. void readRFID()
  132.  
  133. {
  134.  
  135.  
  136.  
  137.   //Look for new cards
  138.   if ( ! mfrc522.PICC_IsNewCardPresent() ) {
  139.     return;
  140.   }
  141.   if ( ! mfrc522.PICC_ReadCardSerial() ) {
  142.     return;
  143.   }
  144.   // If a card is detected, execute the following:
  145.   Serial.println("Time to open");
  146.   // Print the card's ID
  147.   String content = "";
  148.   byte letter;
  149.   for ( byte i = 0; i < mfrc522.uid.size; i++ ) {
  150.     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  151.     if ( i < mfrc522.uid.size - 1 ) content += "-";
  152.   }
  153.   content.toUpperCase();
  154.   Serial.println();
  155.   Serial.println("UID tag :’" + content + "‘");
  156.  
  157.   if (content == "C0-E5-86-25") {
  158.  
  159.     Serial.println("Authorized access");
  160.  
  161.     digitalWrite(ledGrn, HIGH);
  162.  
  163.  
  164.     for (pos = 0; pos <= 90; pos += 1) {
  165.       myservo.write(pos);
  166.       delay(25);
  167.     }
  168.     for (pos = 90; pos >= 0; pos -= 1) {
  169.       myservo.write(pos);
  170.       delay(70);
  171.  
  172.       digitalWrite(ledGrn, LOW);
  173.  
  174.     }
  175.   }
  176.   else {
  177.     Serial.println("Access Denied");
  178.       tone(buzzer, 1000, 6000);
  179.  
  180.   }
  181. }
  182.  
  183. //////////////////////////////////////////////////////
  184.  
  185. void readDHT()
  186. {
  187.  
  188.  
  189.  
  190.  
  191.   h = dht.readHumidity();
  192.   t = dht.readTemperature();
  193.   Serial.print("Humidity: ");
  194.   Serial.print(h);
  195.   Serial.print(" %t");
  196.   Serial.print("Temperature: ");
  197.   Serial.print(t);
  198.   Serial.print(" *C ");
  199.   Serial.println();
  200.  
  201.  
  202.   if (t < 18) //if temperature is less than 18 celcius
  203.   {
  204.     digitalWrite(heatingOutput, HIGH);
  205.     Serial.print("Heating activatedn");
  206.   }
  207.   else
  208.   {
  209.     digitalWrite(heatingOutput, LOW);
  210.   }
  211.  
  212.   if (t > 22) //if temperature is more than 22 celcius
  213.   {
  214.     digitalWrite(coolingOutput, HIGH);
  215.     Serial.print("Cooling activatedn");
  216.   }
  217.   else
  218.   {
  219.     digitalWrite(coolingOutput, LOW);
  220.   }
  221.  
  222. }
  223.  
  224.  
  225.  
  226. //////////////////////////////////////////////////////
  227.  
  228. void readLIGHT()
  229. {
  230.  
  231.  if ((millis()-zadnje_ocitanje)>6000)  
  232.   {    
  233.     zadnje_ocitanje=millis();
  234.   // sadasnje vrijeme postaje zadnje ocitanje
  235.  
  236.   String string1 = "Lighting percentage: ";
  237.   String string2 = string1 + light;
  238.  
  239.   int value_pir = digitalRead(PIR);
  240.  
  241.   String string3 = "Motion detector: ";
  242.   String string4 = string3 + value_pir;
  243.   light = map(analogRead(ldrPin) , 0 , 1024 , 1 , 100);
  244.   Serial.println(string2);
  245.   Serial.println(string4);
  246.  
  247.  
  248.   if ((light < 50) && ( value_pir == HIGH) )                            
  249.   {
  250.     digitalWrite(lightingOutput, HIGH);
  251.     Serial.println("Lighting ON");
  252.  
  253.   }
  254.   else
  255.   {
  256.     digitalWrite(lightingOutput, LOW);
  257.     Serial.println("Lighting OFF");
  258.  
  259.   }
  260.  
  261.  
  262.   }
  263.  
  264.  
  265. }
  266.  
  267.  
  268. //////////////////////////////////////////////////////////////
  269.  
  270. void readSOUND()
  271. {
  272.   int SensorData=analogRead(soundSensor);
  273.  
  274.  
  275.   if(SensorData>600){
  276.  
  277.     if(LEDStatus==false){
  278.         LEDStatus=true;
  279.         digitalWrite(LED,HIGH);
  280.     }
  281.     else{
  282.         LEDStatus=false;
  283.         digitalWrite(LED,LOW);
  284.     }
  285.  
  286.     delay(50);
  287.   }
  288.  
  289. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top