Benjamin LopansriAndrew Santos
Published

MEGR 3171 Group 23 Butter Temp Sensor

A sensor that tells me and my friend when my roommates are using my butter

BeginnerFull instructions provided28
MEGR 3171 Group 23 Butter Temp Sensor

Things used in this project

Hardware components

Grove - Temperature Sensor
Seeed Grove - Temperature Sensor
×1
Grove – Chainable RGB Led V2.0
Seeed Grove – Chainable RGB Led V2.0
×1
Grove 4-Digit Display
×1
Argon
Particle Argon
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Butter Temperature Graph

Receiver

Butter Sensor

Code

Butter Sensor Code

C/C++
This sensor was responsible for sensing the temperature of the butter, sending pings to the other argon, receiving the instructions and determining if the temp is too high or too low. It then sends instructions to the other argon to add a number to the 4-digit display to see how long the butter was out. To use this code, change the T variable in the global variables to just above the refrigerator temperature value and place the sensor on the stick of butter.
// This #include statement was automatically added by the Particle IDE.
#include <Grove_Temperature_And_Humidity_Sensor.h>

DHT dht(D2);

float temp, humidity;
double temp_dbl, humidity_dbl;
float T = 50;

void setup() {
Serial.begin(9600);

dht.begin();

Particle.variable("temp", temp_dbl);
Particle.variable("humidity", humidity_dbl);

Particle.subscribe("start", start, MY_DEVICES);
Particle.subscribe("stop", stop, MY_DEVICES);
}

void loop() 
{
    temp = dht.getTempFarenheit();
    humidity = dht.getHumidity();
    temp_dbl = temp;
    humidity_dbl = humidity;
    
    if (temp < 1)
    {
    	Serial.println("Failed to read from DHT11 sensor!");
    }
    
    else
    {
    Serial.printlnf("Temp: %f", temp);
    Serial.printlnf("Humidity: %f", humidity);
    
    String temp_string = String(temp);
    String humidity_string = String(humidity);
    
    Particle.publish("temp", temp_string, PRIVATE);
    Particle.publish("humidity", humidity_string, PRIVATE);
    Particle.publish("ping", PRIVATE);
    delay(10000);
    }
}


void start(const char*event, const char*data)
{
    
    temp = dht.getTempFarenheit();
    humidity = dht.getHumidity();
    temp_dbl = temp;
    
    if (temp > T)
    {
        Particle.publish("toggleLight", PRIVATE);
       
    }
    
    delay(10000);
}

void stop(const char*event, const char*data)
{
    temp = dht.getTempFarenheit();
    humidity = dht.getHumidity();
    temp_dbl = temp;
    humidity_dbl = humidity;
    
    if((temp > T)) {
    Particle.publish("Vadd", PRIVATE);
    Particle.publish("RED", PRIVATE);

    if (temp < T){
        Particle.publish("untoggleLight", PRIVATE);

    }

    }
    delay(10000);
}

Butter Alerter Code

C/C++
This code gets hooked up to the reciever and counts the amount of time the butter is out of the fridge. The LED flashes every ping from the sensor, and delivers instructions back to the butter sensor to see what the temperature is on the butter. This sensor should be watched passively to see when the butter has been tampered with.
// This #include statement was automatically added by the Particle IDE.
#include <Grove_4Digit_Display.h>

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

ChainableLED leds(D2, D3, 1);
#define CLK D4
#define DIO D5
TM1637 tm1637(CLK, DIO);

int Number = 0;

int toggleLed(String args) 
{
leds.setColorHSB(0, 0.0, 0.5, 1.0);
delay(500);

leds.setColorHSB(0, 0.0, 0.0, 0.0);
delay(500);


return 1;
}


void setup() 
{
    
    leds.init();
    leds.setColorHSB(0, 0.0, 0.0, 0.0);
    
    tm1637.init();
    tm1637.set(BRIGHT_TYPICAL);
    
    Particle.subscribe("toggleLight", toggleLight, MY_DEVICES);
    Particle.subscribe("untoggleLight", untoggleLight, MY_DEVICES);
    Particle.subscribe("Vadd", Vadd, MY_DEVICES);
    Particle.subscribe("ping", ping, MY_DEVICES);
    Particle.subscribe("RED", RED, MY_DEVICES);

}



void loop() 
{

}

void ping(const char*event, const char*data)
{
    toggleLed("");
    delay(1000);
    leds.setColorHSB(0, 0.0, 0.0, 0.0);
    delay(100);
    Particle.publish("start", PRIVATE);
}

void RED(const char*event, const char*data)
{
    leds.setColorHSB(1, 0.0, 1.0, 0.5);
}
void toggleLight(const char*event, const char*data)  
{
    toggleLed("");
    Particle.publish("stop", PRIVATE);
}

void Vadd(const char*event, const char*data)
{
    int B;
    B = Number + 1;
    tm1637.display(0,B);
    Number = B;
}   

void untoggleLight(const char*event, const char*data)  {
    leds.setColorHSB(0, 0.0, 0.0, 0.0);
    Particle.publish("start", PRIVATE);
}

Credits

Benjamin Lopansri

Benjamin Lopansri

1 project • 1 follower
Andrew Santos

Andrew Santos

0 projects • 0 followers

Comments

Add projectSign up / Login