I am trying to get the percentage humidity from a soil sensor, but I get 0 every time I try to convert the number from the output to a percentage. What am I doing wrong?
This is what I have right now and I get 0:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
void setup() {
lcd.begin(16, 2);
}
void loop() {
lcd.setCursor(1,0);
lcd.print("Soil Moisture");
lcd.setCursor(3,1);
lcd.print("LEVEL:"); //analog input
lcd.print(int(analogRead(A1)/1024*100));
delay(3000); //change delay to change refresh rate
lcd.setCursor(3,1);
lcd.clear();
}
If I change this line: lcd.print(int(analogRead(A1)/1024*100)); to this: lcd.print(analogRead(A1)); I get proper numbers between 0 and 1023. I have tried with and without the int() function.