SHARE
TWEET

Untitled

kelsey13roberts Jun 19th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SimpleDHT.h>
  2.  
  3.  
  4. const int photoPin = A0;
  5. const int pinBlue= 9;
  6. const int pinRed =10;
  7. const int pinGreen = 11;
  8. const int pinButton = 2;
  9. int photoVal = 0;
  10. int lightVal = 0;
  11. unsigned long timeVal;
  12. int minimum = 5000;
  13. int maximum = -5000;
  14. int newButton = 0;
  15. int lastButton = 0;
  16. int pinDHT11 = 2;
  17. SimpleDHT11 dht11;
  18.  
  19.  
  20. void setup()
  21. {
  22.   Serial.begin (9600);
  23.   pinMode (pinButton, INPUT);
  24.   pinMode (photoPin, INPUT);
  25.   pinMode (pinBlue, OUTPUT);
  26.   pinMode (pinGreen, OUTPUT);
  27.   pinMode (pinRed, OUTPUT);
  28.   analogWrite (pinBlue, 255);
  29.   analogWrite (pinRed, 0);
  30.   analogWrite (pinGreen, 0);
  31.   delay (500);
  32.   analogWrite (pinBlue, 0);
  33.   analogWrite (pinRed, 255);
  34.   analogWrite (pinGreen, 0);
  35.   delay (500);
  36.   analogWrite (pinBlue, 0);
  37.   analogWrite (pinRed, 0);
  38.   analogWrite (pinGreen, 255);
  39.   delay (500);
  40.   analogWrite (pinBlue, 0);
  41.   analogWrite (pinRed, 0);
  42.   analogWrite (pinGreen, 0);
  43. }
  44.  
  45. void calibrate()
  46. {
  47.   minimum = 1000;
  48.   maximum = 0;
  49.   digitalWrite (pinGreen, HIGH);
  50.   timeVal = millis();
  51.   while (millis() - timeVal < 5000)
  52.   {
  53.     photoVal = analogRead (pinButton);
  54.     if (photoVal > maximum)
  55.     {
  56.       maximum = photoVal;
  57.     }
  58.     else if (photoVal < minimum)
  59.     {
  60.       minimum = photoVal;
  61.     }
  62.   }
  63.   digitalWrite (pinGreen, LOW);
  64.   Serial.println (minimum);
  65.   Serial.println (maximum);
  66. }
  67.  
  68. void loop() {
  69.   newButton = digitalRead (pinButton);
  70.   //Serial.print (newButton);
  71.   if (newButton == HIGH && lastButton == LOW)
  72.   {
  73.     calibrate ();
  74.   }
  75.  
  76.   lastButton = newButton;
  77.   byte temperature = 0;
  78.   byte humidity = 0;
  79.   dht11.read(pinDHT11, &temperature, &humidity, NULL);
  80.   Serial.print("Sample OK: ");
  81.   Serial.print((int)temperature); Serial.print(" *C, ");
  82.   Serial.print((int)humidity); Serial.println(" %");
  83.  
  84.     if (humidity > 85)
  85.   {
  86.     digitalWrite (pinRed, HIGH);
  87.   }
  88. }
  89.  
  90.  
  91. boolean debounce(boolean last)
  92. {
  93.   boolean current = digitalRead(photoPin);
  94.   if (last != current)
  95.   {
  96.     delay(5);
  97.     current = digitalRead(pinButton);
  98.   }
  99.   return current;
  100. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top