motion sensors randomly stopped working?

i have a motion sensor i got with a sensor kit. i was able to get it working just fine with my arduino. (elegoo mega2560 R3)

i then ordered some more motion sensors and tested one of the new ones by replacing the first one. and it worked just fine as well.

now i'm trying to put them all on the board together and somehow even when i hook them up exactly as before they don't work. the original one now basically never detect motion and the new ones always detect motion.

i'm not sure how to go about troubleshooting this anymore. i dunno i'm gonna keep fighting with it... maybe just posting this here well magically fix it or something.

udate: well the first motion sensor magically works again...? superstition partially confirmed.

Without a schematic, a picture or code, it's going to be difficult for anyone to help you.

I hope you don't have them all connected to the same pin you used to test.

Paul

i'm not sure how to make a diagram... here's what i have wired on the board:

pin 6~ -> breadboard row J27 -> breadboard F27 -> motion sensor signal
GND -> breadboard - -> motion sensor -
5V -> breadboard + -> motions sensor +

i currently don't have any of the other motion sensors connected but i but they're gonna be basically the same but with pins 7-11 and the corresponding breadboard bars. so i can eventually have them installed in different locations using some cat6 wire i have to connect them.

in my initial testing i had the original motion sensor hooked up and had it transmitting a message over serial to a raspberry pi that i have a python script that reads the messages. every time it gets the "Ready" message it sends "T" to have the arduino transmit sensor data. i had the pi controlling a relay on the arduino initially. i have some code for trying to let the pi set how many motion and dht11 sensors there are... but i'm noticing that i don't have that actually setting up the pins. but for now i'm trying to manually set the number of motion sensors i have attached.

i'm including a photo of the current state of the board. it still has the wires from where the relay was plugged into the breadboard. and also an LED that's just connected to the power that i had initially had wired through the relay for testing. and there's a light sensor wired up to A1

#include <dht11.h>
dht11 DHT11;

bool person_present = false;
int person_gone = 0;

int motion_threshold = 1;
int person_gone_threshold = 45000;

int motion_count = 1;
int motion_pin[] =      {6,7,8,9,10,11};
int motion_detected[] = {0,0,0,0,0,0};

int relay_pin = 3;
int relay_pin_b = 5;

int light_count = 1;
int lights[] = {A1};

int heat_count = 1;
int heat[] = {A5};

int temps_count = 0;
int temps_index = 0;
int temps[] = {2,4,22,23,24,25};
int temp_delay = 0;
int temp_delay_threshold = 20;

bool manual_mode = false;

int incomingByte = 0;

int loop_delay = 200;





void setup() {
  // setup motion input pins
  int i;
  for(i = 0; i < motion_count; i++){
    pinMode(motion_pin[i],INPUT);
  }
  for(i = 0; i < light_count; i++)
    pinMode(lights[i], INPUT);
  for(i = 0; i < heat_count; i++)
    pinMode(heat[i], INPUT);
  for(i = 0; i < temps_count; i++)
    pinMode(temps[i], INPUT);
  
  // setup relay pins
  pinMode(relay_pin,OUTPUT);
  pinMode(relay_pin_b,OUTPUT);
  
  // setup serial
  Serial.begin(9600);
  Serial.println("Start");
}




bool setTemp = true;
void loop() {

  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    switch(incomingByte){
      case 84: // T
        CheckSensors();
        break;
      case 65: // A
        digitalWrite(relay_pin,HIGH);
        break;
      case 97: // a
        digitalWrite(relay_pin,LOW);
      case 66: // B
        digitalWrite(relay_pin_b,HIGH);
        break;
      case 98: // b
        digitalWrite(relay_pin_b,LOW);
        break;
      case 77: // M
        manual_mode = true;
        break;
      case 109: // m
        manual_mode = false;
        break;
      case 83: // S
        setTemp = true;
        break;
      case 115: // s
        setTemp = false;
        break;
      case 48: // 0
        if(setTemp)
          temps_count = 0;
        else
          motion_count = 0;
        break;
      case 49: // 1
        if(setTemp)
          temps_count = 1;
        else
          motion_count = 1;
        break;
      case 50: // 2
        if(setTemp)
          temps_count = 2;
        else
          motion_count = 2;
        break;
      case 51: // 3
        if(setTemp)
          temps_count = 3;
        else
          motion_count = 3;
        break;
      case 52: // 4
        if(setTemp)
          temps_count = 4;
        else
          motion_count = 4;
        break;
      case 53: // 5
        if(setTemp)
          temps_count = 5;
        else
          motion_count = 5;
        break;
      case 54: // 6
        if(setTemp)
          temps_count = 6;
        else
          motion_count = 6;
        break;
      case 10:
        break;
      default:
        Serial.println(incomingByte);        
    }
  }
  // detect motion
  for(int i = 0; i < motion_count; i++){
    DetectMotion(i);
    Serial.println(motion_pin[i]);
  }
  // the arduino is in control of the lights
  if(!manual_mode){
    if(person_present){
      //Serial.println("+### Person Detected ###+");
      digitalWrite(relay_pin,HIGH);
      if(person_gone++ > person_gone_threshold){
        person_present = false;
        digitalWrite(relay_pin,LOW);
      }
    } else {
      digitalWrite(relay_pin,LOW);
    }  
  }
  
}
void CheckSensors(){
  checkLight();
  checkHeat();
  
  Serial.print("Motion:");
  for(int i = 0; i < motion_count; i++){
    Serial.print(motion_detected[i]);
    if(i < motion_count-1)
      Serial.print(",");
  }
  Serial.println("");
  
  // check the temperatures
  if(temps_count > 0){
    if(temp_delay++ > temp_delay_threshold){
      CheckTemp(temps_index);
      temp_delay = 0;
      temps_index++;
      if(temps_index >= temps_count)
        temps_index = 0;
      }
  }
  
  Serial.println("Ready");
  //Serial.println("loop??");
  delay(loop_delay);
}




