Last active
August 29, 2015 14:12
-
-
Save helxsz/4058c170580066896ad9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DHT.h> // DHT sensor library | |
#include <avr/sleep.h> // sleep library | |
#include <stdlib.h> // library for maths | |
//https://github.com/dicksondickson/PlantFriends/blob/master/sensor_node/sensor_node.ino | |
// DHT Humidity + Temperature sensor define | |
#define DHTPIN 5 // Data pin (D5) for DHT | |
#define DHTPWR 4 // turn DHT on and off via transistor | |
#define DHTTYPE DHT11 // sensor model DHT11 | |
DHT dht(DHTPIN, DHTTYPE); // define DHT11 | |
// LED Pin | |
#define led 6 | |
// Power Management Sleep cycles | |
int sleepCycledefault = 450; // Sleep cycle 450*8 seconds = 1 hour. DEFAULT 450 | |
int soilMoistThresh = 250; // soil moisture threshold. reference chart | |
void setup() | |
{ | |
//Serial.begin(9600); | |
//LED setup. | |
pinMode(led, OUTPUT); | |
// Humidity sensor setup | |
pinMode(DHTPWR, OUTPUT); | |
dht.begin(); | |
// power on indicator | |
LEDBlink(80); | |
LEDBlink(80); | |
} | |
void loop() | |
{ | |
// Humidity + Temperature sensor reading | |
// Reading temperature or humidity takes about 250 milliseconds! | |
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) | |
digitalWrite(DHTPWR, HIGH); // turn on sensor | |
delay (38); // wait for sensor to stabalize | |
int dhttempc = dht.readTemperature(); // read temperature as celsius | |
int dhthumid = dht.readHumidity(); // read humidity | |
//Serial.println(dhttempc); | |
// check if returns are valid, if they are NaN (not a number) then something went wrong! | |
if (isnan(dhttempc) || isnan(dhthumid) || dhttempc == 0 || dhthumid == 0 ) { | |
dhttempc = 0; | |
dhthumid = 0; | |
ErrorLvl += "23"; | |
} | |
delay (18); | |
digitalWrite(DHTPWR, LOW); // turn off sensor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment