Hi
I am trying to use a Ardouino Nano 3.0, a two line LCD display (using the I2C board) and a soil humidity sensor. The problem is that the display only highlights all the pixels in the first line.. no "text" is displayed.. Could anyone please take a look at my code?
#include <LiquidCrystal_I2C.h>
#include <LCD.h>
#include <Wire.h>
int i;
int soilsensor = A0; //Soil sensor
int sensorValue = 0;
#define ONE_WIRE_BUS 7
#define I2C_ADDR 0x27
#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
#define ledred 2
#define ledgreen 3
#define ledblue 4
#define powerPin 7
//LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
Serial.begin(9600);
pinMode(ledred, OUTPUT);
pinMode(ledgreen, OUTPUT);
pinMode(ledblue, OUTPUT);
pinMode(powerPin, OUTPUT);
lcd.begin(16, 2);
for(int i = 0; i< 3; i++){
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Humidity");
delay(1000);
Wire.begin();
//lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
//lcd.setBacklight(HIGH);
//lcd.home ();
}
void loop() {
digitalWrite(ledred, HIGH);
digitalWrite(ledblue, HIGH);
digitalWrite(powerPin, HIGH);
delay(30);
int soil = analogRead(powerPin);
soil = constrain(soil, 400, 1000); // We get the values between 400 and 1000, thats why we need to map the values
soil = map(soil, 400, 1000, 100, 0); // to make lower numbers a bigger percent, and to map them im range of 1 to 100.
lcd.setCursor(12, 0); // Set Curson to line 0, column 12
lcd.print(soil); // display final percentage
lcd.print("%"); // print the percent symbol at the end
}
