Hello, Working on a code for my solarheating panel, but i cant get the LCD to work. The program is working but nothing i the LCD. Can someone help me with the code for the LCD?
I'm old, wearing reading glasses, and new on programming
Desperate for some help.
//Differential Temperature Controller
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
//----DS18B20 definitions (temperature sensors)
#define ONE_WIRE_BUS 2
//----LCD definitions
#define I2C_ADDR 0x3F //LCD device I2C address.
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
//other constants
#define pumpPin 3 //Named for clarity. Pump signal output at digital pin 3 (see setup)
#define ledPin 4
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
OneWire oneWire(ONE_WIRE_BUS); //Refer oneWire to Bus for DS18B20 sensor communication
DallasTemperature sensors(&oneWire);
//----variables
int tankLimit = 180; //set tank overtemp protection
int startDT = 10; //set differential temperature to start pump
int stopDT = 3; //set differential temperature to stop pump
void setup(void)
{
sensors.begin(); //start up the sensors
lcd.begin (16,2); //start up the LCD
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH); // Switch on the backlight
pinMode(pumpPin, OUTPUT); //set digital pin for pump to output type
pinMode(ledPin, OUTPUT);
digitalWrite(pumpPin, HIGH); //starts with pump off (HIGH = relay off)
lcd.setCursor(9,0); //go to pump status line
lcd.print("Pmp:Off"); //Initial until pump loop changes state
}
void loop(void)
{
sensors.requestTemperatures(); //get current values from sensors
float tankT = sensors.getTempFByIndex(0);
float collT = sensors.getTempFByIndex(1);
//display System Status on LCD. Pump status prints under pump control loop below.
lcd.home ();
lcd.print("Tank:");
lcd.print(round(tankT));
lcd.print("F "); //"F_" eliminates bug that would display "FF" sometimes.
lcd.setCursor(0,1);
lcd.print("Collector:");
lcd.print(round(collT));
lcd.print("F ");
//Pump control loop
/*This loop uses three scenarios to control the pump, always with a qualifier that tank limit temp is not exceeded.
* 1) dT higher than startDT (turn on pump)
* 2) dT between stopDT and start dT (keep pump in current state)
* 3) dT below stopDT (turn off pump)
*/
if ( ( (collT - startDT) > tankT ) && ( tankT < tankLimit ) ) //if the measured dT is bigger than startDT, turn on the pump
{
digitalWrite (pumpPin, LOW); //LOW signal turns relay on
digitalWrite (ledPin, HIGH);
lcd.setCursor(9,0); //go to pump status line on LCD
lcd.print("Pmp:On "); //extra space clears "f" from "off" state.
}
else
{
if ( ( (collT - stopDT) >= tankT) && (tankT < tankLimit) ) //if the dT is between stopDT and startDT, don't change anything
{
//do nothing (keep current pump state)
}
else
{
digitalWrite (pumpPin, HIGH); //turn the pump off (HIGH signal is off)
digitalWrite (ledPin, LOW);
lcd.setCursor(9,0); //go to pump status line on LCD
lcd.print("Pmp:Off");
}
}
delay(1000);
}