Strange behaviour of digital pins


I want to build an application with a pir sensor (pin 2) that triggers an RF signal (Tx, pin 12 with RadioHead library, 433 MHz) when the pir senses a movement. I want this application be powered by a battery (ultimately, I want to use the Arduino Pro Mini for this).

When the pir pin goes high, through a non-blocking timer (sensorTimer), I will not ‘poll’ the pir status for e.g. 5 sec.

Also, to know if my battery has still power enough, I will daily (for test purposes I’ve reduced this to 10" = ctlTimer) sent a signal to a Rx which will process this. In the test program, I just set pin 12 high for 50 msec.

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

RH_ASK driver;  // Tx pin = 12

int sensorPin=2;
int sensorStatus=0;
unsigned long sensorTimer=0;
const unsigned long sensorInterval=5000; // sensor wordt gedurende 5 sec niet gepolled
const char *msg="2";  // identificatie van de pir sensor

unsigned long ctlTimer;
const unsigned long ctlInterval=10000; // 86400000;  // dit is een dag
const char *ctlmsg="0";  // controle message dat batterij nog werkt

void setup()
  //pinMode(12,OUTPUT); does not matter
  while (!Serial);
  Serial.println("Serial started ...");
  if (!driver.init()) Serial.println("Driver init failed ...");


void loop()
  if (sensorTimer == 0)   // sensorTimer == 0 at initialization
    if (sensorStatus == 1)  // alarm,  block 5 sec
      Serial.println("In msg");
  if (millis() > (sensorTimer + sensorInterval))

  if (millis() > (ctlTimer + ctlInterval))
    Serial.println("In ctl");


The problem arises that when I sent pin 12 high with the 433 MHz Tx attached, my sensorpin also goes high ???
(see first image, when 433 MHz Tx is attached)

When I replace the 433 MHz Tx by a simple led, sensorpin stays low as expected.
(see second image when led is attached)

Anyone knows why this is ???

Any help greatly appreciated !!!




To use pin 12 properly as an output, you MUST use pinMode(12, OUTPUT).

If you don't, digitalWrite() will turn on the input pullup resistor and make it [u]act[/u] like a weak output.

Hi jremington.

Tkx for your answer, I tried that as you can see in the code (commented it on/off) but it does not help…


Of course it "helps". Digital output does not work properly unless a pin is declared to be an output pin.

Is your pir sensor stable? If you printed the sensor readings, do you have reliable input?

I assume you use one of those cheap ebay PIR sensors with two control pots on it. You must leave "sensitivity" in the middle, and adjust "delay" fully anti-clockwise. Then the delay (HIGH time) of the PIR sensor board is a minimum of ~3seconds.

digitalWrite(12,HIGH); delay(50); digitalWrite(12,LOW);

Can't do that with a 433Mhz transmitter. You need to send a code. Look at the radiohead examples. Leo..

It might be that the transmitter is feeding into the sensor and causing spurious detection. If you can't filter it out, you maybe have to time share things. For the lines from and to the sensor, use coax. Use a grounded shield at the sensor. Also put a filter on the line going to the transmitter. Dwight

Thx for the answers.

I did all the recommended stuff but no solution. I just don't use the pir when I Tx know. It's a workaround.

Best wishes Leo