Digital Water Level Meter With Arduino




Introduction: Digital Water Level Meter With Arduino

this tutorial shows you how to make a digital water level meter with arduino and color display

Step 1: Parts

*Any arduino board

*ili9341 tft display

*5 x 2.2k resistors ,5 x 3.3k resistors

*ultrasonic sensor

Step 2: Connection

Connect display to arduino as above.

resisters are used to convert 5v logic to 3.3. because ili9341 is only working with 3.3v signals.

otherwise whole screen will be filled with white.

*ultra sonic

Trig pin > Arduino pin 5

Echo pin > Arduino pin 6

Step 3: Code

upload this code - and change above mention lines if necessary

code file download

or copy this

#include // include Adafruit graphics library

#include // include Adafruit ILI9341 TFT library

const int trigPin = 5; const int echoPin = 6; // defines variables long duration; int distance; int presntage=0; #define TFT_CS 8 // TFT CS pin is connected to arduino pin 8 #define TFT_RST 9 // TFT RST pin is connected to arduino pin 9 #define TFT_DC 10 // TFT DC pin is connected to arduino pin 10 // initialize ILI9341 TFT library Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

int home; void setup() {

pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); Serial.begin(9600); Serial.println("ILI9341 Test!"); tft.begin(); // read diagnostics (optional but can help debug problems) uint8_t x = tft.readcommand8(ILI9341_RDMODE); Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDMADCTL); Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDPIXFMT); Serial.print("Pixel Format: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDIMGFMT); Serial.print("Image Format: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDSELFDIAG); Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);

pinMode(2,INPUT); Serial.println(F("Done!"));

int home=0; } void loop(void) {


delay(4000); waterlevel(); delay(4000);

} void testFillScreen() { unsigned long start = micros(); tft.fillScreen(ILI9341_BLACK); tft.fillScreen(ILI9341_RED); tft.fillScreen(ILI9341_GREEN); tft.fillScreen(ILI9341_BLUE); tft.fillScreen(ILI9341_BLACK); }

void waterlevel() { tft.fillScreen(ILI9341_BLACK);

tft.drawRect(18,18, 84, 284,ILI9341_GREEN);

while(true) { digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance= duration*0.034/2; // Prints the distance on the Serial Monitor Serial.println(distance);

if(distance<6) {distance=0;} distance=distance-5; if(distance<0) {distance=0;}

if(distance>130) //put here height of your water tank. {distance=130; //put the above value if change, here also }

presntage=distance*100/130; //replace 130 with your water tank height. presntage=100-presntage;

tft.setCursor(130, 130); tft.fillRect(120,120, 120, 50,ILI9341_BLACK); tft.fillRect(20,20, 80, 280,ILI9341_BLACK); tft.setTextColor(ILI9341_GREEN); tft.setTextSize(4); if(presntage!=100){ tft.print(presntage);tft.print(" %"); } else { tft.print(presntage); } if(presntage<10) { tft.fillRect(20,20+(100-presntage)*2.8, 80, presntage*2.8,ILI9341_RED); } else if(presntage<30) { tft.fillRect(20,20+(100-presntage)*2.8, 80, presntage*2.8,ILI9341_YELLOW); } else if(presntage<80) { tft.fillRect(20,20+(100-presntage)*2.8, 80, presntage*2.8,ILI9341_BLUE); } else { tft.fillRect(20,20+(100-presntage)*2.8, 80, presntage*2.8,ILI9341_GREEN); }

delay(1000); }

} void testText() { tft.fillScreen(ILI9341_BLACK); tft.setCursor(20, 40); tft.setTextColor(ILI9341_WHITE); tft.setTextSize(5); tft.println("Welcome");

tft.setCursor(30, 140); tft.setTextColor(ILI9341_RED); tft.setTextSize(2); tft.println("Press Buttons");

tft.setCursor(40, 160); tft.setTextColor(ILI9341_GREEN); tft.setTextSize(2); tft.println("To Navigate");

tft.fillRect(0,290, 100, 30,ILI9341_YELLOW);

tft.setCursor(10, 300); tft.setTextColor(ILI9341_BLUE); tft.setTextSize(2); tft.println("W.Level"); tft.fillRect(140,290, 100, 30,ILI9341_BLUE); tft.setCursor(150, 300); tft.setTextColor(ILI9341_BLACK); tft.setTextSize(2); tft.println(" Info");


Be the First to Share


    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest
    • Lamps Challenge

      Lamps Challenge
    • Puzzles Challenge

      Puzzles Challenge



    Question 1 year ago on Step 2

    Hi. Can the code be modified to include another sensor? I have 2 tanks that I would like to monitor. I would also like to add battery volts, amps and charge to the display. Would that be possible. Trying to create one screen with all these paramaters


    2 years ago

    Put the ".ino " code file in please


    Reply 2 years ago

    The idea is to add the file here not send us off to unrecognised web sites where what we get could have any sort of viruses attached . They at least vet them here. Just click add file. hanks anyway Ill try it.


    Reply 2 years ago

    its a direct link from trusted adds or viruses


    Reply 2 years ago

    That's not the point . Who knows?


    Reply 2 years ago

    Thanks for doing that . You want to edit it into your instructable