Last active
September 1, 2017 15:25
-
-
Save nick96/389bb2a5a0764c176bc081208578fc61 to your computer and use it in GitHub Desktop.
Code snippets for blog
This file contains 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
/* Code testing out the DHT11 Temperature and Humidity sensor */ | |
#include "DHT.h" | |
#define DHTPIN 2 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup() { | |
Serial.begin(9600); | |
dht.begin(); | |
} | |
void loop() { | |
float h, t, hic; | |
delay(2000); | |
h = dht.readHumidity(); | |
t = dht.readTemperature(); | |
if (isnan(h) || isnan(t)) { | |
Serial.println("Error: Cannot connect to sensor."); | |
return; | |
} | |
hic = dht.computeHeatIndex(t, h, false); | |
Serial.print("Humidity: "); | |
Serial.print(h); | |
Serial.println("%"); | |
Serial.print("Temperature: "); | |
Serial.print(t); | |
Serial.println(" *C"); | |
Serial.print("Heat index: "); | |
Serial.print(hic); | |
Serial.println(" *C\n"); | |
} |
This file contains 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
/* Test out the moisture sensor */ | |
void setup () { | |
Serial.begin(9600); | |
Serial.flush(); | |
} | |
void loop () { | |
int val; | |
Serial.print(F("Moisture sensor value: ")); | |
val = analogRead(A0); | |
Serial.println(val); | |
if (val <= 300) { | |
Serial.println(F("Dry soil")); | |
} else if (val <= 700) { | |
Serial.println(F("Humid soil")); | |
} else if (val <= 950) { | |
Serial.println(F("In water...")); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment