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 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 [Pool Water Monitoring] #8 Temperature communication using LoRa and Arduino MKR 1300 WAN and a Serial Console mishap
  • 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: feiticeir0
  • Date Created: 27 Dec 2021 12:24 AM Date Created
  • Views 1597 views
  • Likes 5 likes
  • Comments 2 comments
  • pool_water_monitoring
  • lora
  • ds18b20 MKR 1300 LoRa
  • justencase
  • Arduino MKR WAN 13000
  • arduino serial console
  • just_encase
  • just encase
Related
Recommended

[Pool Water Monitoring] #8 Temperature communication using LoRa and Arduino MKR 1300 WAN and a Serial Console mishap

feiticeir0
feiticeir0
27 Dec 2021

Logo

Hi all !

Hope everyone is well and safe.

Before and a bit after Christmas, was time to test LoRa to LoRa communication using the two Arduinos MKR 1300 WAN from the kit. 

One of the Arduinos will be connected to the Adafruit's high temperature sensor and the other one to the computer. The Adafruit's high temperature sensor is immersed in the pool water.

Hardware

  • 2x Arduino MKR 1300 WAN
  • 1x 4.7K ohm resistor
  • 1x DS18B20 high temperature sensor
  • 2x AA bateries

Note: Although in the picture, the Arduino is powered by USB (powerbank), the final try and the working prototype was being powered by two AA bateries.

Here's the schematics for it:

Schematics

Code

The code is straight forward. I will be using the LoRa sender example from the Arduino examples sending the temperature value (using OneWire's and DallasTemperature libraries) .

Here's the code for LoRa sending the temperature

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

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float celcius = 0;

void setup() {
  //Serial.begin(9600);
  sensors.begin();
  //while (!Serial && millis() < 50000); //need this because it was waiting on serial

  //Serial.println("LoRa Sender");
  if (!LoRa.begin(866E6)) {
    //Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  
  sensors.requestTemperatures();
  celcius = sensors.getTempCByIndex(0);
  //Serial.print("Sending temperature: ");
  //Serial.println(celcius);
  // send packet
  LoRa.beginPacket();
  LoRa.print(celcius);
  //LoRa.print(counter);
  LoRa.endPacket();

  delay(5000);
}

The code is easy to understand, but if you look closely, you'll see (among others) the following line commented out:

  //while (!Serial && millis() < 50000); //need this because it was waiting on serial

Why ?

Because of two things:

1

When powered by batteries, there's no led on. The Arduino doesn't show that it is working... That's a shame and something to be addressed later.

2

No temperature was reaching the other Arduino. What the hell was going on. Powering the Arduino by USB (first, using a powerbank), did light on a led, but still, no temperature on the other side. 

Connecting the Arduino to the computer, did send temperature readings to the other side. But why ???

A closer look into the code and a Google search did produce some results. The thing is, the Arduino is waiting, forever (or 5s - but it didn't work, so I commented out the line) for a serial console... That only exists when connected to the computer.

After commenting all the lines referencing the Serial Console, it finally start sending temperature readings. Still, when powered by batteries, no LED is ON - so just remember that.

Here's the code for the receiving one.

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



void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Receiver");

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

void loop() {
  
  // try to parse packet
  float packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received temperature '");
    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
    /*
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());*/
  }
}

and voilà

Here's both Arduinos connected to the computer, one sending the temperature and the other receiving it.

LoRa communication MKR 1300 WAN

Here's the Arduino MKR1300 WAN on the remote place

Arduino MKR 1300 WAN

And here's the result from the remote Arduino on the Arduino connected to the computer.

Remote temperature

From here to sending to the Arduino IoT cloud is easy.

Next, let's experiment with all the other sensors and start putting all together .

Merry Christmas and Happy holidays.

  • Sign in to reply
  • feiticeir0
    feiticeir0 over 3 years ago in reply to dougw

    It's always a pleasure when you finally solve a "mystery". Thank you dougw

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 3 years ago

    Debugging a "simple" issue can be a tedious and frustrating experience, but it is a lot worse if you don't figure it out. Congratulations.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
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