Luc Paquin
Published © CC BY

Project #28 – Sensors – Water Sensor – Mk26

Project #28 – Sensors – Water Sensor – Mk26

BeginnerFull instructions provided1 hour34
Project #28 – Sensors – Water Sensor – Mk26

Things used in this project

Hardware components

DFRobot FireBeetle 2 ESP32-E
×1
DFRobot Fermion: 3.5” 480x320 TFT LCD Capacitive
×1
DFRobot GDL Line 10 CM
×1
Elecrow Crowtail - Water Sensor 2.0
×1
Elecrow Crowtail - LED Green
×1
DFRobot Gravity: IO Shield for FireBeetle 2
×1
DFRobot Terminal Block Board for FireBeetle 2 ESP32-E IoT
×1
DFRobot Lithium Ion Battery - 1000mAh
×1
DFRobot USB 3.0 to Type-C Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing

Code

DL2601Mk04p.ino

Arduino
/****** Don Luc Electronics © ******
Software Version Information
Project #28 – Sensors – Water Sensor – Mk26
28-26
DL2601Mk04p.ino
DL2601Mk04
1 x DFRobot FireBeetle 2 ESP32-E
1 x Fermion: 3.5” 480x320 TFT LCD Capacitive
1 x GDL Line 10 CM
1 x Crowtail - Water Sensor 2.0
1 x Crowtail - LED Green
1 x Gravity: IO Shield for FireBeetle 2
1 x Terminal Block Board for FireBeetle 2 ESP32-E IoT
1 x Lithium Ion Battery - 1000mAh
1 x Micro USB Cable
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM with Unique ID for Unit
#include "EEPROM.h"
// Wire
#include <Wire.h>
// Arduino
#include "Arduino.h"
// DFRobot Display GDL API
#include <DFRobot_GDL.h>

// Water Sensor
// LED Green
int iLEDG = D11;
// Water
int iWater =  D10;
int iWaterState = 0;
String sW = "";

// Defined ESP32
#define TFT_DC  D2
#define TFT_CS  D6
#define TFT_RST D3

/*dc=*/ /*cs=*/ /*rst=*/
// DFRobot Display 320x480
DFRobot_ILI9488_320x480_HW_SPI screen(TFT_DC, TFT_CS, TFT_RST);

// Software Version Information
// EEPROM Unique ID Information
#define EEPROM_SIZE 64
String uid = "";

// Software Version Information
String sver = "28-26";

void loop() {
  
  // Water Sensor
  isWater();

  // isDisplay Water
  isDisplayWater();

  // Delay 1 Second
  delay( 1000 );

}

getDisplay.ino

Arduino
// DFRobot Display 320x480
// DFRobot Display 320x480 - UID
void isDisplayUID(){

  // DFRobot Display 320x480
  // Text Display
  // Text Wrap
  screen.setTextWrap(false);
  // Rotation
  screen.setRotation(3);
  // Fill Screen => black
  screen.fillScreen(0x0000);
  // Text Color => white
  screen.setTextColor(0xffff);
  // Font => Free Sans Bold 12pt
  screen.setFont(&FreeSansBold12pt7b);
  // TextSize => 1.5
  screen.setTextSize(1.5);
  // Don Luc Electronics
  screen.setCursor(0, 30);
  screen.println("Don Luc Electronics");
  // SD
  screen.setCursor(0, 60);
  screen.println("Water Sensor");
  // Version
  screen.setCursor(0, 90);
  screen.println("Version");
  screen.setCursor(0, 120);
  screen.println( sver );
  // EEPROM
  screen.setCursor(0, 150);
  screen.println("EEPROM");
  screen.setCursor(0, 180);
  screen.println( uid );

}
// isDisplayWater
void isDisplayWater(){

  // DFRobot Display 320x480
  // Text Display
  // Text Wrap
  screen.setTextWrap(false);
  // Rotation
  screen.setRotation(3);
  // Fill Screen => white
  screen.fillScreen(0xffff);
  // Text Color => blue
  screen.setTextColor(0x001F);
  // Font => Free Sans Bold 12pt
  screen.setFont(&FreeSansBold12pt7b);
  // TextSize => 1.5
  screen.setTextSize(1.5);
  // Water Sensor
  screen.setCursor(0, 30);
  screen.println("Water Sensor");
  // Accelerometer X
  screen.setCursor(0, 60);
  screen.println( "Water State" );
  screen.setCursor(0, 90);
  screen.println( sW );

}

getEEPROM.ino

Arduino
// isUID EEPROM Unique ID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getWater.ino

Arduino
// Water Sensor
// is Water
void isWater(){

// Read the State of the Water Sensor value:
  iWaterState = digitalRead(iWater);

  // check if rainning.
  // if it is, the waterState is LOW
  if (iWaterState == LOW) {     
    
    // Turn LED HIGH
    digitalWrite(iLEDG, HIGH);
    sW = "HIGH";

  } 
  else {
    
    // Turn LED LOW
    digitalWrite(iLEDG, LOW);
    sW = "LOW";
    
  }

}

setup.ino

Arduino
// Setup
void setup()
{
 
  // Delay
  delay( 100 );

   // EEPROM Size
  EEPROM.begin(EEPROM_SIZE);
  
  // EEPROM Unique ID
  isUID();

  // Delay
  delay( 100 );
 
  // DFRobot Display 320x480
  screen.begin();

  // Delay
  delay( 100 );
  
  // Water Sensor
  // LED Green 
  pinMode(iLEDG, OUTPUT);
  // Water
  pinMode(iWater, INPUT);

  // Delay
  delay( 100 );

  // DFRobot Display 320x480 - UID
  // Don Luc Electronics
  // Version
  // EEPROM
  isDisplayUID();

  // Delay 5 Second
  delay( 5000 );

}

Credits

Luc Paquin
59 projects • 5 followers
Teacher, Instructor, E-Mentor, R&D and Consulting -Programming Language -Microcontrollers -IoT -Robotics -Machine Learning -AI -Sensors

Comments