Led light up a soon as power applied

hi , i am a final year student and i am making my final year project , so i use PIR sensor (HC-SR501) , Rf Module 315 MHz and arduino uno R3. in my project the led in the receiver part should light up when data received from the transmitter but the problem is the led light up as soon as the power applied to it. can some one help me with this problem. i am very new with arduino and coding so i dont know which part is wrong.

transmitter
transmitter

receiver
receiver

transmitter sketch

//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 3;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;

#include <RH_ASK.h>
#include <SPI.h>


RH_ASK rf_driver;
/////////////////////////////
//SETUP
void setup(){
  rf_driver.init();
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);

    Serial.begin(9600);
    if (rf_driver.init());
      Serial.println("init failed");
  }

  void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;   
         static char *msgHigh = "motion detected";
         rf_driver.send((uint8_t*)msgHigh, strlen(msgHigh));
         rf_driver.waitPacketSent();         
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec"); 
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){       
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
           static char *msgLow = "motion ended";
           rf_driver.send((uint8_t*)msgLow, strlen(msgLow));
           rf_driver.waitPacketSent();         
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
    delay(1000);
  }

receiver sketch

int dataPin = 11;
int ledPin =10;


#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK rf_driver;


void setup()
{
    rf_driver.init();  
    Serial.begin(9600);	// Debugging only
    if (rf_driver.init())
         Serial.println("init failed");
    
  pinMode (11, INPUT );
  pinMode (10 ,OUTPUT);
  digitalWrite (10 ,LOW);
}

void loop()
{

  if (digitalRead (11) == HIGH);
     digitalWrite (10 , HIGH);

  if( digitalRead (11) == LOW);
     digitalWrite (10, LOW);
    uint8_t buf[8];
    uint8_t buflen = sizeof(buf);
    if (rf_driver.recv(buf, &buflen)) // Non-blocking
    {
      int i;
      // Message with a good checksum received, dump it.
      Serial.print("Message: ");
      Serial.println((char*)buf);         
    }
}

Try
. . .
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);
pinMode(ledPin, OUTPUT);
. . .

Do you mean very briefly at startup?

Do you have link to the datasheet for the receiver module?

yes from the moment power applied to it .
receiver specification

  • operating V = DC 5V
    -Quiescent current = 4mA
  • Frequency = 315 Mhz
  • sensitivity = -105 DB

this is in the transmitter code but the problem is in the receiver part

Receiver too.


  pinMode (11, INPUT );
  digitalWrite (10 ,LOW);
  pinMode (10 ,OUTPUT);


Need a bit more than that. It's possible that the data line has a pull-up resistor... so it's default state is HIGH... the gets pulled LOW when required.

What is the purpose of the LED ? Is it just to show that something has been received? Maybe you would be better just to wait until you have read some actual data, and then set the LED on?

Hi,
You send this;

 static char *msgHigh = "motion detected";
         rf_driver.send((uint8_t*)msgHigh, strlen(msgHigh));

but you don't look for it in the receiver, all you are looking for with;

if (digitalRead (11) == HIGH);
     digitalWrite (10 , HIGH);

  if( digitalRead (11) == LOW);
     digitalWrite (10, LOW);

in the receiver is a level on pin 11, this will be probably noise when there is nothing to receive.
So it will probably be HIGH.
You need to turn the LED ON when the actual message from the transmitter is sent.

There are two examples in the IDE from RadioHead.

One a TX and the other Rx.
Use them to get your project started.

ask_receiver
and
ask_transmitter

Use those and get them working BEFORE adding the LED or PIR.

This may help.
dsh.772-146.1.pdf (669.7 KB)

Tom... :smiley: :+1: :coffee: :australia:

the purpose of the LED is to indicate when data received from the transmitter. i don't know about the pull op resistor, i buy all my component online and those are the specification that are listed

Post a link to where you bought it from.

RF Wireless 315 / 433 MHz Transmitter & Receiver Module Pair | Shopee Malaysia

In C language, this is equivalent to

  if (digitalRead (11) == HIGH) {  }

"do nothing"

thank you tom for the file, i already try this code before and its not working. the sketch that i posted was a new one that i recently got from nice people in this community as well and everything work perfectly except the LED in the receiver part

Please don't start new threads for an existing topic
https://forum.arduino.cc/t/transmitter-keep-sending-signal/1054684/7

i am really really sorry but i am kinda behind my schedule and nobody reply on the previous topic . so create the new one. once again i apologize

Look at my reply. I believe I found the problem.