Hey guys, I have a sketch that I put together here to control my humidifier with Arduino, a Powerswitch Tail 2 (powerswitch tail 2 is a relay), and a DHT11 which is a temperature and humidity sensor. The output of the sensor will display on a 16*2 LCD.
I'm not a programming expert so I wanted to post my code here and get some feedback. The code compiles and everything but if anybody can take the time to look at the code and tell me if the last VOID PART is good enough for my powerswitch to turn on /off my humidifier that would be great. I don't have my powerswitch yet otherwise I would test it out myself but in the meantime I thought I would consult anybody here that's good with programming.
Anyways, guys read my code and let me know what you think.
#include "DHT.h"
#include <LiquidCrystal.h>
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float tempF = 0.0;
int poweroutlet = 13;
void setup() {
pinMode(poweroutlet, OUTPUT);
digitalWrite(poweroutlet, LOW);
Serial.begin(9600);
lcd.begin(16, 2);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
tempF = ((t) * 9/5)+32;
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
}
else {
lcd.setCursor(0,0);
lcd.print("Temp=");
lcd.print(tempF);
lcd.print(" F");
lcd.setCursor(0,1);
lcd.print("Humid=");
lcd.print(h);
lcd.print("% ");
delay(500);
}
}
void powerSwitch(float data) {
float h = dht.readHumidity ();
if (h < 31) {
digitalWrite(poweroutlet, HIGH);
}
else if (h > 50) {
digitalWrite(poweroutlet, LOW);
}
else (37<h>44); {
digitalWrite(poweroutlet, LOW);
}
}