Here’s a full overview of how to build a LoRa-based [temperature sensor](https://www.onzuu.com/category/temperature-sensors) — perfect for remote IoT applications like smart farming, warehouse monitoring, or environmental tracking. ![ESP32-LoRa32-TTGO-OLED-WEB-SERVER](https://hackmd.io/_uploads/B1B2S_Bmlx.jpg) **LoRa-Based Temperature Sensor: Project Overview** **What It Does:** A temperature sensor (e.g., [DS18B20](https://www.ampheo.com/product/ds18b20-26808200) or [DHT22](https://www.ampheo.com/product/part-dht22-26872164)) measures ambient temperature. A microcontroller reads this data and transmits it via a LoRa module (e.g., SX1276/RFM95) to a remote LoRa gateway or receiver node. **Hardware Components** ![企业微信截图_20250610165441](https://hackmd.io/_uploads/ryv17dB7gx.png) **Hardware Connection (Example: [Arduino](https://www.ampheo.com/c/development-board-arduino) + RFM95 + DS18B20)** ![企业微信截图_20250610165520](https://hackmd.io/_uploads/SJ6bXurmle.png) DS18B20 (with pull-up resistor): * VCC → 3.3V / 5V * GND → GND * DATA → D7 (with 4.7kΩ pull-up to VCC) **Sample Code (Arduino Framework)** Using: * OneWire & DallasTemperature for [DS18B20](https://www.ampheoelec.de/product/ds18b20-26808200) * LoRa library (by Sandeep Mistry) ``` cpp #include <SPI.h> #include <LoRa.h> #include <OneWire.h> #include <DallasTemperature.h> // LoRa Pins #define SS 10 #define RST 9 #define DIO0 2 // Temperature Sensor Pin #define ONE_WIRE_BUS 7 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup() { Serial.begin(9600); sensors.begin(); LoRa.setPins(SS, RST, DIO0); if (!LoRa.begin(915E6)) { Serial.println("LoRa init failed."); while (1); } Serial.println("LoRa init OK."); } void loop() { sensors.requestTemperatures(); float tempC = sensors.getTempCByIndex(0); Serial.print("Sending: "); Serial.println(tempC); LoRa.beginPacket(); LoRa.print("Temp: "); LoRa.print(tempC); LoRa.endPacket(); delay(5000); // Send every 5 seconds } ``` **Receiving Side (LoRa Receiver Node)** Another Arduino or ESP32 running: ``` cpp #include <SPI.h> #include <LoRa.h> void setup() { Serial.begin(9600); LoRa.setPins(10, 9, 2); if (!LoRa.begin(915E6)) { Serial.println("Starting LoRa failed!"); while (1); } } void loop() { int packetSize = LoRa.parsePacket(); if (packetSize) { String received = ""; while (LoRa.available()) { received += (char)LoRa.read(); } Serial.print("Received: "); Serial.println(received); } } ``` **Notes** * Adjust frequency to 868E6 or 433E6 depending on your region. * Add sleep mode (e.g., LowPower.h) for battery-powered nodes. * You can use [STM32](https://www.ampheo.com/search/STM32) or ESP32 instead of [Arduino](https://www.ampheoelec.de/c/development-board-arduino) ([What is Arduino?](https://adrianchad.blogspot.com/2025/05/what-is-arduino.html)) for better performance or wireless networking. * You can expand to use LoRaWAN and send data to TTN (The Things Network) or a [Raspberry Pi](https://www.ampheo.com/c/raspberry-pi/raspberry-pi-boards) LoRa Gateway. **Optional Add-ons** ![企业微信截图_20250610165736](https://hackmd.io/_uploads/SJ6tmurmel.png)