LoRa Motion Sensor IOT Music Player Alarm

Published Aug 20, 2022
 5 hours to build
 Intermediate

LoRa transceivers are demonstrated by a motion sensor transmitting easily though walls to an ESP8266 controlling a WD player playing barking dog sounds.

display image

Components Used

ESP8266 WiFi Module
ESP8266 is a system on chip (SoC) which provides WIFI capability for embedded applications. This enables internet connectivity to embedded applications. ESP8266 modules are mostly used in Internet of Things(IoT) applications.
1
PIR Sensor
PIR motion sensors sense the Infrared signal radiated from moving objects including human or animal body. It is generally used to detect the presence of human or animal motions.
1
3.3V Voltage Regulator AMS1117
LDO Voltage Regulators 1A,Pos Fix Vltg LDO Linear Reg
1
Arduino UNO
Arduino UNO
1
WTV020SD
WTV020-SD is a module for embedding audio playback.
1
7805 Voltage Regulator
7805 Voltage Regulator
1
LM386 Audio Amplifier
Audio Amplifiers LOW VLTG AUDIO PWR AMP
1
Speaker
Speakers & Transducers 28 mm, Round Frame, 0.25 W, 32 Ohm, Neodymium Magnet, PET Cone, Speaker
1
RFM95 Lora TRX module
Sub-GHz Modules Lora TRX module +20dBm/-139dBM 300Kbps
1
Description

Motion Sensor IOT Music Player Alarm with LoRa

Previously, I created an Arduino Uno powered front porch motion sensor, and used it to activate a WTV020-SD music player which plays alternating recordings of dogs barking on an SD card. However, neither the popular 433MHz nor the popular nRF24L01 2.4GHz RF transceivers could reliably transmit though the front wall of the house. (Greenhouse data from the back yard, same problem).

LoRa technology provides 3.3 volt transceivers that can transmit a very long distance, some claim miles, and work nicely from the back yard and though walls. This project adds a LoRa transmitter to the motion sensor’s Arduino Uno; and an Node ESP8266  to the before-mentioned player using the Node’s built-in WIFI for a monitorable webpage.

LoRa Motion Sensor:

The motion sensor uses an Arduino Uno, A buck step down power supply module (the Uno output 3.3V output does not provide quite enough power for the LoRa), and a Hope95Rf LoRa transceiver.

Send:

 

Sensor in a box:

 

I'm using Arduino Sandeep LoRa library which by default utilizes the SPI protocol default pins in both the Uno and Esp8266. This simple code for the Uno transmits the word "motion" when motion is detected:

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


int inputPinMotion = 2;   //  Motion Sensor
int val = 0;      // State of PIR sensor LOW/HIGH


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

  Serial.println("LoRa Sender");

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

//====================

void loop() {    
  
  val = digitalRead(inputPinMotion);  // Motion Sensor  read input value
  if (val == HIGH) {
    Serial.println("Motion detected");    
    sendMotionDetect();
    delay(5000);
    Serial.println("Motion ended");  
   }

   } // End Loop

void sendMotionDetect() {

 // send packet
  LoRa.beginPacket();
  LoRa.print("motion");
  LoRa.endPacket();
  Serial.println("Motion sent");
  delay(100);  
}

Receive:

The receiver uses a NodeMCU ESP8266  (shown with the Sandeep library default pins for the LoRa) and triggers the music player via the Trigger Out pin when the word motion is received.

LoRa data is received in the code's loop. I’m serial printing the first six digits as an array, and interpreting the transmission by looking at the first letter:

void loop() {

 //LoRa Receive Packet
 int packetSize = LoRa.parsePacket();
  if (packetSize) {
  Serial.println("Received packet");

// read packet
    while (LoRa.available()) {     
    for (i=0; i < 6; i++){
    myArray[i] = LoRa.read();
      }
    }
   Serial.println(myArray);
   
// Interpret packet 
  if (myArray[0] == 'm'){ 
  Serial.println("sendBark"); 
  sendBark();
}

 

The webpage has both an Async Server and a WebSocket server. I'm experimenting with the Websocket server because it easily displays serial data on a webpage.

Music Player:

WD Player

This WD player is currently using a WTV020-SD-16P  a "U-disk audio player TF SD card voice module MP3 Sound" ($1.70 US). This WD player chip is said to be often used in toys; however that seems a bad idea since the SD card holder opens so easily. Drop of glue maybe. I've ordered a 5W Voice Playback Module MP3 Player I/O Trigger UART Control For Arduino for fun. Drawing from the WTV... SPEC sheet:

 

The various player inputs are triggered by applying ground to the appropriate pins. I’m using only the NEXT input which plays and switches the dog barks each time it is triggered.  Here is my operating circuit copied onto a Fritzing Drawing:

Circuit includes a EK1236 (200 Gain LM386 Audio AMP) (abt $2.00 US); a button for manual testing purposes, some regulators for power distribution, and a speaker. This uses its own power instead of a buck converter in case I want more powerful speaker output later, although this is adequately loud now. The two voltage regulators provide conversion from a 9V cord to 3.3V for the player (top) and 5V (bottom) for the Audio Amp. The wiring on the regulators may look odd as the 1117 and 1124 regulators had different in and out pins. The player dog barking sounds are triggered by either pushing the Next button; or a 3V or 5V high on the "To Trigger" input which applies ground to pin 13 of the player through the PNP transistor. I forget why I hooked up the Audio Amp to the Audio-L channel out instead of the WD speaker connections. 

Installed the project in an old speaker,  My speaker sounded better than the one that was in the original.

 

 

 

Work in progress. Next steps, make a circuit board for the music player;  add additional tracks besides barking, improve the webpage, make an LoRa Arduino Shield for Arduino Unos, and an addon board for the ESP8266 so that I can attach a more cool antenna to the greenhouse version:

 

Come on guys and gals! I'm not trying to win this year, just post useful information. A few likes? 

Thanks, Evan

Codes

Downloads

wd_player Download
Comments
Ad