I´m new to the arduino world and trying make my first actual project.
I´m reading voltage 0-5 from pot at A0 and would like to display it on my 16x2 lcd screen
I have search the web for many hours looking for someone who has 4 pin lcd to display data
Could someone help me to combine these two codes that I found and attached so it would work?
The codes are both working separately.
Best regards from Iceland
GeckoDiode:
But if the code works then the combined code should work too. Will just have to wait for @ladan to try it out.
Yep. Your line in the code was right, only the description was wrong.
Once he gets this working though, he should really switch to 'millis()'-based timing for updates, rather than using delay, and maybe a slightly longer period than 10mS, to reduce LCD flicker. When I can get away with it, I like to update only once per second, but that's not always practical, if you want to catch faster changing values.
The LCD is some no name aliexpress version that does not any information printed on, so I ran
l2C scanner to find the address and tried a few codes before I found this one that I changed to 16.2
The LCD is some no name aliexpress version that does not any information printed on, so I ran
l2C scanner to find the address and tried a few codes before I found this one that I changed to 16.2
I will be using this meter for fuel display in my car. A0 will be the variable resistor in my fuel tank and I will properly use this circuit that I found to convert the 0-90 ohm signal to voltage input.
If that will work I would need to display non linear signal to the lcd because the area of the tank varies so much. Here is a pic with table to help understanding
The table is just example I have not measured the resistance every 10 liters yet
Thanks for the sites have been looking at them today.
But that is one thing that I have not been able to find out
How to a write code saying
Example
If analogRead is smaller than 249 then lcd.print("low")
If else analogRead is between 250 and 375 then lcd.print("medium")
If else analogRead is between 376 and 500 then lcd.print("high")
ladan:
But that is one thing that I have not been able to find out
How to a write code saying
Example
If analogRead is smaller than 249 then lcd.print("low")
If else analogRead is between 250 and 375 then lcd.print("medium")
If else analogRead is between 376 and 500 then lcd.print("high")
If it's done exactly as you say above, nothing will be printed if the value is 249, and nothing will happen if the value is larger than 500. That's also assuming that your second and third conditions are inclusive. ie Include 250 and 375 then 376 and 500.
Is that what you really want?
Allowing for your first condition really being <250, the code would look like this:-
int sensorVal = analogRead(A0);
if (sensorVal < 250)
lcd.print(F("low"));
else if (sensorVal > 249 and sensorVal < 376)
lcd.print(F("medium"));
else if (sensorVal > 375 and sensorVal < 501)
lcd.print(F("high"));
but nothing will be printed if the value is over 500.
Doesn't make sense to me why you don't want a fuel level indication if the value is larger than 500.
Yes I know it will not include the number without using >= and <= this was just an example. The code will go on to 1023 with some random steps (that I will get from the fuel tank sensor)
Now the only problem I´m having is to erase previous data from the screen
Example:
I load the software ok
"low" appears
turn the pot
"medium" appears
turn the pot backwards
"lowium" appears
Yes I know it will not include the number without using >= and <= this was just an example. The code will go on to 1023 with some random steps (that I will get from the fuel tank sensor)
Now the only problem I´m having is to erase previous data from the screen
Example:
I load the software ok
"low" appears
turn the pot
"medium" appears
turn the pot backwards
"lowium" appears
Oh, I sort of like "lowium". (Between low and medium. )
All you need to do is clear the LCD between writes to it:-
lcd.clear();
Just do it immediately before each 'lcd.print()' statement.
Edit: Even better, do it immediately after the 'analogRead()', and before the 'if...else' statements. Then it only needs to be typed once.
At the moment, though, until you write code that covers values above 500, you might have to do it the first way, or the LCD display will be blank when values exceed 500.
Oh, I sort of like "lowium". (Between low and medium. )
Hahaha thats right
When I saw your replay I had gone another way with using the same amount of letter for each step. But will definitely have to use it later.
I have now added the more steps to the code and put amount of liters for each step and It´s working great.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // Define I2C Address where the PCF8574A is
#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
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
lcd.begin (16,2);
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.print("Bensinbirgdir:");
}
void loop()
{
lcd.home (); // go home
// Read sensor value
int sensorVal = analogRead (A0);
// Display voltage
lcd.setCursor (0, 1);
float voltage = sensorVal ;
if (sensorVal <= 200)
lcd.print("005");
else if (sensorVal > 201 and sensorVal <= 240)
lcd.print("010");
else if (sensorVal > 241 and sensorVal <= 280)
lcd.print("015");
else if (sensorVal > 281 and sensorVal <= 320)
lcd.print("020");
else if (sensorVal > 321 and sensorVal <= 360)
lcd.print("025");
else if (sensorVal > 361 and sensorVal <= 400)
lcd.print("030");
else if (sensorVal > 401 and sensorVal <= 440)
lcd.print("035");
else if (sensorVal > 441 and sensorVal <= 480)
lcd.print("040");
else if (sensorVal > 481 and sensorVal <= 520)
lcd.print("045");
else if (sensorVal > 521 and sensorVal <= 560)
lcd.print("050");
else if (sensorVal > 561 and sensorVal <= 600)
lcd.print("055");
else if (sensorVal > 601 and sensorVal <= 640)
lcd.print("060");
else if (sensorVal > 641 and sensorVal <= 680)
lcd.print("065");
else if (sensorVal > 681 and sensorVal <= 720)
lcd.print("070");
else if (sensorVal > 721 and sensorVal <= 760)
lcd.print("075");
else if (sensorVal > 761 and sensorVal <= 800)
lcd.print("080");
else if (sensorVal > 801 and sensorVal <= 840)
lcd.print("085");
else if (sensorVal > 841 and sensorVal <= 880)
lcd.print("090");
else if (sensorVal > 881 and sensorVal <= 920)
lcd.print("095");
else if (sensorVal > 921 and sensorVal <= 960)
lcd.print("100");
else if (sensorVal > 961)
lcd.print("105");
delay (100);
}
Now my next mission will be to make the circuit for the sensor and measure resistance for every 5 liters I put on it.
When thats done I will have to update all the break points in my code and maybe add something to stabilise the data because acceleration and bumpy roads
Should I use smooting for that or something else?
ladan:
When thats done I will have to update all the break points in my code and maybe add something to stabilise the data because acceleration and bumpy roads
Should I use smooting for that or something else?
I'd personally do it in software. Just take readings at regular intervals over a given period, then average them and display the result. You'd probably need to experiment with the length of the time, and interval between individual readings, but once you get that right it should work fine.