I dont seem to understand this
Trying to print to lcd in percentage's instead of 0 to 1023
My range is 200 to 1000
This is what I have but does not seem to work
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Second Potentiometer connection with Arduino
* Potentiometer 5v to Arduino 5v
* Potentiometer GND to Arduino GND
* Potentiometer Wiper/Vout to Arduino A0(Analog pin 0)
*/
// include the library code:
#include <LiquidCrystal.h>
int sensorValue = 0;
float value;
float percentage;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(A0, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
percentage =100-(value-0) /( 1023.0-0) * 100;
lcd.println(percentage);
delay(700);
// set the cursor to column 0, line 0:
lcd.setCursor(0, 0);
// print out the value at LCD Display:
lcd.print("level ");
lcd.print(percentage);
// print out the value at Serial Monitor:
Serial.println(sensorValue);
delay(1000);
lcd.clear();
}
This line doesn't make any sense to me. I don't see value getting set anywhere. Also, when you say the range is 200 to 1000 do you mean that you should only see analog values between 200 and 1000 or you need to convert the range 0 to 1023 to the range 200 to 1000?
I have to characters after.00 is that from my sketch
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Second Potentiometer connection with Arduino
* Potentiometer 5v to Arduino 5v
* Potentiometer GND to Arduino GND
* Potentiometer Wiper/Vout to Arduino A0(Analog pin 0)
*/
// include the library code:
#include <LiquidCrystal.h>
int sensorValue = 0;
float value;
float percentage;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(A0, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
percentage = map(sensorValue, 200, 1023, 0, 100);
lcd.println(percentage);
delay(500);
// set the cursor to column 0, line 0:
lcd.setCursor(0, 0);
// print out the value at LCD Display:
lcd.print("level ");
lcd.print(percentage);
// print out the value at Serial Monitor:
Serial.println(sensorValue);
delay(50);
lcd.clear();
}
Thanks but it reads from 0 to 24 and still have those strange charaters
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Second Potentiometer connection with Arduino
* Potentiometer 5v to Arduino 5v
* Potentiometer GND to Arduino GND
* Potentiometer Wiper/Vout to Arduino A0(Analog pin 0)
*/
// include the library code:
#include <LiquidCrystal.h>
byte sensorValue = 0;
byte percentage;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(A0, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
percentage = map(sensorValue, 0, 1023, 0, 100);
lcd.println(percentage);
delay(500);
// set the cursor to column 0, line 0:
lcd.setCursor(0, 0);
// print out the value at LCD Display:
lcd.print(percentage);
// print out the value at Serial Monitor:
Serial.println(sensorValue);
delay(50);
lcd.clear();
}
Thanks guys. The funny characters are gone from the end of the line but as I turn the potentiometer it goes from 0 to 24 (first half) then starts a 0 again to 24(for the second half)
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Second Potentiometer connection with Arduino
* Potentiometer 5v to Arduino 5v
* Potentiometer GND to Arduino GND
* Potentiometer Wiper/Vout to Arduino A0(Analog pin 0)
*/
// include the library code:
#include <LiquidCrystal.h>
byte sensorValue = 0;
byte percentage;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(A0, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
const int min = 0, max = 1023;
const float span = max - min, hundred = 100.0;
percentage = hundred * (sensorValue - min) / span;
lcd.print(percentage);
delay(500);
// set the cursor to column 0, line 0:
lcd.setCursor(0, 0);
// print out the value at LCD Display:
lcd.print(percentage);
// print out the value at Serial Monitor:
Serial.println(sensorValue);
delay(50);
lcd.clear();
}
Thats a no go jca34f the display only displays "inf"
If i turn the pot off it displays "nan"
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Second Potentiometer connection with Arduino
* Potentiometer 5v to Arduino 5v
* Potentiometer GND to Arduino GND
* Potentiometer Wiper/Vout to Arduino A0(Analog pin 0)
*/
// include the library code:
#include <LiquidCrystal.h>
float sensorValue = 0;
float percentage;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(A0, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
const int min = 0, max = 1023;
const float span = max - max, hundred = 100.0;
percentage = hundred * (sensorValue - min) / span;
lcd.print(percentage);
delay(500);
// set the cursor to column 0, line 0:
lcd.setCursor(0, 0);
// print out the value at LCD Display:
lcd.print(percentage);
// print out the value at Serial Monitor:
Serial.print(sensorValue);
delay(50);
lcd.clear();
}
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Second Potentiometer connection with Arduino
* Potentiometer 5v to Arduino 5v
* Potentiometer GND to Arduino GND
* Potentiometer Wiper/Vout to Arduino A0(Analog pin 0)
*/
// include the library code:
#include <LiquidCrystal.h>
float sensorValue = 0;
float percentage;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(A0, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
lcd.print("Tank Level:");
}
void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
const int min = 0, max = 1023;
const float span = max - min, hundred = 100.0;
percentage = hundred * (sensorValue - min) / span;
lcd.setCursor(0, 0);
lcd.print("Tank Level:");
lcd.setCursor(4,1);
lcd.print(percentage);
lcd.print("%");
delay(2000);
// print out the value at Serial Monitor:
Serial.print(sensorValue);
delay(50);
lcd.clear();
}