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;
}