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.
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.
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.
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?
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.
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.
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.
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.
So I have now added two ultrasonic sensors and the two results are displayed on the LCD.
I will draw the connections later in case you can't work them out from the code.
Will think about how to output a percentage bar and a mode button later.
#include<LiquidCrystal.h>LiquidCrystallcd(12,11,5,4,3,2);#include"NewPing.h"// Define Constants#defineTRIGGER_PIN_17#defineECHO_PIN_17#defineTRIGGER_PIN_28#defineECHO_PIN_28#defineMAX_DISTANCE400NewPingsonar1(TRIGGER_PIN_1,ECHO_PIN_1,MAX_DISTANCE);NewPingsonar2(TRIGGER_PIN_2,ECHO_PIN_2,MAX_DISTANCE);////// Define Variablesfloatduration1;// Stores First HC-SR04 pulse duration valuefloatduration2;// Stores Second HC-SR04 pulse duration valuefloatdistance1;// Stores calculated distance in cm for First Sensorfloatdistance2;// Stores calculated distance in cm for Second Sensorvoidsetup(){lcd.begin(16,2);// 16 digits and two rows}voidloop(){duration1=sonar1.ping();duration2=sonar2.ping();// Determine distance from duration// Use 343 metres per second as speed of sounddistance1=(duration1/2)*0.0343;distance2=(duration2/2)*0.0343;lcd.setCursor(0,0);lcd.print(distance1);lcd.setCursor(0,1);lcd.print(distance2);delay(500);}
Close up of the LCD displaying two distances. Unfortunately the webcam has a fixed focus and close ups tend to be blurry. Maybe I should get another digital camera!
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:
constintArea1=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>=0andDistance1<=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:
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
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%.
//#Water level sensor. This scetch is to add a digital water lwvel sensor for a motor home //to monitor the fresh and grey water levels. //#The buzzer will sound for 3-5 sec when the level is at 50 and 25% and when grey water is//at 75%#include<Blynk.h>#include<NewPing.h>#include<LiquidCrystal.h>LiquidCrystallcd(12,11,5,4,3,13);#include<EEPROM.h>intaddr=0;intaddr2=1;intflag;bytereadval;#defineSONAR_NUM2//numer of sensors used.//##Tank dimentions change to suitconstintMAX_DISTANCE=400;//Max Distance to measure.constintDiameter1=19;//Diameter of tank 1.constintDiameter2=19;//Diameter of tank2 2.constintDepth1=25;//Depth of tank 1.constintDepth2=25;//Depth of tank2.constunsignedintPeriod=2000;//period between pings, in milliseconds//##Sensor PinsconstintTrigPin1=6;//Triger pin for sensor 1constintEchoPin1=7;//Echo pin for sensor 1constintTrigPin2=10;//Triger pin sensor 2 constintEchoPin2=8;//Echo pin sensor 2constintArea1=PI*sq(Diameter1/2);//Area of tank 1constintArea2=PI*sq(Diameter1/2);//Area of takn 2//Global variablesintLitres1,Litres2,Distance1,Distance2,WaterDepth1,WaterDepth2;BlynkTimertimer;//Config TimerNewPingsonar[SONAR_NUM]={//Sensor object aerrayNewPing(TrigPin1,EchoPin1,MAX_DISTANCE),// Each sensor's trigger pin, echo pin, and max distance to ping.NewPing(TrigPin2,EchoPin2,MAX_DISTANCE)};voidsendSensorReadings(){//#Tank 1 ReadingsDistance1=sonar[0].ping_cm();//Get distance to top of tank if(Distance1>=0andDistance1<=Depth1){Serial.println("In range");WaterDepth1=Depth1-Distance1;//calulate the depth of water in tank 1Litres1=(Area1*WaterDepth1)/1000;//calulate the volume of waterdelay(50);}else{Serial.println("Out of range");/*Flash a warning led or buzzer, etc... here*/}//#Tank2 ReadingsDistance2=sonar[1].ping_cm();//Get distance to top of tank 2if(Distance2>=0andDistance2<=Depth2){Serial.println("In range");WaterDepth2=Depth2-Distance2;//calulate the depth of water in tank 1Litres2=(Area2*WaterDepth2)/1000;//calulate the volume of waterdelay(50);}else{Serial.println("Out of range");/*Flash a warning led or buzzer, etc... here*/}digitalWrite(13,HIGH);//Flash the led so we know ist runningdelay(50);digitalWrite(13,LOW);//#Serial OutputSerial.println();Serial.println();Serial.println("Tank 1 Water Distance: "+String(Distance1));//print Depth tank 1Serial.println("Tank 1 Water Depth: "+String(WaterDepth1));//print WaterDepth tank 1Serial.println("Tank 1 Litres: "+String(Litres1));//print Litres tank 1Serial.println();Serial.println("Tank 2 Water Distance: "+String(Distance2));//print Depth Tank 2Serial.println("Tank 2 Water Depth: "+String(WaterDepth2));//print Waterdepth tank 2Serial.println("Tank 2 Litres: "+String(Litres2));//print Litres tank 2}voidsetup(){lcd.begin(16,2);pinMode(13,OUTPUT);//led pin 13timer.setInterval(Period,sendSensorReadings);// Setup a function to be called every 'n' secondsdelay(10);Serial.begin(19200);//Open serial consoleSerial.println();delay(20);}voidloop(){lcd.setCursor(0,0);lcd.print("TNK 1 Litres "+String(Litres1));//print on lcd amount in liters in Tank1lcd.setCursor(0,1);lcd.print("TNK 2 Litres "+String(Litres2));//print on lcd amount in liters in tank2 timer.run();}
We use cookies on the DroneBot Workshop Forums to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.