// detect motion

void DetectMotion(int i) {
  if(digitalRead(motion_pin[i]) == HIGH){
    motion_detected[i]++;
  } else {
    motion_detected[i] = 0;
  }
  if(motion_detected[i] > motion_threshold) {
    person_present = true;
    person_gone = 0;
    Serial.print("MotionDetected,");
    Serial.print(i+1,DEC);
    Serial.print(",");
    Serial.print(motion_pin[i],DEC);
    Serial.print(":");
    Serial.println(motion_detected[i]);
    delay(loop_delay);
  }
  delay(100);
}


void checkHeat(){
  for(int i = 0; i < heat_count; i++){
    Serial.print("Heat");
    Serial.print(",");
    Serial.print(i+1,DEC);
    Serial.print(",");
    Serial.print(heat[i],DEC);
    Serial.print(":");
    Serial.println(analogRead(heat[i]), DEC);
  }
}

void checkLight(){
  for(int i = 0; i < light_count; i++){
    Serial.print("Light");
    Serial.print(",");
    Serial.print(i+1,DEC);
    Serial.print(",");
    Serial.print(lights[i],DEC);
    Serial.print(":");
    Serial.println(analogRead(lights[i]), DEC);
  }
}

// check temperature
void CheckTemp(int i){
  int chk = DHT11.read(temps[i]);
  Serial.print("HumidityTemperature");
  Serial.print(",");
  Serial.print(i+1,DEC);
  Serial.print(",");
  Serial.print(temps[i],DEC);
  Serial.print(":");
    
  switch (chk){
    case DHTLIB_OK: 
        //Serial.println("OK"); 
        Serial.print((float)DHT11.humidity, 2);
        Serial.print(",");
        Serial.print(Fahrenheit(DHT11.temperature), 2);
        Serial.println("");
        break;
    case DHTLIB_ERROR_CHECKSUM: 
        Serial.println("Checksum error"); 
        break;
    case DHTLIB_ERROR_TIMEOUT: 
        Serial.println("Timeout error"); 
        break;
    default: 
        Serial.println("Unknown error"); 
        break;
  }
}

double Fahrenheit(double celsius) {
  return 1.8 * celsius + 32;
}

double Kelvin(double celsius){
  return celsius + 273.15;
}

I would start with a simple code just to see if one, two, three etc sensors work ( just print “1” etc), adding each in turn to your board. Not looked at your code as it does a lot more !

The output of those sensors , is I think either 0v or 3v when triggered, which is just within the trigger range of the Arduino, any voltage drops across your board may cause some problems .

Any flickering leds on the board may confuse the sensor as may pointing them at each other ( unsure about that, but easy to check)

Bear in mind too that the outside strips on your prototype board may not be connected across any blank space.

hammy:
I would start with a simple code just to see if one, two, three etc sensors work ( just print “1” etc), adding each in turn to your board. Not looked at your code as it does a lot more !

The output of those sensors , is I think either 0v or 3v when triggered, which is just within the trigger range of the Arduino, any voltage drops across your board may cause some problems .

Any flickering leds on the board may confuse the sensor as may pointing them at each other ( unsure about that, but easy to check)

Bear in mind too that the outside strips on your prototype board may not be connected across any blank space.

yeah. stripping out most of the code so it's just the motion sensors is probably gonna be my best option. just get it to broadcast when a sensor detects motion. then i can add the light sensors back in. and worry about adding in the DHT11 stuff again once i get more of those.

and hopefully there won't be too much voltage drop from the length of wire it's gonna take to put sensors at the top of the stairs and in the basement. otherwise i'm gonna have to figure out why the motion sensors were basically always detecting motion on the raspberry pi's GPIO pins.

If you are going to use them at a distance I’d use the PIR sensors used in house alarm systems

stripped down code to just this.

void setup() {
  // setup motion input pins
  pinMode(6,INPUT);
    
  // setup serial
  Serial.begin(9600);
  Serial.println("Start");
}

void loop() {
  Serial.println(digitalRead(6));
  delay(1000);
}

including photo of circuit.

i tried swapping the gnd and 5v pins and either way it outputs "1". (for the new sensors, the original one now always sends either 1 or 0 depending on which way i've wired gnd and 5v)

the pins on the PIR aren't labeled. i'm not sure how i'd identify which pin is which on the motion sensor without just trying all possible configurations...?

attaching photo of the circuit... and closeup of the back of two of the sensors. the one on the left with the yellow jumper is the original one that came with a sensor kit. and the one on the right is one of the ones i ordered. i now have 10 of them...

if anybody has any idea why they would suddenly stop working that would be really helpful. because like i said originally. before i tried to wire up the rest of the sensors everything was working perfectly. and now i can't even get them to work at all.

ok. i think i might have figured it out.

first: 3.3v instead of 5v
second: new sensors pins are 3.3v on one side s on the other and gnd in the middle...

gonna give Hammy some karma for mentioning 3v... probably wouldn't have ever thought to try 3.3v otherwise.

edit: nevermind the moment i connect more than one motion sensor the whole lot seem to get scrambled. at this point i'm mostly grasping at superstitions and random guesses.