In my project I have a DHT temperature/humidity sensor and a PIR. I'm transmitting the data those two sensors receive to another device. When I transmit the data with the "radio.sendWithRetry" the pin connected to the PIR goes "high" or reads 3.3 volts and triggers a false positive movement of the sensor. I've tried moving my PIR sensor to different pins but each time I notice the same thing. I'm using the miniWirelessHW-915 (Anarduino MiniWireless Details) for this project. Below is my code. Please help and thank you in advance.
#include <dht.h>
//Start RFM69 Specific Code -------------------------------------------------------------------------------------------------
#include <RFM69.h>
#include <SPI.h>
#define NODEID 10 //unique for each node on same network 1X=basement 2X=Main Level
#define NETWORKID 14 //the same on all nodes that talk to each other
#define GATEWAYID 1
#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "WIRELESSKEY" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 30 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200 //must be 9600 for GPS, use whatever if no GPS
//Device IDs- 2=PIR 3=Magnet 4=Temp/hum 5=IR Sensor 6=Light Sensor
typedef struct {
int nodeID; //node ID
int deviceID; //sensor ID (2, 3, 4, 5, 6)
unsigned long var1_usl; //uptime in ms
float var2_float; //sensor data?
float var3_float; //battery condition?
} Payload;
Payload theData;
char buff[20];
byte sendSize=0;
boolean requestACK = false;
RFM69 radio;
// End RFM69 Specific Code -------------------------------------------------------------------------------------------------
int PIRinputPIN = 7;
int pirState = LOW;
int val = 0;
dht DHT;
#define DHT22_PIN 6
void setup() {
Serial.begin(SERIAL_BAUD);
Serial.println("Serial Started");
theData.nodeID = NODEID;
radio.initialize(FREQUENCY,NODEID,NETWORKID);
radio.setHighPower();
radio.encrypt(ENCRYPTKEY);
char buff[50];
sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(buff);
pinMode(PIRinputPIN, INPUT);
theData.nodeID = 10;
delay(10000); //PIR needs to calibrate
}
void loop() {
//------------------------------------------------------------------------------
//deviceID = 2 for PIR
//------------------------------------------------------------------------------
val=digitalRead(PIRinputPIN);
if (val == HIGH && pirState == LOW)
{
Serial.println("MOTION DETECTED!!!!");
theData.deviceID = 2;
theData.var2_float = val;
radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData));
pirState = HIGH;
}
else if (val == LOW && pirState == HIGH)
{
Serial.println("No more motion");
theData.deviceID = 2;
theData.var2_float = val;
radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData));
pirState = LOW;
}
delay (10000);
//------------------------------------------------------------------------------
//deviceID = 4 for temp/humidity
//------------------------------------------------------------------------------
Serial.println("DHT.read");
DHT.read22(DHT22_PIN);
delay(2000);
Serial.println("DHT.humidity");
float h = DHT.humidity;
delay(2000);
float t = DHT.temperature;
Serial.println("DHT.temperature");
delay(2000);
t = t * 1.8 + 32;
Serial.print("Temp/Hum: ");Serial.print(t); Serial.print("F / "); Serial.print(h); Serial.print("%");Serial.println(" ");
delay(2000);
theData.deviceID = 4;
theData.var2_float = t;
theData.var3_float = h;
radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData));
delay (2000);
}