Long Range Wireless Water Level Indicator

Step 1: Material Required For Wireless Water Level Indicator

#include <SPI.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN
const byte addresses[][6] = {"00001"};

const uint8_t level_pins[] = { 2, 3, 4, 5, 6, 7, 8 };
const uint8_t num_level_pins = sizeof(level_pins);
uint8_t level_states[num_level_pins];

void setup()
{
  int i = num_level_pins;
  while (i--)
  {
    pinMode(level_pins[i], INPUT);
  }
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setDataRate(RF24_1MBPS);
  radio.openWritingPipe(addresses[0]); // 00001
  radio.setPALevel(RF24_PA_HIGH);
  radio.enableDynamicPayloads();
}

void loop()
{
  int i = num_level_pins;
  bool different = false;
  while (i--)
  {
    uint8_t state = ! digitalRead(level_pins[i]);
    if ( state != level_states[i] )
    {
      different = true;
      level_states[i] = state;
    }
  }

  if ( different )
  {
    Serial.println("Now sending...");
retry:    bool ok = radio.write( level_states, num_level_pins );
    Serial.print("Level States: ");
    Serial.print(level_states[0]);
    Serial.print(" , ");
    Serial.print(level_states[1]);
    Serial.print(" , ");
    Serial.print(level_states[2]);
    Serial.print(" , ");
    Serial.println(level_states[3]);
    Serial.print(" , ");
    Serial.print(level_states[4]);
    Serial.print(" , ");
    Serial.print(level_states[5]);
    Serial.print(" , ");
    Serial.println(level_states[6]);
    if (ok)
      Serial.println("Sent\n\r");
    else
    { Serial.println("Failed\n\r");
      goto retry;
    }
  }
  delay(20);
}
#include <SPI.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN
const byte addresses[][6] = {"00001"};

int Buzz = 2;

const uint8_t level_pins[7];
const uint8_t num_level_pins = sizeof(level_pins);
uint8_t level_states[num_level_pins];

#include <UTFT.h>
UTFT myGLCD(QD220A, A2, A1, A5, A4, A3); // SDI,CLK,CS,RST,RS
int LED = A0;
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];

void setup()
{
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  pinMode(Buzz, OUTPUT);
  digitalWrite(Buzz, LOW);
  myGLCD.InitLCD(0);
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.setColor(VGA_TEAL);
  myGLCD.print("Wireless", CENTER, 50, 360);
  myGLCD.print("Water", CENTER, 80, 360);
  myGLCD.print("Level", CENTER, 110, 360);
  myGLCD.print("Indicator", CENTER, 140, 360);
  delay(1000);

  myGLCD.clrScr();
  myGLCD.print("Water Level", 0, 0, 360);
  myGLCD.setColor(VGA_NAVY);

  myGLCD.fillRect(0, 217, 175, 219);
  myGLCD.fillRect(0, 20, 2, 216);
  myGLCD.fillRect(173, 20, 175, 219);

  myGLCD.drawLine(0, 191, 175, 191);
  myGLCD.drawLine(0, 163, 175, 163);
  myGLCD.drawLine(0, 135, 175, 135);
  myGLCD.drawLine(0, 107, 175, 107);
  myGLCD.drawLine(0, 79, 175, 79);
  myGLCD.drawLine(0, 51, 175, 51);
  myGLCD.drawLine(0, 23, 175, 23);

  int i = num_level_pins;
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setDataRate(RF24_1MBPS);
  radio.openReadingPipe(1, addresses[0]); // 00001
  radio.setPALevel(RF24_PA_HIGH);
  radio.enableDynamicPayloads();
  radio.startListening();
}

