Georgio Harmouchtrentisokwithv8
Published

3171 Refrigerator Door Sensor

This is a very simple photosensor-based system that alerts the user when the refrigerator door is left open.

BeginnerWork in progress5 hours178
3171 Refrigerator Door Sensor

Things used in this project

Hardware components

Argon
Particle Argon
×2
Photo resistor
Photo resistor
×1
LED (generic)
LED (generic)
×2
Resistor 220 ohm
Resistor 220 ohm
×4
Buzzer
Buzzer
×1
Pushbutton Switch, Momentary
Pushbutton Switch, Momentary
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

3171 Simple Schematics

This is how the system was tested using one Particle Argon board. This was the earliest, fully functioning prototype of the photoresistor Refrigerator Sensor.

Code

3171_MEGR

C/C++
This is the code that was used to test the early, single Argon Particle board system
int led1 = A4; 
//DEFINED LED 1 LOCATION AS A5
int led2 = D7;
//TURNED ON THE ONBOARD LED AS WELL D7 FOR VALIDATION OF RESULTS
int photoresistor = A0;
//DEFINED VALUE FOR PHOTORESISTOR
int analogValue;
//DECLARED A VALUE FOR THE ANALOG VALUE WE WILL RETRIEVE FROM THE PHOTORESISTOR
void setup() {

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(photoresistor, INPUT);
//DEFINED ALL THE OUTPUTS AND INPUTS AND THEIR RESPECTIVE PINOUTS  

}

void loop() {
 
 analogValue = analogRead(photoresistor);
//"80" IS AN ARBITRARY VALUE THAT WAS USED TO CALIBRATE THE SENSOR FOR AMBIENT LIGHT CONDITIONS
if (analogValue < 80){
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
}else{
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
}
}
//INFINITE LOOP TO RUN THE ANALOG VALUE TEST. IF ANALOG PHOTORESISTOR VALUE IS RETRIEVED AND IS BELOW AN ARBITRARY VALUE, LED WILL NOT TURN ON, ELSE, TURN ON LED (IF GREATER THAN DEFINED ARBITRARY VALUE)

Publish/Fridge Argon 3171_MEGR

C/C++
This code includes the Publish feature that is used in the 2 Argon Particle board system. It is based on the 1 Argon Particle board system.
int led1 = A4; 
//DEFINED LED 1 LOCATION AS A4
int led2 = D7;
//TURNED ON THE ONBOARD LED AS WELL D7 FOR VALIDATION OF RESULTS
int photoresistor = A0;
//DEFINED VALUE FOR PHOTORESISTOR
int analogValue;
//DECLARED A VALUE FOR THE ANALOG VALUE WE WILL RETRIEVE FROM THE PHOTORESISTOR
int FridgeCount;
//Defaults Fridge Count to 0
bool buzz = D10;
//Buzzer control

void setup() {

    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(photoresistor, INPUT);
//DEFINED ALL THE OUTPUTS AND INPUTS AND THEIR RESPECTIVE PINOUTS  
    Particle.subscribe("buzz", buzz, MY_DEVICES);

}

void loop() {
 
 analogValue = analogRead(photoresistor);
//"80" IS AN ARBITRARY VALUE THAT WAS USED TO CALIBRATE THE SENSOR FOR AMBIENT LIGHT CONDITIONS
if (analogValue < 50){
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    
    String FridgeCount = String(0);
    Particle.publish("FridgeCount", FridgeCount, PRIVATE);
    
    delay(5000);

}else{
    digitalWrite(led2, HIGH);
    digitalWrite(led1, HIGH);
    
    Particle.publish("toggle-led", PRIVATE);
    String FridgeCount = String(1);
    Particle.publish("FridgeCount", FridgeCount, PRIVATE);
    
    delay(500);
    digitalWrite(led1, LOW);
    
    delay(4500);
}
}
//INFINITE LOOP TO RUN THE ANALOG VALUE TEST. IF ANALOG PHOTORESISTOR VALUE IS RETRIEVED AND IS BELOW AN ARBITRARY VALUE, LED WILL NOT TURN ON, ELSE, TURN ON LED (IF GREATER THAN DEFINED ARBITRARY VALUE)

void buzz(const char *event, const char *data) {
    digitalWrite(D10, HIGH);
    delay(500);
    digitalWrite(D10, LOW);
    delay(500);
}

Subscribe/Desk Argon 3171_MEGR

C/C++
This code includes the Subscribe feature that is used in the 2 Argon Particle board system.
void setup() {
    pinMode(D7, OUTPUT);
    pinMode(A1, OUTPUT);
    Particle.subscribe("toggle-led", toggleLed, MY_DEVICES);
}

void loop() {

}

void toggleLed(const char *event, const char *data) {
    digitalWrite(D7, HIGH);
    digitalWrite(A1, HIGH);    
    delay(500);
    digitalWrite(D7, LOW);
    digitalWrite(A1, LOW);    
    delay(500);
}

Test Publish

C/C++
This is the test script for the 2 Argon Particle board system. It is not used in the final design however. This was the script that was used to test the Publish feature.
void setup() {

}

void loop() {
    digitalWrite(D7, HIGH);
    
    Particle.publish("toggle-led", PRIVATE);
    
    delay(300);
    digitalWrite(D7, LOW);
    
    delay(3000);

}

Test Subscribe

C/C++
This is the test script for the 2 Argon Particle board system. It is not used in the final design however. This was the script that was used to test the Subscribe feature.
void setup() {
    pinMode(D7, OUTPUT);
    Particle.subscribe("toggle-led", toggleLed, MY_DEVICES);
}

void loop() {

}

void toggleLed(const char *event, const char *data) {
    digitalWrite(D7, HIGH);
    delay(500);
    digitalWrite(D7, LOW);
    delay(500);
}

Credits

Georgio Harmouch

Georgio Harmouch

1 project • 0 followers
trentisokwithv8

trentisokwithv8

1 project • 0 followers

Comments

Add projectSign up / Login