Hi, I'm working on a project that automatically waters a plant. In the loop function of my sketch the lcd replaces my normal text with odd special characters. However the text in setup is normal. I believe to have narrowed it down to the program because the "hello world" example works just fine.
Here is my sketch:
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <LiquidCrystal.h>
const byte d7=1;
const byte d6=2;
const byte d5=3;
const byte d4=4;
const byte en=5;
const byte rs=6;
const byte pump=7;
const byte soilMoisture=A0;
const byte waterLevel=A1;
const byte button=A2;
const int pumpTime=4000;
//const unsigned long timeGap=900000;
const unsigned long timeGap=10000;
unsigned long previousTime=0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte miniTwo[8] = {
B00000,
B00000,
B01110,
B00010,
B01110,
B01000,
B01110,
};
byte timer[8] = {
B01110,
B00100,
B01110,
B10101,
B10111,
B10001,
B01110,
};
byte moon[8] = {
B00000,
B01110,
B11101,
B11000,
B11101,
B01110,
B00000,
};
void setup() {
pinMode(button, INPUT);
pinMode(pump, OUTPUT);
pinMode(waterLevel, INPUT);
pinMode(soilMoisture, INPUT);
lcd.createChar(0, miniTwo);
lcd.createChar(1, timer);
lcd.createChar(2, moon);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("H");
lcd.write(byte(0));
lcd.print("O: ");
lcd.setCursor(8,0);
lcd.write(byte(1));
lcd.print(": ");
lcd.setCursor(0,1);
lcd.print("Stan:");
Serial.begin(9600);
}
tmElements_t tm;
void loop() {
unsigned long currentTime=millis();
//obsługa automatyczna
if(currentTime-previousTime>=timeGap && analogRead(waterLevel)>500 && analogRead(soilMoisture)>429 && RTC.read(tm) && 21>=tm.Hour && tm.Hour>=9){
digitalWrite(pump, HIGH);
delay(pumpTime);
digitalWrite(pump, LOW);
previousTime=currentTime;
}
//obsługa guzika
if(analogRead(button)>1020 && analogRead(waterLevel)>500 && analogRead(soilMoisture)>429 && RTC.read(tm) && 21>tm.Hour && tm.Hour>9){
digitalWrite(pump, HIGH);
delay(pumpTime);
digitalWrite(pump, LOW);
}
//the problem
lcd.setCursor(5,0);
lcd.print(analogRead(soilMoisture));
}
Any help would be grealty appreciated. Thanks!