yvesmorele
Published © CC BY-NC-SA

Sensors for Individual Sampling Pumps with LORA

I made a system to control the good operation for individuals sampling pumps.

IntermediateFull instructions provided886
Sensors for Individual Sampling Pumps with LORA

Things used in this project

Hardware components

LILYGO TTGO ESP32 LoRa OLED
×1
MPXV7002 pressure sensor
×1

Software apps and online services

MIT App Inventor 2
MIT App Inventor 2

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

schematic pressure sensor TTGO

Code

sender

Arduino
send the pressure value to the receiver
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>

//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
#define dP = 34;

//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 866E6

//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15 
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

//packet counter
int counter = 0;

const int potPin = 34;
double Pression;
double Vout;
int i = 0;  //Incrmente i pour faire une moyenne de 10 valeures
double moyenne; //Moyenne des essais
double total;

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
int potValue = 0;
void setup() {

  //reset OLED display via software
  pinMode(OLED_RST, OUTPUT);
  digitalWrite(OLED_RST, LOW);
  delay(20);
  digitalWrite(OLED_RST, HIGH);

  //initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("LORA SENDER ");
  display.display();
  
  //initialize Serial Monitor
  Serial.begin(115200);
  
  Serial.println("LoRa Sender Test");

  //SPI LoRa pins
  SPI.begin(SCK, MISO, MOSI, SS);
  //setup LoRa transceiver module
  LoRa.setPins(SS, RST, DIO0);
  
  if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  Serial.println("LoRa Initializing OK!");
  display.setCursor(0,10);
  display.print("LoRa Initializing OK!");
  display.display();
  delay(2000);
}

void loop() {
  
  total = 0;
 i = 0;
    while (i < 50)
  //Serial.print("Sending packet: ");
  //Serial.println(counter);
  {
    Vout = float(analogRead(potPin))*(5/4095.00);  // Passe d'un rsultat binaire en tension
    Pression =((Vout *1200)-2950); // Passe de la tension  la pression aprs calcul d'talonnage
    total = total + Pression;
    
    Serial.println (total);
    Serial.println (Vout);
    Serial.println (Pression);
   delay (10);
    i++;
    
    moyenne = total/i;
    Serial.println(moyenne);
    //delay (10);
  }
    
  //Send LoRa packet to receiver
  LoRa.beginPacket();
  LoRa.print("#");
  LoRa.print(moyenne);
  LoRa.print(",capteur3");
  LoRa.print(", compteur ");
  LoRa.print(counter);
   LoRa.print(",");
  LoRa.endPacket();
  
  display.clearDisplay();
  display.setCursor(0,15);
  display.print("EMETTEUR POMPE ");
  display.setTextSize(2);
  display.print("3"); 
   display.setTextSize(1);    
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("Counter:");
  display.setCursor(50,0);
  display.print(counter); 
  display.setCursor(0,40);
   display.setTextSize(2);
  display.print((moyenne)); 
  display.print(" Pa");
   display.setTextSize(1);     
  display.display();

  counter++;
  
  delay(1000);
}

receiver

Arduino
receive the pressure value and send it by bletooth the result to tha android app
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif


BluetoothSerial SerialBT;

//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const uint8_t vbatPin = 35;
float VBAT;  // battery voltage from ESP32 ADC read
//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26

//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 866E6

//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15 
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);

String LoRaData;

void setup() { 
  pinMode(vbatPin, INPUT);
  //reset OLED display via software
  pinMode(OLED_RST, OUTPUT);
  digitalWrite(OLED_RST, LOW);
  delay(20);
  digitalWrite(OLED_RST, HIGH);
  
  //initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("LORA RECEIVER ");
  display.display();
  
  //initialize Serial Monitor
  Serial.begin(115200);
 SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("LoRa Receiver Test");
  
  //SPI LoRa pins
  SPI.begin(SCK, MISO, MOSI, SS);
  //setup LoRa transceiver module
  LoRa.setPins(SS, RST, DIO0);

  if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  Serial.println("LoRa Initializing OK!");
  display.setCursor(0,10);
  display.println("LoRa Initializing OK!");
  display.display();  
}

void loop() {
  
VBAT = (float)(analogRead(vbatPin)) / 4095*2*3.3*1.1;
display.setCursor(0,55);
   display.print("batterie  ");
   display.print(VBAT);
   display.display();

   
  //try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    //received a packet
    Serial.print("Received packet ");

    //read packet
    while (LoRa.available()) {
      LoRaData = LoRa.readString();
    //Serial.print(LoRaData);
     
    // SerialBT.print(LoRa.readString());
     
    //if (Serial.available()) {
    // SerialBT.print(LoRa.readString());
     
 // }
    
    }

    //print RSSI of packet
    SerialBT.print(LoRaData);
    Serial.print(LoRaData);
    int rssi = LoRa.packetRssi();
    Serial.print(" with RSSI ");    
    Serial.println(rssi);
    SerialBT.print("' with RSSI ");
     SerialBT.println(LoRa.packetRssi());
 //   Dsiplay information

String readString = (LoRaData);

// Split the readString by a pre-defined delimiter in a simple way. '%'(percentage) is defined as the delimiter in this project.
int delimiter, delimiter_1, delimiter_2,  delimiter_3 ;

delimiter = readString.indexOf("#");
delimiter_1 = readString.indexOf(",", delimiter + 1);
delimiter_2 = readString.indexOf(",", delimiter_1 +1);
delimiter_3 = readString.indexOf(",", delimiter_2 +1);

// Define variables to be executed on the code later by collecting information from the readString as substrings.
String pression = readString.substring(delimiter + 1, delimiter_1);
String numcapteur = readString.substring(delimiter_1 + 1, delimiter_2);
String compteur = readString.substring(delimiter_2 + 1, delimiter_3);


 
   display.clearDisplay();
   display.setCursor(0,0);
   //display.print("RECEPT CAPTEUR POMPE");
   //display.setCursor(0,10);
   display.print("pression   ");
   display.print(pression);
   display.setCursor(0,10);
   display.setTextSize(2);
   display.print(numcapteur);
   display.setTextSize(1);
  display.setCursor(0,40);
  // display.print(compteur);
   display.setCursor(0,40);
   display.print("RSSI:");
   display.setCursor(30,40);
   display.print(rssi);
   
    
   
    int Pression = pression.toInt();
    
  if (Pression > 100) { 
    display.setCursor(100,20);
    display.setTextSize(2);
    display.print("OK");
    display.setTextSize(1);
    Serial.println(Pression);
    display.display();
  }
 else {
    display.setCursor(100,20);
    display.setTextSize(2);
    display.print("Fail");
    display.setTextSize(1);
    display.display();
  }
  }
  }

  

pompe_definitif_ttgo_111_IOT_gif.aia

Textile
android app
No preview (download only).

Credits

yvesmorele

yvesmorele

9 projects • 45 followers
chemical scientist

Comments