void loop()
{
L1:  while (!radio.available());
  radio.read( level_states, num_level_pins );

  int i = num_level_pins;
  while (i--)
  {
    if ( level_states[6])
    {
      Serial.println("Level 7");
      myGLCD.setColor(VGA_TEAL);
      myGLCD.fillRect(3, 24, 172, 50);
      for (int k = 0; k <= 5; k++)
      {
        myGLCD.setColor(VGA_GREEN);
        myGLCD.print("FULL", CENTER, 28, 360);
        digitalWrite(Buzz, HIGH);
        delay(50);
        myGLCD.setColor(VGA_TEAL);
        myGLCD.print("FULL", CENTER, 28, 360);
        digitalWrite(Buzz, LOW);
        delay(50);
      }
      goto L1;
    }
    if ( level_states[5])
    {
      Serial.println("Level 6");
      myGLCD.setColor(VGA_TEAL);
      myGLCD.fillRect(3, 52, 172, 78);
      myGLCD.setColor(VGA_BLACK);
      myGLCD.fillRect(3, 24, 172, 50);
      goto L1;
    }
    if ( level_states[4])
    {
      Serial.println("Level 5");
      myGLCD.setColor(VGA_TEAL);
      myGLCD.fillRect(3, 80, 172, 106);
      myGLCD.setColor(VGA_BLACK);
      myGLCD.fillRect(3, 52, 172, 78);
      goto L1;
    }
    if ( level_states[3])
    {
      Serial.println("Level 4");
      myGLCD.setColor(VGA_TEAL);
      myGLCD.fillRect(3, 108, 172, 134);
      myGLCD.setColor(VGA_BLACK);
      myGLCD.fillRect(3, 80, 172, 106);
      goto L1;
    }
    if ( level_states[2])
    {
      Serial.println("Level 3");
      myGLCD.setColor(VGA_TEAL);
      myGLCD.fillRect(3, 136, 172, 162);
      myGLCD.setColor(VGA_BLACK);
      myGLCD.fillRect(3, 108, 172, 134);
      goto L1;
    }
    if ( level_states[1])
    {
      Serial.println("Level 2");
      myGLCD.setColor(VGA_TEAL);
      myGLCD.fillRect(3, 192, 172, 216);
      myGLCD.fillRect(3, 164, 172, 190);
      myGLCD.setColor(VGA_BLACK);
      myGLCD.fillRect(3, 136, 172, 162);
      goto L1;
    }
    if ( level_states[0])
    {
      Serial.println("Level 1");
      myGLCD.setColor(VGA_TEAL);
      myGLCD.fillRect(3, 192, 172, 216);
      myGLCD.setColor(VGA_BLACK);
      myGLCD.fillRect(3, 164, 172, 190);
      for (int k = 0; k <= 4; k++)
      {
        myGLCD.setColor(VGA_RED);
        myGLCD.print("LOW", CENTER, 196, 360);
        digitalWrite(Buzz, HIGH);
        delay(50);
        myGLCD.setColor(VGA_TEAL);
        myGLCD.print("LOW", CENTER, 196, 360);
        digitalWrite(Buzz, LOW);
        delay(50);
      }
      goto L1;
    }
  }
  delay(5);
}

5 Comments

  1. Krishna has been a life-saver with this project from start to finish! He put this together way back in 2018, I stumbled on it in 2023 after we installed an irrigation tank at our Farm which is in a remote part of the property. Without spending thousands of dollars on a manufactured system, I wanted to give a try and building a custom solution based on the efforts of someone like Krishna.

    Last year I got all the components together, I’m now finally getting them soldered in place and the sensor, transmitter, and receiver in place at the Farm. He’s been able to walk me through a number of the confusing parts for me. His work is well detailed in the YouTube video as well as here…I’m just totally new to soldering circuit boards and uploading code to PCB’s.

    I will drop in another note once I get this finished and up and running in the next few weeks. Great work Krishna…thanks!

  2. Arduino: 1.8.18 (Windows 10), Board: “Arduino Nano, ATmega328P”

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:9:15: warning: uninitialized const ‘level_pins’ [-fpermissive]

    const uint8_t level_pins[7];

    ^~~~~~~~~~

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino: In function ‘void setup()’:

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:36:42: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“Wireless”, CENTER, 50,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:37:39: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“Water”, CENTER, 80,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:38:40: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“Level”, CENTER, 110,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:39:44: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“Indicator”, CENTER, 140,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:43:41: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“Water Level”, 0, 0,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino: In function ‘void loop()’:

    sketch_jul05a:67:57: error: void value not ignored as it ought to be

    done = radio.read( level_states, num_level_pins );

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:80:50: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“FULL”, CENTER, 28,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:84:50: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“FULL”, CENTER, 28,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:140:50: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“LOW”, CENTER, 196,360);

    ^

    C:\Users\Akhil v\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:144:50: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    myGLCD.print(“LOW”, CENTER, 196,360);

    ^

    exit status 1

    void value not ignored as it ought to be

    receiver code error sir please help

    • Code has been updated, try compiling updated code. But make sure to install Arduino libraries provided in step 6 before compiling the codes.

      If you are unable to add libraries to Arduino. Go to Arduino program files and search for libraries folder and paste downloaded library after unzipping it.

      • Sir, I checked the new code .I think there is an error ..The receiver always shows level full when the transmitter is on..

  3. sir, I checked the new code .I think there is an error ..The receiver always shows level full when the transmitter is on..

Leave a Reply

Your email address will not be published. Required fields are marked *