Joe HankinsJohn Bustle
Published

Annoying Fridge Alarm

Forgetful roommates who don't close the fridge? Worried about keeping your food (and drinks) thoroughly cooled? Then this device is for you!

BeginnerFull instructions provided144
Annoying Fridge Alarm

Things used in this project

Hardware components

Argon
Particle Argon
×2
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
DS18B20 Programmable Resolution 1-Wire Digital Thermometer
Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer
×1
Through Hole Resistor, 2 kohm
Through Hole Resistor, 2 kohm
×1
Adafruit Rotating LED buzzer alarm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Maker service
IFTTT Maker service

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Door Sensor Schematic

Temperature Sesnor Schematic

Code

Temperature Sensor

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <DS18B20.h>

// This #include statement was automatically added by the Particle IDE.
#include <DS18B20.h>

// This #include statement was automatically added by the Particle IDE.
#include <DS18B20.h>

#include <DS18B20.h>
#include <math.h>

const int      MAXRETRY          = 4;
const uint32_t msSAMPLE_INTERVAL = 2500;
const uint32_t msMETRIC_PUBLISH  = 10000;

const int16_t dsVCC  = D2;
const int16_t dsData = D3;
const int16_t dsGND  = D4;

// Sets Pin D3 as data pin and the only sensor on bus
DS18B20  ds18b20(dsData, true); 

char     szInfo[64];
double   celsius;
double   fahrenheit;
uint32_t msLastMetric;
uint32_t msLastSample;

void setup() {
  Serial.begin(115200);
  
  pinMode(dsGND, OUTPUT);
  digitalWrite(dsGND, LOW);
  pinMode(dsVCC, OUTPUT);
  digitalWrite(dsVCC, HIGH);

  delay(1000);
  Particle.subscribe("Fridge Status: OPEN", myHandler, "e00fce68623c330ea3b4fcc1");
}

void loop() {
  if (millis() - msLastSample >= msSAMPLE_INTERVAL){
    getTemp();
  }

  if (millis() - msLastMetric >= msMETRIC_PUBLISH){
    Serial.println("Publishing now.");
    publishData();
  }
}

void publishData(){
  sprintf(szInfo, "%2.2f", fahrenheit);
  Particle.publish("dsTmp", szInfo, PRIVATE);
  msLastMetric = millis();

}

void getTemp(){
  float _temp;
  String status;
  int   i = 0;

  do {
    _temp = ds18b20.getTemperature();
  } while (!ds18b20.crcCheck() && MAXRETRY > i++);

  if (i < MAXRETRY) {
    celsius = _temp;
    fahrenheit = ds18b20.convertToFahrenheit(_temp);
    Serial.println(fahrenheit);
  }
  else {
    celsius = fahrenheit = NAN;
    Serial.println("Invalid reading");
  }
  msLastSample = millis();
  if(fahrenheit >= 45)
  {
      status = "WARM";
      Particle.publish("WARM", status, PUBLIC);
  }
  else{}
}
void myHandler(const char *event, const char *data)
{
    Particle.publish(event, data, PRIVATE);
    
}

Door Sensor

C/C++
int switchPin = D0;
int writePin = D6;
int alarmPin = D7;
String status;

void fridgeAlarm();
void setup() {
    pinMode(switchPin, INPUT);
    pinMode(writePin, OUTPUT);
    pinMode(alarmPin, OUTPUT);
    Particle.subscribe("WARM", myHandler, "e00fce68391e3538c530f420");
}

void loop() {
delay(5000);
digitalWrite(writePin, HIGH);
digitalWrite(alarmPin, HIGH);

if (digitalRead(switchPin) == HIGH)
{
    delay(5000);
    status = "OPEN";
    Particle.publish("Fridge Status: OPEN", status, PRIVATE);
    while(digitalRead(switchPin) == HIGH)
    {
    digitalWrite(alarmPin, LOW);
    }
}
if (digitalRead(switchPin) == LOW)
{
    digitalWrite(alarmPin, HIGH);
}
else
{
}
}
void myHandler(const char *event, const char *data)
{
    Particle.publish(event, data, PRIVATE);
}

Credits

Joe Hankins

Joe Hankins

1 project • 0 followers
John Bustle

John Bustle

1 project • 1 follower

Comments

Add projectSign up / Login