Hi guys.
I managed to make my own simple program without asking questions but… i get to the stage where i cannot figure out how write this program to display PSI pressure withou xxx.00
Simply saying i only want my display to show->0 1 2 3 instead 0.008 or 1.28 or 4.99 psi.
i have a sensor that is designED for 150psi. 0.5v=0psi 4,5v=150psi.
overaul reason is that i need to display 5 sensors on 16x2 display.
Code below
/*
5 ANALOG PRESSURE SENSORS
*/
// include the library code: #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int sensorValue = 1;
int sensorValue2 = 2;
int val = 0;
void setup() {
Serial.begin(9600);
// LCD type
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(4, 0);
lcd.print(“PRESSURE”);
lcd.setCursor(5, 1);
lcd.print(“SENSOR”);
delay(5000);
lcd.clear();
lcd.print(“P1 P2 P5”);
lcd.setCursor(0, 1);
lcd.print("P3 P4 | ");
}
void loop() {
int raw;
float voltage;
float pressure; //pressure in psi
// read the input pin
raw = analogRead(A1);
// Calculate the input voltage
// Using the full input range of 5V.
voltage = (float) raw / 1023.0 * 5.0;
// The pressure is with a linear scale.
// 0.5 V = 0 psi
// 4.5 V = 150 psi
// That is 37.5 psi per voltage.
// At 0.5V the pressure is 0 psi
pressure = 0 + (voltage * 37.5);
lcd.setCursor(2,0);
lcd.print(pressure);
}
ok, i`ve read your suggestions and… so far my readout stuck on “1” on p1 and “0” on p3 no matter which way i turn the post (simulating sensor) those values wont change.
i guess i do something wrong
/*
5 ANALOG PRESSURE SENSORS
*/
// include the library code: #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int sensorValue = 1;
int sensorValue2 = 2;
int val = 0;
void setup() {
Serial.begin(9600);
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(4, 0);
lcd.print(“PRESSURE”);
lcd.setCursor(5, 1);
lcd.print(“SENSOR”);
delay(500);
lcd.clear();
lcd.print(“P1 P2 P5”);
lcd.setCursor(0, 1);
lcd.print("P3 P4 | ");
}
void loop() {
int raw;
float voltage;
float pressure; //pressure in psi
// read the input pin
raw = analogRead(A1);
// Calculate the input voltage
// Using the full input range of 5V.
voltage = (float) raw / 1023.0 * 5.0;
// The pressure is with a linear scale.
// 0.5 V = 0 psi
// 4.5 V = 150 psi
// That is 37.5 psi per voltage.
// At 0.5V the pressure is 0 psi
pressure = 0 + (voltage * 37.5);
lcd.setCursor(2,0);
lcd.print(0.123456,0);
delay(500);
raw = analogRead(A2);
voltage = (float) raw / 1023* 5.0;
pressure = 0+ (voltage * 37.5);
lcd.setCursor(2,1);
lcd.print(0.123456,0) ;
}
pressure = (((float)analogRead(A0) / 1023.0 * 5.0) - 0.5) * 37.5;
lcd.setCursor(2,0);
lcd.print(pressure+0.5, 0); // Print pressure rounded up to the next full PSI with no decimal places
// OR
lcd.print((int)(pressure+0.5)); // Print pressure rounded up to the next full PSI as an integer
does work, indeed, but values below 100psi are displayed with xx0 which gives false readoud. i know that this is lets say 40psi but display show 400... once its 990 count stars from 100 and ends on 188
AWOL:
So print a couple of spaces after every value, or get clever with some simple comparisons.
Please remember to use code tags when posting code.
Do you mean i should use “<-10”,">-10",">0",">=10" formulas??
Can you please post some example… not necessary related to the post.
Sorry for lack of technical language.
Hi.
So i`ve figured out how to print without unnecessary characters.
Can you please give me some advice on how to choose where particular range is displayed.
E.G.
0-9 column 3
10-99 column 3-4
100-150 column 2-3-4
Code:
//Sensor #1
raw = analogRead(A1);
voltage = (float) raw / 1023.0 * 5.0;
pressure = (((float)analogRead(A1) / 1023.0 * 5.0) - 0.5) * 37.5;
if (pressure>-100)
{
lcd.setCursor(4,0);
lcd.write(254);
lcd.setCursor(2,0);
lcd.print(pressure,0);
}
if (pressure<-100)
{
lcd.setCursor(4,0);
lcd.write(254);
lcd.setCursor(3,0);
lcd.print(pressure,0);
}
if (pressure <-10);
{
lcd.setCursor(3,0);
lcd.write(254);
lcd.setCursor(2,0);
lcd.print(pressure,0);
}
if (pressure <0);
{
lcd.setCursor(4,0);
lcd.write(254);
lcd.setCursor(2,0);
lcd.print(pressure,0);
}
mOskit:
Hi.
So i`ve figured out how to print without unnecessary characters.
Can you please give me some advice on how to choose where particular range is displayed.
E.G.
0-9 column 3
10-99 column 3-4
100-150 column 2-3-4
Code:
//Sensor #1
raw = analogRead(A1);
voltage = (float) raw / 1023.0 * 5.0;
pressure = (((float)analogRead(A1) / 1023.0 * 5.0) - 0.5) * 37.5;
if (pressure>-100)
{
lcd.setCursor(4,0);
lcd.write(254);
lcd.setCursor(2,0);
lcd.print(pressure,0);
}
if (pressure<-100)
{
lcd.setCursor(4,0);
lcd.write(254);
lcd.setCursor(3,0);
lcd.print(pressure,0);
}
if (pressure <-10);
{
lcd.setCursor(3,0);
lcd.write(254);
lcd.setCursor(2,0);
lcd.print(pressure,0);
}
if (pressure <0);
{
lcd.setCursor(4,0);
lcd.write(254);
lcd.setCursor(2,0);
lcd.print(pressure,0);
}