I’m new to Arduino and my general coding knowledge is limited. I’m using Arduino Unos to open and close relays based on inputs from PIR motion sensors (pin 10). I’ve built 5 of these circuits and my code probably isn’t efficient but it does what I expect it to.
I want the circuits to be scalable so that, if connected, the value from the PIR sensor on a master circuit will control the relays on slave circuits.
My plan was to have an output wire (pin 13) and an input wire (pin 11) on each circuit. I tried to use the same logic as I was using for the PIR sensor, but I experienced what I now believe is a floating pin (random highs / lows). I changed pin 11 from input to input pullup, reversed my highs / lows, and now I’m having a strange intermittent problem that doesn’t make sense to me.
I set the output (pin 13) on my master as low and connected it to the input_pullup (pin 11) on my slave but it didn’t override the pullup resistors to report low. I connected from ground on the master to pin 11 on the slave, it still didn’t work.
The curious thing is that if I run from a specific ground pin on the master to pin 11 on the master (the same circuit) it continuously triggers the loop which is what I would expect it to do. When I run from the same ground pin on the master to pin 11 on the slave it doesn’t work. It also doesn’t work if I connect any other ground pin on the master to pin 11 on the master.
I’ve repeated and replicated the results and switched the master and slave circuits to be relatively confident that all of the pins are behaving as they should and that the circuits are indeed identical.
Why would connecting from one ground pin to the input_pullup on the same circuit work but if I connect the same ground pin to the input pullup on an identical circuit it doesn’t work? Also, why does it work from one ground pin on a self-contained circuit but not from other ground pins on the same circuit?
My code is provided below. Your time and consideration are greatly appreciated!
int delay1 = 0; //Delay between prop 1 and prop 2 (in seconds)
int delay2 = 0; //Delay between prop 2 and prop 3 (in seconds)
int delay3 = 0; //Delay between prop 3 and prop 4 (in seconds)
int delay4 = 0; //Delay between prop 4 and prop 5 (in seconds)
int delay5 = 0; //Delay between prop 5 and prop 6 (in seconds)
int delay6 = 0; //Delay between prop 6 and prop 7 (in seconds)
int delay7 = 0; //Delay between prop 7 and prop 8 (in seconds)
int delay8 = 5; //Delay between prop 8 and prop 1 (in seconds)
int led = 13; // the pin that the LED is atteched to
int sensor10 = 10; // the pin that the PIR motion sensor is atteched to
int sensor11 = 11; // the pin that the PIR motion sensor is atteched to
int state10 = LOW; // by default, no motion detected
int state11 = LOW; // by default, no motion detected
int val10 = 0; // variable to store the sensor status (value)
int val11 = 0; // variable to store the sensor status (value)
const int relayPin2 =2; //the "s" of relay module attach to
const int relayPin3 =3; //the "s" of relay module attach to
const int relayPin4 =4; //the "s" of relay module attach to
const int relayPin5 =5; //the "s" of relay module attach to
const int relayPin6 =6; //the "s" of relay module attach to
const int relayPin7 =7; //the "s" of relay module attach to
const int relayPin8 =8; //the "s" of relay module attach to
const int relayPin9 =9; //the "s" of relay module attach to
void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(sensor10, INPUT); // initialize sensor as an input
pinMode(sensor11, INPUT_PULLUP); // initialize sensor as an input
Serial.begin(9600); // initialize serial
pinMode(relayPin2, OUTPUT); //initialize relay as an output
pinMode(relayPin3, OUTPUT); //initialize relay as an output
pinMode(relayPin4, OUTPUT); //initialize relay as an output
pinMode(relayPin5, OUTPUT); //initialize relay as an output
pinMode(relayPin6, OUTPUT); //initialize relay as an output
pinMode(relayPin7, OUTPUT); //initialize relay as an output
pinMode(relayPin8, OUTPUT); //initialize relay as an output
pinMode(relayPin9, OUTPUT); //initialize relay as an output
}
void loop(){
val10 = digitalRead(sensor10); // read sensor value
val11 = digitalRead(sensor11); // read sensor value
if (val10 == HIGH or val11 == LOW) { // check if the sensor is HIGH
digitalWrite(led, LOW); // turn LED ON
digitalWrite(relayPin2, HIGH); //disconnect the relay
delay(delay1*1000); // delay
digitalWrite(relayPin3, HIGH); //disconnect the relay
delay(delay2*1000); // delay
digitalWrite(relayPin4, HIGH); //disconnect the relay
delay(delay3*1000); // delay
digitalWrite(relayPin5, HIGH); //disconnect the relay
delay(delay4*1000); // delay
digitalWrite(relayPin6, HIGH); //disconnect the relay
delay(delay5*1000); // delay
digitalWrite(relayPin7, HIGH); //disconnect the relay
delay(delay6*1000); // delay
digitalWrite(relayPin8, HIGH); //disconnect the relay
delay(delay7*1000); // delay
digitalWrite(relayPin9, HIGH); //disconnect the relay
delay(1000); // delay
digitalWrite(led, HIGH); // turn LED ON
digitalWrite(relayPin2, LOW); //Close the relay
digitalWrite(relayPin3, LOW); //Close the relay
digitalWrite(relayPin4, LOW); //Close the relay
digitalWrite(relayPin5, LOW); //Close the relay
digitalWrite(relayPin6, LOW); //Close the relay
digitalWrite(relayPin7, LOW); //Close the relay
digitalWrite(relayPin8, LOW); //Close the relay
digitalWrite(relayPin9, LOW); //Close the relay
delay(10); // delay
for (int x=0; x < delay8; x++) { // Wait for 1 second
delay(1000);
}
}
else {
digitalWrite(led, HIGH); // turn LED ON
digitalWrite(relayPin2, LOW); //Close the relay
digitalWrite(relayPin3, LOW); //Close the relay
digitalWrite(relayPin4, LOW); //Close the relay
digitalWrite(relayPin5, LOW); //Close the relay
digitalWrite(relayPin6, LOW); //Close the relay
digitalWrite(relayPin7, LOW); //Close the relay
digitalWrite(relayPin8, LOW); //Close the relay
digitalWrite(relayPin9, LOW); //Close the relay
delay(1); // delay 1 milliseconds
}
}
/*************************************************/

