Hi i make this code to show the level at the display from two water tanks
the first one work great, but the second not show anything
this is my code
void setup() {
lcd.begin(16,2);
lcd.print(" AQUA LEVEL ");
lcd.createChar(0, symbol);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
delay(3000); // Show application name for 3 seconds.
}
It might
be useful
to set the
pin mode
for the other
set of
pins.
And stop with all the stupid blank lines in your code.
i make it like this and still not have anything blank guy
void setup() {
lcd.begin(16,2);
lcd.print(" AQUA LEVEL ");
lcd.createChar(0, symbol);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
pinMode(ECHO_PIN2, INPUT);
pinMode(TRIG_PIN2, OUTPUT);
delay(3000); // Show application name for 3 seconds.
}
you had a few errors ion there...
#include <LiquidCrystal.h>
#define ECHOPIN 3 // Pin to receive echo pulse
#define TRIGPIN 4 // Pin to send trigger pulse
#define ECHO_PIN2 2 // Pin to receive echo pulse2
#define TRIG_PIN2 5 // Pin to send trigger pulse2
#define STATUSPIN 13 // Use for troubleshooting
int highWater = 24; // These values allow to calculate % of full
int lowWater = 100; // SRF04 hangs above water (lower distance = more water)
byte symbol[8] = { // Custom character for LCD display
B00000,
B11111,
B11111,
B11111,
B11111,
B11111,
B00000,
};
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Assign pins
//
void flashLed(int pin, int times, int wait)
{
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
//
void setup()
{
lcd.begin(16,2);
lcd.print(" AQUA LEVEL ");
lcd.createChar(0, symbol);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
pinMode(ECHO_PIN2, INPUT);//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
pinMode(TRIG_PIN2, OUTPUT);//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
delay(3000); // Show application name for 3 seconds.
}
//
void loop()
{
digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW); // Send pin low again
int distance = pulseIn(ECHOPIN, HIGH); // Read in times pulse
distance= distance/65; // divide by 58 gives cm.
//
digitalWrite(TRIG_PIN2, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG_PIN2, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIG_PIN2, LOW); // Send pin low again
int distance2 = pulseIn(ECHO_PIN2, HIGH); // Read in times pulse
distance2= distance2/58; // divide by 58 gives cm.
int scaledValue = map(constrain(distance, highWater, lowWater), lowWater, highWater, 0, 11);
lcd.clear();
lcd.print("E | F 1");
lcd.setCursor(0,1);
while (scaledValue > 0)
{
lcd.print((char)0);
scaledValue--;
}
//delay(3000); // Wait 2 seconds before printing the 2nd value.//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//
int scaledValue2 = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 11); //<<<<<<<<note distance2
lcd.clear();
lcd.print("E | F 2");
lcd.setCursor(0,1);
while (scaledValue2 > 0) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
lcd.print((char)0);
scaledValue2--;//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
delay(3000); // Wait 2 seconds before measuring again. We're in no hurry!
}
sure there is something wrong but where ?!
for the first part, i think there is nothing wrong
#include <LiquidCrystal.h>
#define ECHOPIN 3 // Pin to receive echo pulse
#define TRIGPIN 4 // Pin to send trigger pulse
#define ECHO_PIN2 2 // Pin to receive echo pulse2
#define TRIG_PIN2 5 // Pin to send trigger pulse2
#define STATUSPIN 13 // Use for troubleshooting
int highWater = 24; // These values allow to calculate % of full
int lowWater = 100; // SRF04 hangs above water (lower distance = more water)
byte symbol[8] = { // Custom character for LCD display
B00000,
B11111,
B11111,
B11111,
B11111,
B11111,
B00000,
};
the second one i don't know where exactly
i corrected it tin the code I posted...
i test it, it shows the tank 2 only and not read anything !!
post your latest code, buddy
i change it to this and now the tank 2 shows full !! i not use it in the tank right now, so the sensor not detect anything
#include <LiquidCrystal.h>
#define ECHOPIN 3 // Pin to receive echo pulse
#define TRIGPIN 4 // Pin to send trigger pulse
#define ECHO_PIN2 5 // Pin to receive echo pulse2
#define TRIG_PIN2 6 // Pin to send trigger pulse2
#define STATUSPIN 13 // Use for troubleshooting
int highWater = 24; // These values allow to calculate % of full
int lowWater = 100; // SRF04 hangs above water (lower distance = more water)
byte symbol[8] = { // Custom character for LCD display
B00000,
B11111,
B11111,
B11111,
B11111,
B11111,
B00000,
};
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Assign pins
// Utility function for flashing STATUSPIN
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
void setup() {
lcd.begin(16,2);
lcd.print(" AQUA LEVEL ");
lcd.createChar(0, symbol);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
pinMode(ECHO_PIN2, INPUT);
pinMode(TRIG_PIN2, OUTPUT);
delay(3000); // Show application name for 3 seconds.
}
void loop() {
// Measure distance
digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW); // Send pin low again
int distance = pulseIn(ECHOPIN, HIGH); // Read in times pulse
distance= distance/65; // divide by 58 gives cm.
// Measure distance 2
digitalWrite(TRIG_PIN2, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG_PIN2, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIG_PIN2, LOW); // Send pin low again
int distance2 = pulseIn(ECHO_PIN2, HIGH); // Read in times pulse
distance2= distance2/58; // divide by 58 gives cm.
// Convert measured value1 to value between 0-11, to display on LCD
// Use Arduino built-in map and constrain functions
int scaledValue = map(constrain(distance, highWater, lowWater), lowWater, highWater, 0, 11);
lcd.clear();
lcd.print("E | F 1");
lcd.setCursor(0,1);
while (scaledValue > 0) {
lcd.print((char)0);
scaledValue--;
}
delay(3000); // Wait 2 seconds before printing the 2nd value.
// Convert measured value2 to value between 0-11, to display on LCD
// Use Arduino built-in map and constrain functions
int scaledValue2 = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 11); //<<<<<<<<note distance2
lcd.clear();
lcd.print("E | F 2");
lcd.setCursor(0,1);
while (scaledValue2 > 0) {
lcd.print((char)0);
scaledValue2--;
}
delay(3000); // Wait 2 seconds before measuring again. We're in no hurry!
}
distance= distance/65; // divide by 58 gives cm.
Which?
Code or comment?
Maybe put in some serial prints and lose some blank lines.
lol nic one i am not that good in coding so i make blank lines to be more easy for me =(
there is alot of errors in my code, i solve it all
but i have problem now i have two water tank, so i must see first level from the first ultrasonic sensor, then delay 3000 and shows the second level
the first sensor work fine, the second one not show anything,
i change the code and now the first sensor gives the level for the two tanks !!
what about the other one !!
i am trying this from 4 days, and i try everything i know,
look at me i am the captain now
#include <LiquidCrystal.h>
#define ECHOPIN 3 // Pin to receive echo pulse
#define TRIGPIN 4 // Pin to send trigger pulse
#define ECHO_PIN2 6 // Pin to receive echo pulse2
#define TRIG_PIN2 5 // Pin to send trigger pulse2
#define STATUSPIN 13 // Use for troubleshooting
int highWater = 24; // These values allow to calculate % of full
int lowWater = 100; // SRF04 hangs above water (lower distance = more water)
byte symbol[8] = { // Custom character for LCD display
B00000,
B11111,
B11111,
B11111,
B11111,
B11111,
B00000,
};
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Assign pins
// Utility function for flashing STATUSPIN
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
void setup() {
lcd.begin(16,2);
lcd.print(" AQUA LEVEL ");
lcd.createChar(0, symbol);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
pinMode(ECHO_PIN2, INPUT);
pinMode(TRIG_PIN2, OUTPUT);
delay(3000); // Show application name for 3 seconds.
}
void loop() {
// Measure distance
digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW); // Send pin low again
int distance = pulseIn(ECHOPIN, HIGH); // Read in times pulse
distance= distance/65; // divide by 58 gives cm.
// Measure distance 2
digitalWrite(TRIG_PIN2, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG_PIN2, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIG_PIN2, LOW); // Send pin low again
int distance2 = pulseIn(ECHO_PIN2, HIGH); // Read in times pulse
distance2= distance2/58; // divide by 58 gives cm.
// Convert measured value1 to value between 0-11, to display on LCD
// Use Arduino built-in map and constrain functions
int scaledValue = map(constrain(distance, highWater, lowWater), lowWater, highWater, 0, 11);
lcd.clear();
lcd.print("E | F 1");
lcd.setCursor(0,1);
while (scaledValue > 0) {
lcd.print((char)0);
scaledValue--;
}
delay(3000); // Wait 2 seconds before printing the 2nd value.
// Convert measured value2 to value between 0-11, to display on LCD
// Use Arduino built-in map and constrain functions
int scaledValue2 = map(constrain(distance, highWater, lowWater), lowWater, highWater, 0, 11);
lcd.clear();
lcd.print("E | F 2");
lcd.setCursor(0,1);
while (scaledValue2 > 0) {
lcd.print((char)0);
scaledValue2--;
}
delay(3000); // Wait 2 seconds before measuring again. We're in no hurry!
}
int scaledValue2 = map(constrain(distance, highWater, lowWater), lowWater, highWater, 0, 11);
Should that be distance2
?
~~ ~~int scaledValue2 = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 11);~~ ~~
i try that two, and not show anything ! from the second ultrasonic sensor
oh wow i was try that and not work !!! why it works now i dont know
thanks alooooooooooooot <3