Hello all.
I am using a Grove starter kit plus. I have a temp sensor and the RGB Backlight display which is showing the room temp. That is working fine and I can see what the room temp is. I wanted to light an LED when the temp goes below 70 degrees. Later I want to hookup a relay to turn my boiler on and off based on room temp.
I am not able to make it work. I am pasting my code below. Am i missing something (which i am sure i am).? I left in my commented out code of what i tried before i tried the if statement.
Any help would be appreciated.
Thanks
Eddie
#include <Wire.h> //LDC libraries
#include "rgb_lcd.h"
rgb_lcd lcd; //Declare the LCD
const int pinTemp = A0; // pin of temperature sensor
const int pinLed = 3; // pin of led define here
//Set the color of LCD to red
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
float temperature;
int B=3975; // B value of the thermistor
float resistance;
void setup()
{
pinMode(pinLed, OUTPUT); // set led OUTPUT
Serial.begin(9600); //set to read output on serial monitor
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.print("Room Temperature:");
delay(1000);
}
void loop()
{
int val = analogRead(pinTemp); // get analog value
resistance=(float)(1023-val)*10000/val; // get resistance
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; // calc temperature
temperature = (temperature * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Serial.println(temperature);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(temperature);
if (temperature < 70)
{
digitalWrite (pinLed = HIGH);
}
else (temperature > 70)
{
digitalWrite (pinLed = LOW);
}
/*
{
for(int i=HIGH; temerature<70; i++)
{
analogWrite(pinLed, i);
delay(5);
}
delay(100);
for(int i=LOW; temerature>70; i--)
{
analogWrite(pinLed, i);
delay(100);
}
}
*/
delay(1000); // delay 1s