Heltec Lora32 V2 - Sending LoRa message is making my pin HIGH ?!

megajuras
Posts: 2
Joined: Wed Dec 06, 2023 5:59 pm

Heltec Lora32 V2 - Sending LoRa message is making my pin HIGH ?!

Postby megajuras » Wed Dec 06, 2023 6:06 pm

Hi,

I’m trying to crate a Lora PIR sensor using HC-SR501 module and Heltec Lora 32 v2 (EU433).
I connected the PIR to groung, 3v3 and GPIO13. I am able read the pin state. Cool.

Then I added some timer-based limits and actions (i.e. notify motion detected not often that 20secs, send keepAlive each 3mins). Untill actions are just Serial.print mocks (nothing is really sent) everything is fine: Sensor is putting the pin HIGH for few seconds, then goes LOW. My time limiters are working and I’m not spamming, but sending keepalives if needed. All is fine.

Then I added actual transmission to my actions:

Code: Select all

void sendMotionDetected() {
  Serial.println("LoRa: Sending MotionDetected !");
  // send packet
  LoRa.beginPacket();
  LoRa.print("1");
  LoRa.endPacket();
}

void sendKeepAlive() {
  Serial.println("LoRa: Sending KeepAlive.");
  // send packet
  LoRa.beginPacket();
  LoRa.print("0");
  LoRa.endPacket();
}
…and strange things started to happen. Below console log is when only sendKeepAlive() is sending and sendMotionDetected() is only serialPrint(msg). Most interesting thing is that there is NO MOTION DETECTED!

Code: Select all

Pirpinstate = 0
Pirpinstate = 0
Pirpinstate = 0
Pirpinstate = 0
Pirpinstate = 0
LoRa: Sending KeepAlive.
Pirpinstate = 1
LoRa: Sending MotionDetected !
Pirpinstate = 1
Pirpinstate = 1
Pirpinstate = 1
Pirpinstate = 1
Pirpinstate = 1
Pirpinstate = 0
Pirpinstate = 0
Pirpinstate = 0
Pirpinstate = 0
Pirpinstate = 0
Pirpinstate = 0
LoRa: Sending KeepAlive.
Pirpinstate = 1       // 1 shouldn't be here - there was no movement
LoRa: Sending MotionDetected !
Pirpinstate = 1       // 1 shouldn't be here - there was no movement
Pirpinstate = 1       // 1 shouldn't be here - there was no movement
Pirpinstate = 1       // 1 shouldn't be here - there was no movement
Pirpinstate = 1       // 1 shouldn't be here - there was no movement
Pirpinstate = 1       // 1 shouldn't be here - there was no movement
Pirpinstate = 0
Pirpinstate = 0
If I only comment out Lora.*** lines in the functions, leaving only SerialPrints - everyting is workink as expected:

Code: Select all

...
Pirpinstate = 0
LoRa: Sending KeepAlive.
Pirpinstate = 0
Pirpinstate = 0
...
Sending LoRa message is making my pin HIGH ?!
They used that pin to talk between Lora and ESP chips - I need to change the pin. Not so easy :confused:

What I tried?
  • changing pin to GPIO 2 and 12 - the same
  • changing PIR sensor to other type (smaller) - the same
  • disconnecting sensors OUT wire - this fixed the issue
  • connect pullDown resistor between IO pin and GND (and disabling INPUT_PULLDOWN in code) - the same
I have the feeling that the sensor acts as an antena and it’s catching LoRa transmission and sets OUT to HIGH.

But how to get rid of it?
(full code below)

megajuras
Posts: 2
Joined: Wed Dec 06, 2023 5:59 pm

Re: Heltec Lora32 V2 - Sending LoRa message is making my pin HIGH ?!

Postby megajuras » Thu Dec 07, 2023 9:34 am

Here is my code with Lora transmissions commented out:

Code: Select all

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

int counter = 0;

#define SS      18
#define RST     14
#define DI0     26
#define BAND    433E6

#define PIR_PIN 2

//logic config
#define SECONDS_DELAY_BETWEEN_DETECTIONS 10
#define SECONDS_DELAY_BETWEEN_KEEP_ALIVE 10  //60



void sendMotionDetected() {
  Serial.println("LoRa: Sending MotionDetected !");
  // send packet
  // LoRa.beginPacket();
  // LoRa.print("1");
  // LoRa.endPacket();
}

void sendKeepAlive() {
  Serial.println("LoRa: Sending KeepAlive.");
  // send packet
  // LoRa.beginPacket();
  // LoRa.print("0");
  // LoRa.endPacket();
}



void setup() {
  //set PIR PIN
  pinMode(PIR_PIN, INPUT_PULLDOWN);

  SPI.begin(5, 19, 27, 18);
  LoRa.setPins(SS, RST, DI0);

  Serial.begin(115200);
  while (!Serial);
  delay(1000);

  Serial.println("LoRa Sender");

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

  LoRa.setSpreadingFactor(11); //accepted values: 6-12
}






int pirPinState = LOW;
unsigned long lastDetectedMilis = 0;
unsigned long lastKeepAliveSentMillis = 0;

void loop() {
  pirPinState = digitalRead(PIR_PIN);
  Serial.print("Pirpinstate = ");
  Serial.println(pirPinState);

  if(pirPinState == HIGH) {
    //motion detected
    if(millis() - lastDetectedMilis > SECONDS_DELAY_BETWEEN_DETECTIONS*1000) {
      lastDetectedMilis = millis();
      sendMotionDetected();
    } else {
      //ignore - detection tooo sooon from previous one
      //Serial.println("ingoring HIGH on PIR_PIN");
    }
  } else {
    if(millis() - lastDetectedMilis > SECONDS_DELAY_BETWEEN_KEEP_ALIVE*1000
    && millis() - lastKeepAliveSentMillis > SECONDS_DELAY_BETWEEN_KEEP_ALIVE*1000) {
      lastKeepAliveSentMillis = millis();
      sendKeepAlive();
    }
  }

  delay(1000);
}

Who is online

Users browsing this forum: No registered users and 84 guests