I'm trying, unsuccessfully, to create a programe that simulates a basic temperature control/monitoring and displays on an LCD. I am using a yellow LED to simulate an alarm, a blue LED to simulate a fan that will come on above 26C and a red LED to simulate a heater that will come on at 16C.
My programe will run ok, my issues are that my LED's do not activate when there is a change in temp and also my LCD does not display anything.
Being extremely new to this ive no doubt it will be something very obvious but i've no idea what.
Below is a copy of my progame. Any help will be greatly appreciated.
//include the library code:
#include <LiquidCrystal.h>
//initialize the libaray with te numbers of the interface pins:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//set up sensor pin to pin 0:
int anologPin = A1;
//create tempreture variable
int led_red = 13; // the red LED is connected to Pin 13 of the Arduino
int led_blue = 7; // the blue LED is connected to Pin 7 of the Arduino
int led_yellow = 8; // the yellow LED is connected to Pin 8 of the Arduino
// define variable
float tempC;
//Set up LED's as outputs:
void setup() {
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(13, OUTPUT);
//Set up LCD's number of columns and rows:
lcd.begin(16, 2);
//Print a message to the LCD
lcd.print("hello,world!");
}
void loop() {
tempC = get_temperature(anologPin);
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.setCursor(0,1);
lcd.print (tempC, 1); lcd.print(" "); lcd.print("C");
delay(200);
if (tempC < 16){
digitalWrite(led_red, HIGH);
digitalWrite(led_blue, LOW);
digitalWrite(led_yellow, HIGH);
delay(2000); // wait 2 seconds
}
else if (tempC > 26){
digitalWrite(led_red, LOW);
digitalWrite(led_blue, HIGH);
digitalWrite(led_yellow, HIGH);
delay(2000); // wait 2 seconds
}
else {
digitalWrite(led_red, LOW);
digitalWrite(led_blue, LOW);
digitalWrite(led_yellow, LOW);
}
}
float get_temperature(int pin) {
float temperature = analogRead(pin);
float voltage = temperature * 3.3;
voltage = voltage / 1024.0;
return ((voltage - 0.5) * 100);
}