Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SimpleDHT.h>
- const int photoPin = A0;
- const int pinBlue= 9;
- const int pinRed =10;
- const int pinGreen = 11;
- const int pinButton = 2;
- int photoVal = 0;
- int lightVal = 0;
- unsigned long timeVal;
- int minimum = 5000;
- int maximum = -5000;
- int newButton = 0;
- int lastButton = 0;
- int pinDHT11 = 2;
- SimpleDHT11 dht11;
- void setup()
- {
- Serial.begin (9600);
- pinMode (pinButton, INPUT);
- pinMode (photoPin, INPUT);
- pinMode (pinBlue, OUTPUT);
- pinMode (pinGreen, OUTPUT);
- pinMode (pinRed, OUTPUT);
- analogWrite (pinBlue, 255);
- analogWrite (pinRed, 0);
- analogWrite (pinGreen, 0);
- delay (500);
- analogWrite (pinBlue, 0);
- analogWrite (pinRed, 255);
- analogWrite (pinGreen, 0);
- delay (500);
- analogWrite (pinBlue, 0);
- analogWrite (pinRed, 0);
- analogWrite (pinGreen, 255);
- delay (500);
- analogWrite (pinBlue, 0);
- analogWrite (pinRed, 0);
- analogWrite (pinGreen, 0);
- }
- void calibrate()
- {
- minimum = 1000;
- maximum = 0;
- digitalWrite (pinGreen, HIGH);
- timeVal = millis();
- while (millis() - timeVal < 5000)
- {
- photoVal = analogRead (pinButton);
- if (photoVal > maximum)
- {
- maximum = photoVal;
- }
- else if (photoVal < minimum)
- {
- minimum = photoVal;
- }
- }
- digitalWrite (pinGreen, LOW);
- Serial.println (minimum);
- Serial.println (maximum);
- }
- void loop() {
- newButton = digitalRead (pinButton);
- //Serial.print (newButton);
- if (newButton == HIGH && lastButton == LOW)
- {
- calibrate ();
- }
- lastButton = newButton;
- byte temperature = 0;
- byte humidity = 0;
- dht11.read(pinDHT11, &temperature, &humidity, NULL);
- Serial.print("Sample OK: ");
- Serial.print((int)temperature); Serial.print(" *C, ");
- Serial.print((int)humidity); Serial.println(" %");
- if (humidity > 85)
- {
- digitalWrite (pinRed, HIGH);
- }
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(photoPin);
- if (last != current)
- {
- delay(5);
- current = digitalRead(pinButton);
- }
- return current;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement