fudhail
Published

Dam monitoring with B-l072Z LoRaWAN

Monitoring the dam parameters like water level, humidity, pressure, temperature etc. Its essential to maintain the normal condition of the dam

IntermediateProtip3 hours2,834
Dam monitoring with B-l072Z LoRaWAN

Things used in this project

Hardware components

STM32 B-L072Z-LRWAN1
×1
STM32 Nucleo X-NUCLEO IKS01A3
×1
Arduino WATER SENSOR SEN18
×1
Arduino RAIN SENSOR MH-RD
×1

Software apps and online services

Arduino IDE
Arduino IDE
HELIUM CONSOLE

Story

Read more

Schematics

Schematic diagram

The connections are
Rain drop sensor have 4 pins but we are using only 3 pins.VCC,GND ,D and A.The pin A is connected to the A0 of B-L072Z with x-necleo board
the second module Water level sensor have 3 pins that is VCC,GND and S or A .this pin S or A is connected to the pin A2

Code

The code

C/C++
The code included all modules . You can upload this code using Arduino IDE ,and watch the serial monitor for the visualization of data.
We are using only Three sensors of X-NUCLEO board
#include <LPS22HHSensor.h>
#include <STTS751Sensor.h>
#include <HTS221Sensor.h>

#ifdef ARDUINO_SAM_DUE
#define DEV_I2C Wire1
#elif defined(ARDUINO_ARCH_STM32)
#define DEV_I2C Wire
#elif defined(ARDUINO_ARCH_AVR)
#define DEV_I2C Wire
#else
#define DEV_I2C Wire
#endif
#define SerialPort Serial

// lowest and highest Rain sensor readings:
int rain = A0;
const int sensorMin = 0;     // sensor minimum
const int sensorMax = 1024;  // sensor maximum
// Water level sensor 
int watersensor = A2;
const int waterMin = 0; // minimum value of this sensor its too small
const int waterMax= 1024; //the maximum value of reading 
int levelReading;

// Components
LPS22HHSensor *PressTemp;
HTS221Sensor *HumTemp;
STTS751Sensor *Temp3;

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(watersensor,INPUT);
  pinMode(rain,INPUT);

  // Initialize serial for output.
  SerialPort.begin(115200);
  
  // Initialize I2C bus.
  DEV_I2C.begin();

  
  PressTemp = new LPS22HHSensor(&DEV_I2C);
  PressTemp->Enable();
  HumTemp = new HTS221Sensor (&DEV_I2C);
  HumTemp->Enable();
  Temp3 = new STTS751Sensor (&DEV_I2C);
  Temp3->Enable();

}

void loop() {
  
  // Led blinking.
  digitalWrite(LED_BUILTIN, HIGH);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(250);

  // Read humidity and temperature.
  float humidity = 0, temperature = 0;
  HumTemp->GetHumidity(&humidity);
  HumTemp->GetTemperature(&temperature);

  // Read pressure and temperature.
  float pressure = 0, temperature2 = 0;
  PressTemp->GetPressure(&pressure);
  PressTemp->GetTemperature(&temperature2);

  //Read temperature
  float temperature3 = 0;
  Temp3->GetTemperature(&temperature3);

  // read the Rain sensor on analog A0:
  int sensorReading = analogRead(rain);
  int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
  
  // range value:
  switch (range) {
 case 0:    // Sensor getting wet
    Serial.println("Raining");
    break;
 case 1:    // Sensor getting wet
    Serial.println("Rain Warning");
    break;
 case 2:    // Sensor dry
    Serial.println("Not Raining");
    break;
  }

  // Read the rain sensor on analog A2
  int levelReading = analogRead(watersensor);
  int level = map(levelReading, waterMin, waterMax, 0, 10);  //the sensor is very small so we used 10% only.
  
  // range value: the level of water described below
  switch (level) {
 case 0:    
    Serial.println(" LEVEL OF WATER = 91%");
    break;
 case 1:    
    Serial.println(" LEVEL OF WATER = 92%");
    break;
 case 2:    
    Serial.println(" LEVEL OF WATER = 93%");
    break;
 case 3:    
    Serial.println(" LEVEL OF WATER = 94%");
    break;
 case 4:   
    Serial.println(" LEVEL OF WATER = 95%");
    break;
 case 5:   
    Serial.println(" LEVEL OF WATER = 96%");
    break; 
 case 6:    
    Serial.println(" LEVEL OF WATER = 97%");
    break;
 case 7:   
    Serial.println(" LEVEL OF WATER = 98%");
    break;
 case 8:   
    Serial.println(" LEVEL OF WATER = 99%");
    break;
 case 9:    
    Serial.println(" LEVEL OF WATER = 100% Full");
    break;

  }
  

  // Output data.
  SerialPort.print("| Hum[%]: ");
  SerialPort.print(humidity, 2);
  SerialPort.print(" | Temp[C]: ");
  SerialPort.print(temperature, 2);
  SerialPort.print(" | Pres[hPa]: ");  
  SerialPort.print(pressure, 2);
  SerialPort.print(" | Temp2[C]: ");
  SerialPort.println(temperature2, 2);

}

Credits

fudhail

fudhail

6 projects • 13 followers
opencv Arduino Raspberry pi iot robotics

Comments