Help with multiple motion sensors

Hi there:

Im making a project where I have 2 motion sensors in line. The thing is that i want to detect when a person enter and exit from a room and at the same time has a counter. To be more specific, I called one of the sensor r1 and the other one r2, If the person enters, r1 turn on first and then r2, and viceversa, if the person exits r2 turn on first and then r1. In the same code Im making a reading from the temperature in the room. I have this code but it gave me an error and I cant figured it out.

#include <OneWire.h>
#include <DallasTemperature.h>

//TODO: Investigate the ~ in beside the port number in the board (e.g., ~3 vs 4)

#define ONE_WIRE_BUS 4 //temperature on port 4

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer = { 0x28, 0x43, 0xC2, 0x03, 0x04, 0x00, 0x00, 0x85 };

volatile boolean r1IsEvent;
volatile boolean r2IsEvent;
volatile int pcounter;

int RELAY = 13; //pin for the RELAY

void setup(void)
{
Serial.begin(9600);

sensors.begin();

sensors.setResolution(insideThermometer, 10);
r1IsEvent = false;
r2IsEvent = false;
pcounter =
//attach receiver one to pin 2
attachInterrupt(0, receiverOneChanged, FALLING);
//attach receiver one to pin 3
attachInterrupt(1, receiverTwoChanged, FALLING);

}

void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop(void)
{
delay(4000);
Serial.print("Here we go!!!...\n\r");
sensors.requestTemperatures();

Serial.print("The temperature is: \n\r");
printTemperature(insideThermometer);
Serial.print("\n\r");
Serial.print("We got it!!!!\n\r");
Serial.print("\n\r");
Serial.print("\n\r");
Serial.print("\n\r");
}

void receiveOneChanged(){
r1IsEvent = true;
if(r2IsEvent){
r1IsEvent = false;
r2IsEvent = false;
//person exit
pcounter = pcounter - 1;
if(pcounter == 0){
digitalWrite(RELAY, LOW);
}
}
}

void receiveTwoChanged(){
r2IsEvent = true;
if(r1IsEvent){
if(pcounter == 0){
digitalWrite(RELAY, HIGH);
}
r1IsEvent = false;
r2IsEvent = false;
//person entered
pcounter = pcounter + 1;
}
}

I have this code but it gave me an error and I cant figured it out.

And, you're not going to tell us what it was. Why is that?

what you mean, the error??

Yes, the error.

these are the errors:

allan_temp_sensor.cpp: In function 'void setup()':

allan_temp_sensor:30: error: 'receiverOneChanged' was not declared in this scope

allan_temp_sensor:32: error: 'receiverTwoChanged' was not declared in this scope

What are the names of the functions you have written?

void receiveOneChanged(){
void receiveTwoChanged(){

I'm wondering why you are not registering those functions?
//attach receiver one to pin 2
attachInterrupt(0, receiverOneChanged, FALLING);
//attach receiver one to pin 3
attachInterrupt(1, receiverTwoChanged, FALLING);

Where I need to add the lines?? Can you show me that please??

You don't need to add any lines. You just need to correct the ones that are wrong.

?????

I think that I need more help with this. im not so clear with what i need to do.

?????

If you named your functions Joe() and Fred(), you would not register them as Mary and Susan, would you?

The name you are registering is NOT the name of the function.

i did the change but now I have this error:

allan_temp_sensor.cpp: In function 'void setup()':
allan_temp_sensor:30: error: void value not ignored as it ought to be

  pcounter =
  //attach receiver one to pin 2
  attachInterrupt(0, receiverOneChanged, FALLING);

You can't assign the return value from attachInterrupt to pcounter, since attachInterrup does not return a value.

I can't believe you are trying to use interrupts at your current skill level.

And what i need to do in that case?? Erase that line??

And what i need to do in that case?? Erase that line??

Yes.. And,, stop using double punctuation marks.. It makes you look silly..

Thanks for the compliment, tell me if am wrong, if I erased that part from the code Im going to lost the pcounter that I need to count, or not?

tell me if am wrong, if I erased that part from the code Im going to lost the pcounter that I need to count, or not?

The pcounter variable will still exist. It will still be valued in the ISRs.