Hey guys,
I developped an Arduino program to switch on and off home devices as follow but it doesn't work:
When current is different than 0 (electricity is back), I switch on the fridge only and keep other devices off, wait for 1 minute then switch on other devices.
I switch on the WM when no one is home.
I switch off LIGHT and OUTL when no one is home.
I used PIR motion sensor HCSR501 to detect motion and current sensor ACS712-05 to measure current.
Below my code but it doesn't work.
Could you help me?
const int FRID = 12;
const int WM = 11;
const int OUTL = 10;
const int HEATE = 9;
const int LIGHT = 8;
#define pirPin 7
// Create variables:
int val = 0;
bool motionState = false; // We start with no motion detected.
#include <Wire.h>
#define currentPin A0
float multiplier =0.185; //Sensibility in Voltios/Ampers for the 5A model
float SensorRead;
float CurrentSensorRead;
float difference;
float currentValue;
float previousValue;
void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode (FRID, OUTPUT);
pinMode (OUTL, OUTPUT);
pinMode (HEATE, OUTPUT);
pinMode (WM, OUTPUT);
pinMode (LIGHT, OUTPUT);
pinMode(currentPin, INPUT);
}
void loop()
{
read_data(); //read data from inputs
manage_devices();
}
void read_data(void) {
SensorRead= analogRead(currentPin);
val=digitalRead(pirPin);
}
void comparing_data(void) {
currentValue = SensorRead;
difference = currentValue - previousValue;
Serial.println(difference);
previousValue = currentValue;
delay(5000);
}
void manage_devices(void) {
if (difference<=0){
digitalWrite(FRID, HIGH);
digitalWrite(OUTL, LOW);
delay(3600);
digitalWrite(OUTL, HIGH);
digitalWrite(HEATE, LOW);
delay(3600);
digitalWrite(HEATE, HIGH);
digitalWrite(WM, LOW);
delay(3600);
digitalWrite(WM, HIGH);
digitalWrite(LIGHT, LOW);
delay(3600);
digitalWrite(LIGHT, HIGH);
}
else if (val=0){
digitalWrite(LIGHT, LOW);
}
else if (val=1){
digitalWrite(WM, HIGH);
}
}