element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Just Encase
  • Challenges & Projects
  • Design Challenges
  • Just Encase
  • More
  • Cancel
Just Encase
Blog Monitoring an irrigation canal using LoRa #3
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Just Encase to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: redcharly
  • Date Created: 15 Feb 2022 3:16 PM Date Created
  • Views 588 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Monitoring an irrigation canal using LoRa #3

redcharly
redcharly
15 Feb 2022

Hi, I'm Carlo Russo and I'd like to introduce you to my third blog for the Design Challenge: Just Encase.
We have already made the connection between the two Boards using the LoRaWAN protocol and in this blog we will consider the sensors to be added to the transmitter board and we will see how to send the data obtained to the receiver board.
As sensors, the kit includes the "Grove Starter Kit for Arduino", a collection of sensors and actuators of all kinds.

image

There are sensors for temperature, brightness, audio signals, touch, etc. All these sensors are easily integrated into the Base Shield which is compatible with Arduino Uno.

In our case, we don't want to burden the project too much by using another board and always keeping in mind the consumption constraint (I don't want to open the box often to replace the batteries), I chose not to use the Base Shield and to connect the sensor boards that I intend to use directly on the Arduino MKR1300 it's not a pretty solution but it works!.

By acting in this way, obviously, we will not have an orderly and compact realization but we will be forced to manage wires that connect the various boards.

We will use the temperature sensor to measure temperature inside the case. 

image


Another sensor that I will use is the "High Temp Waterproof DS18B20" temperature sensor, a sensor with three wires, resistant to liquids and which uses a digital technology that makes it easy to use even at relatively long distances.

image

This sensor uses a Dallas 1-Wire protocol technology that allows the transport of digital data through 1 wire only and has a resolution of up to 12 bits. This protocol also provides for the identification of each individual sensor through a unique 64-bit code that allows you to connect multiple sensors on the same wire and be able to recognize and manage them individually via their respective ID. This protocol is quite complex but, by downloading and using the library in the Arduino IDE, using this sensor becomes really simple.
In our case we do not have large requirements related to accuracy so we can safely use the sensor at a lower resolution.

Now it's time to see the board with the two sensors.
This is the photo of the transmitting board with the two sensors mounted. There is a bit of a mess of cables but, when we put everything in the box, we will arrange the cables in an orderly manner.
Using two temperature sensors we will be able to simultaneously monitor the temperature inside the box (through the sensor of the Grove Kit) and the outside temperature (thanks to the sensor DS18B20) of the channel water.

image

I had to add a few lines of code to the transmitter sketch to read the data from the second sensor and transmit it via the LoRaWAN protocol.
As soon as I started the sketch for a while I feared that something had gone wrong as I got two too different temperature values. I made a couple of checks and verified the accuracy of the formula used to obtain the temperature in degrees Celsius. Only after minutes of confusion did I understand the mystery ... the sensor of the Adafruit was right under the jet of hot air from my laptop and therefore measured a temperature significantly higher than that measured by the other!

The sender:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <LoRa.h>
//#include <math.h>

#define ONE_WIRE_BUS 2

const int B = 4750;               // B value of the thermistor
const int R0 = 100000;            // R0 = 100k
const int pinTempSensor = A0;     // Grove - Temperature Sensor connect to A0
 
OneWire oneWire(ONE_WIRE_BUS); // Imposta la connessione OneWire
DallasTemperature sensore(&oneWire); // Dichiarazione dell'oggetto sensore
int counter = 0;

void setup() {
  Serial.begin(9600);
  sensore.begin();

  if (!LoRa.begin(868E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  delay(1000);
}


void loop() {
  int a = analogRead(pinTempSensor);
  float R = 1023.0/((float)a)-1.0;
  //convert to temperature via datasheet ;
  float temperature=(1.0/((log(R)/B)+(1/298.15)))-273.15;
  
  Serial.print("Box temperature = ");
  Serial.println(temperature);
  sensore.requestTemperatures(); // richiesta lettura temperatura
   
  Serial.print("Sending packet: ");
  Serial.print(counter);
  Serial.print("  ");
  float celsius = sensore.getTempCByIndex(0);
  Serial.print(celsius);
  Serial.println("°C");
  
  // send LoRa packet
  LoRa.beginPacket();
  LoRa.print(counter);
  LoRa.print("   OutTemperature ");
  LoRa.print(celsius);
  LoRa.print("°C  ");
  LoRa.print("   BoxTemperature ");
  LoRa.print(temperature);
  LoRa.println("°C");
  LoRa.endPacket("!");

  counter++;

  delay(10000);
}
     

 

   image

The receiver:

#include <SPI.h>
#include <LoRa.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa Receiver");
  if (!LoRa.begin(868E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

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

    // read LoRa packet
  String LoRaLabel = LoRa.readStringUntil('!');
  Serial.print(LoRaLabel);
  }
}

image

With this third blog we have completed the transmitter, in the next part we will modify the receiver.

Until next time!


Carlo

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube