Water level indicat...
 
Notifications
Clear all

Water level indicator

81 Posts
12 Users
11 Likes
11.5 K Views
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  
Posted by: @robotbuilder
Posted by: @tooter

Hi all I feel I have made a lot of progress today I've taken some code written for a wireless water meter and adjusted it to compile for the uno. I felt i would be beneficial to re write the code as opposed to copy and paste it I found it to be a beneficial learning curve there was a few hiccups along the way but managed to get it working quite well through the serial output. 

Great work.  Being able to figure it out for yourself comes with great personal satisfaction.

I noticed you use a header file called Blynk.h that I am unfamiliar with.

Checking the internet I read that Blynk allows arduino to communicate over the internet?

 

Thanks yer for some reason i cant explain the sonar wouldn't out put the measurements to serial if i didn't add the blynk library. I'm now trying to figure out how to make the screens back light to come on for 5 sec when a button is pressed. I've tried using the delay function but it resulted in random flashing from the back light. Looking for a different approach now.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

@tooter

Ok. I don't think you need the blynk library. Where are you getting this code and what is your actual hardware wiring? Perhaps tomorrow I can hook up a couple of sonar modules and the LCD module shown below plus code for you to try out. I notice that a I2C Port Expander Module can be used with the LCD but I would have to order one of those.

LCD1602A

 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  
Posted by: @robotbuilder

@tooter

Ok. I don't think you need the blynk library. Where are you getting this code and what is your actual hardware wiring? Perhaps tomorrow I can hook up a couple of sonar modules and the LCD module shown below plus code for you to try out. I notice that a I2C Port Expander Module can be used with the LCD but I would have to order one of those.

LCD1602A

 

Hi thanks that would be good. I think the blynk library is used for the timer. If I comment out the blynk library

I get no output from the serial un-comment it and bingo works again.

The sketch i used was from instrucables and was made for the esp 8266 (nodemcu) hence the blynk library.

I will try and find time to draw a diagram for you to see my wiring.

I have also been working on a sketch to incorporate the lcd but struggling a bit but making slow progress if you would like to see it? 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 
Posted by: @tooter

The sketch i used was from instructables and was made for the esp 8266 (nodemcu) hence the blynk library.

So why are you using code for an ESP8266:ESP8266 ? 

I see that the blynk library offers a complete and self-contained Wi-Fi networking solution, allowing it to either host the application or to offload all Wi-Fi networking functions from another application processor. Is that what you want, to control the hardware from an Android mobile device or something? I don't have a smart phone so that is not an option for me to work out.

I understood that you wanted to read two sonar sensors and output results on an LCD?  Also that you wanted a button to toggle between the readings of each sonar sensor. If the LCD has two lines of text you might just display both readings at the same time.

 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

diagram of water meter.

water meter diagram

   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

Ok just saw your diagram of the water meter circuit.

I will wire it up tomorrow. It is 4:15AM here and I am going back to bed 🙂

 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  
Posted by: @robotbuilder

Ok just saw your diagram of the water meter circuit.

I will wire it up tomorrow. It is 4:15AM here and I am going back to bed 🙂

 

no probs thanks for the help.


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  
Posted by: @robotbuilder
Posted by: @tooter

The sketch i used was from instructables and was made for the esp 8266 (nodemcu) hence the blynk library.

So why are you using code for an ESP8266:ESP8266 ? 

I see that the blynk library offers a complete and self-contained Wi-Fi networking solution, allowing it to either host the application or to offload all Wi-Fi networking functions from another application processor. Is that what you want, to control the hardware from an Android mobile device or something? I don't have a smart phone so that is not an option for me to work out.

I understood that you wanted to read two sonar sensors and output results on an LCD?  Also that you wanted a button to toggle between the readings of each sonar sensor. If the LCD has two lines of text you might just display both readings at the same time.

 

Hi yes that is what i want. I used the esp 8266 code as it was the easiest for me to understand. I have rewritten the code so i can understand it a little better and got it out punting to serial shoeing water depth and how many litres are left I just need it out putting to the lcd. I think it would be easier to understand if it had a mode button as I want it to show the amount of fresh water in one tank and the amount of grey water i the other I wouldn't want to get them mixed up for obvious reasons. thank you.

 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

I really like the LCD output that you get form the firsr  skech posted on page 1. It gives a persentage and a bar increasing from left to fight my plan was to have that screen plus fresh and grey in the top left of each screen when the mode button is pushed. Hope that makes sense.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

Sure you can make it however you want once you know how it all works.
I already know how to read two sonar sensors so that is done.
This is my first foray into using the LCD display so I have begun with the "Hello World" 🙂
By the end of the day I should have a good idea how to  use the LCD display.

Here are some examples of the sources I am using as a tutorials.

https://www.circuitbasics.com/how-to-set-up-an-lcd-display-on-an-arduino/

https://www.arduino.cc/en/Reference/LiquidCrystal

LCD HelloWorld

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {
  
}

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@tooter

Some comments on your code:

#define pi 3.1415926535897932384626433832795

You left this "pi" macro in your code, however you are using the Arduino built in version of "PI" instead.  Just be aware that the C and C++ languages are case sensitive in nature, so you should remove one of these to avoid any confusion.

Having said that, Arduino also offers a built in sq(x) function to help simplify your code, i.e:

const int Area1 = PI * sq(Diameter1 / 2);

Most importantly, I would review the logic you're using in the following conditional statement:

if (Distance1 >= Depth1 || Distance1 == 0 ) Distance1 = Depth1; //Check it dont go negative

I think you really only want to ensure that the distance is within range, and then perform your calculations, and take appropriate action otherwise - For example:

  if(Distance1 >= 0 and Distance1 <= Depth1) {
    Serial.println("In range");
    /*Perform your calculations here*/
   } else {
    Serial.println("Out of range");
    /*Flash a warning led or buzzer, etc... here*/ 
   }

Lastly, the following is not a big deal, but just letting you know that you can embed new lines and tab spaces directly within strings, to reduce your code size if you wish:

  Serial.println("\nTank 1");
  Serial.println("\tWater Distance: " + String(Distance1));
  Serial.println("\tWater Depth: "    + String(WaterDepth1));
  Serial.println("\tLitres: "         + String(Litres1));

Cheers!


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

Hi wow you have been bust today. It looks like you made more progress in one day that I have all week 😄. I will have a good look through the examples you put up and adress the things you flagged in my code it's just a matter of time and I'll get there. I appreciate the help. Cheers


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

Ok so made a little progress today. learnt a little to. Using your sketch as a guide I managed to get the lcd to out-put how many litres in the tank(see pic) surprisingly easy when it printing to serial already.

I also made the changes to the sketch you suggested. thanks.

Is it possible to change the out of range amount  as I would like the range to be low for the frash water tank and high for the grey water and a 3-5 sec buzzer to sound when fresh is down to 25% and grey is at 75%.

IMG 20200520 170638
IMG 20200520 170630

 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

   
ReplyQuote
Page 2 / 6