// Connections:
// LCD pin 1 to Arduino GND
// LCD pin 2 to Arduino 5v
// LCD pin 3 (Contrast) to GND
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pin 16 to Arduino GND
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
//Tested with SHT21 Breakout from Misenso
//SHT21 pin SDA to Arduino Analog pin 4
//SHT21 pin SCL to Arduino Analog pin 5
//SHT21 pin GND to Arduino GND
//SHT21 pin VCC to Arduino 3v (not 5v)
//RGB LED
//Red Cathode to Arduino pin 9
//Blue Cathode to Arduino pin 8
//Green Cathode to Arduino pin 7
//Anode to 270 ohm resistor to 5V
#include <LiquidCrystal.h>
#include <Wire.h>
#include <LibHumidity.h>
LibHumidity humidity = LibHumidity(0);
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight
int RedLEDPin = 9; // LED connected to digital pin 9
int BlueLEDPin = 8; // LED connected to digital pin 8
int GreenLEDPin = 7; // LED connected to digital pin 7
void setup()
{
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
//I2C
pinMode(16, OUTPUT);
digitalWrite(16, LOW); //GND pin
pinMode(17, OUTPUT);
digitalWrite(17, HIGH); //VCC pin
//Furnace / AC Indicator
pinMode(RedLEDPin, OUTPUT); // sets the digital pin as output
pinMode(BlueLEDPin, OUTPUT); // sets the digital pin as output
pinMode(GreenLEDPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
lcd.begin(20,4); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Humidity: "); // change this text to whatever you like. keep it clean.
lcd.print(humidity.GetHumidity());
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print("Temp in C: ");
lcd.print(humidity.GetTemperatureC());
lcd.setCursor(0,2); // set cursor to column 0, row 2
lcd.print("Temp in F: ");
lcd.print(humidity.GetTemperatureF());
{
if (humidity.GetTemperatureF() < 60)
{
digitalWrite(RedLEDPin, LOW); // sets the Red LED on
digitalWrite(BlueLEDPin, HIGH); // sets the Blue LED off
digitalWrite(GreenLEDPin, LOW); // sets the Green LED off
}
else if (humidity.GetTemperatureF() >= 75)
{
digitalWrite(BlueLEDPin, LOW); // sets the Blue LED on
digitalWrite(RedLEDPin, HIGH); // sets the Red LED off
digitalWrite(GreenLEDPin, HIGH); // sets the Green LED off
}
else
{
digitalWrite(GreenLEDPin, LOW); // sets the Green LED on
digitalWrite(BlueLEDPin, HIGH); // sets the Blue LED off
digitalWrite(RedLEDPin, HIGH); // sets the Red LED off
}
}
delay (20000);
}
0 comments:
Post a Comment