Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastIO.h>
- #include <I2CIO.h>
- #include <LCD.h>
- #include <LiquidCrystal.h>
- #include <LiquidCrystal_I2C.h>
- #include <LiquidCrystal_SR.h>
- #include <LiquidCrystal_SR2W.h>
- #include <LiquidCrystal_SR3W.h>
- #include <Wire.h>
- #include <boarddefs.h>
- #include <IRremote.h>
- #include <IRremoteInt.h>
- #include <ir_Lego_PF_BitStreamEncoder.h>
- #include <Stepper.h>
- #include "DHT.h"
- #define IN1 8
- #define IN2 9
- #define IN3 10
- #define IN4 11
- #define DHTPIN A0
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- byte threshold = 100;
- int base = 0;
- byte photoR = 1;
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- int stepsPerRevolution = 500; //koraka po punom okretanju
- int RECV_PIN = 7;
- int LED_1 = 6;
- int LED_2 = 5;
- int flag = 0;
- Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- int lightp = 0;
- void setup()
- {
- Serial.begin(9600);
- lcd.begin(16, 2);
- lcd.backlight();
- pinMode(IN1, OUTPUT);
- pinMode(IN2, OUTPUT);
- pinMode(IN3, OUTPUT);
- pinMode(IN4, OUTPUT);
- Serial.begin(9600);
- irrecv.enableIRIn(); // Start the receiver
- pinMode(LED_1, HIGH);
- pinMode(LED_2, HIGH);
- pinMode(photoR, INPUT);
- myStepper.setSpeed(60); //okretaji motora
- dht.begin(); //DHT senzor
- base = analogRead(photoR);
- }
- void loop() {
- // if (irrecv.decode(&results)) {
- // Serial.println(results.value, HEX);
- // if (results.value == 0xFF30CF) //pali osvjetljenje
- // {
- // digitalWrite(LED_1, HIGH);
- // digitalWrite(LED_2, HIGH);
- // }
- // else if (results.value == 0xFF18E7) //gasi osvjetljenje
- // {
- // digitalWrite(LED_1, LOW);
- // digitalWrite(LED_2, LOW);
- // }
- // else if (results.value == 0xFF7A85) //digni roletnu
- // {
- // myStepper.step(stepsPerRevolution);
- // }
- // else if (results.value == 0xFF10EF) //spusti roletnu
- // {
- // myStepper.step(-stepsPerRevolution);
- // }
- // irrecv.resume(); // Receive the next value
- float h = dht.readHumidity(); //varijabla za vlagu
- float t = dht.readTemperature(); // varijabla za temperaturu
- if (isnan(h) || isnan(t)) {
- Serial.println("Neuspješno očitavanje senzora! ");
- return;
- }
- Serial.print("Vlaga: ");
- Serial.print(h);
- Serial.print(" %\t");
- Serial.print("Temperatura: ");
- Serial.print(t);
- Serial.println(" *C ");
- Serial.print(analogRead(photoR));
- int light = analogRead(photoR);
- if (light < base - threshold) // low light
- {
- digitalWrite(LED_1, HIGH);
- digitalWrite(LED_2, HIGH);
- if(flag == 1)
- {
- myStepper.step(-stepsPerRevolution);
- flag = 0;
- }
- lcd.setCursor(0, 0);
- lcd.print("Vlaga: ");
- lcd.print(h);
- delay(1000);
- lcd.clear();
- lcd.print("Temp: ");
- lcd.print(t);
- delay(1000);
- lcd.clear();
- }
- // high light
- else if(light >= base - threshold)
- {
- digitalWrite(LED_1, LOW);
- digitalWrite(LED_2, LOW);
- if(flag == 0)
- {
- myStepper.step(stepsPerRevolution);
- flag = 1;
- }
- lcd.setCursor(0, 0);
- lcd.print("Vlaga: ");
- lcd.print(h);
- delay(1000);
- lcd.clear();
- lcd.print("Temp: ");
- lcd.print(t);
- delay(1000);
- lcd.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement