Hi
My project is to create a Water level for two tanks. For now, I’m making the test with
one sensor and the second sensor is not part of my problem.
One bug at the time so lets look at my problem for one water tank.
I’m using ultrasonic sensor (Waterproof sensor JSN SR04T) Work nice.
I want one LCD 16X2 oriented vertical that will represent the water level in the tank with a
progress bar.
A second LCD but a 16X4, that will be use to tell me the mesured lengh by the sensor,
the percent of water in the tank and later the gallons per minute during the filling.
Problem One
I found a code for the progress Bar and it work well BUT the last square is my probleme.
While the mesured distance is changing slowly I can see a square then the number 3 appear
and decrease for 2, 1, 0 and then nothing. then it is the next square that change for 3, 2, 1, 0 etc…
See the picture attached.
It’s probably because there is 4 column in each square and those number 3 to 0 represent each column
and instead of removing one column at the time, the numbers are visible. I have two choices, making the number invisible until a full square disapear for the next, or find a way to make the column disapear one at the time until a full square is done.
Problem Two
I need to set a lower and a higher limit for the percent.
The day I will install that into my tank I want to be able to set the lower limit to 170cm and the top limit to 30cm. So 30cm will be 100% and 170 cm will be 0% of course the progress bar need to follow the percent value.
Any suggestion ?
Thanks
#include "Ultrasonic_1.h"
#include "Ultrasonic.h"
#include "Wire.h"
#include "LCD.h"
#include "LiquidCrystal_I2C.h"
Ultrasonic ultrasonic(2,3);
Ultrasonic_1 ultrasonic_1(4,5);
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
LiquidCrystal_I2C lcd_1(0x26,2,1,0,4,5,6,7);
#define lenght 16.0
double percent=100.0;
unsigned char b;
unsigned int peace;
byte p1[8] = {
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10};
byte p2[8] = {
0x18,
0x18,
0x18,
0x18,
0x18,
0x18,
0x18,
0x18};
byte p3[8] = {
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C};
byte p4[8] = {
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E};
byte p5[8] = {
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F};
void setup() {
Serial.begin(9600),
lcd.begin (16, 2); // 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE);
lcd_1.begin (16,4); // 16 x 4 LCD module
lcd_1.setBacklightPin(3,POSITIVE);
lcd_1.setBacklight(HIGH);
lcd.createChar(0, p1);
lcd.createChar(1, p2);
lcd.createChar(2, p3);
lcd.createChar(3, p4);
lcd.createChar(4, p5);
lcd.begin(16, 2);
}
void Sensor_0(){
lcd.setCursor(0, 0);
unsigned int value = ultrasonic.Ranging(CM);
percent = value*100.0/200.0;
lcd_1.setCursor(0, 0);
lcd_1.print(value);
lcd_1.print(" - ");
lcd_1.print(percent);
lcd_1.print(" % ");
double a=lenght/100*percent;
if (a>=1) {
for (int i=1;i<a;i++) {
lcd.write(4);
b=i;
}
a=a-b;
}
peace=a*5;
switch (peace) {
case 0:
break;
case 1:
lcd.print(0);
break;
case 2:
lcd.print(1);
break;
case 3:
lcd.print(2);
break;
case 4:
lcd.print(3);
break;
}
//clearing line
for (int i =0;i<(lenght-b);i++) {
lcd.print(" ");
}
;
Serial.print("Sensor_0: ");
Serial.println(ultrasonic.Ranging(CM));
}
void Sensor_1(){
lcd.setCursor(0, 1);
lcd.print(ultrasonic_1.Ranging(CM));
lcd.setCursor(4, 1);
lcd.print("cm");
Serial.print("Sensor_1: ");
Serial.println(ultrasonic_1.Ranging(CM));
Serial.println(" ");
}
void loop(){
Sensor_0();
//Sensor_1();
delay(500);
}