Maria AdkinsHaleigh Grose
Published © GPL3+

MEGR 3171 Lunch Bag Temperature Sensor

With our internet-connected device, you will know if your lunch is safe to eat!

IntermediateFull instructions provided5 hours384
MEGR 3171 Lunch Bag Temperature Sensor

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×2
ELEGOO 37-in-1 Sensor Module Kit V1.0
ELEGOO 37-in-1 Sensor Module Kit V1.0
×1
Argon
Particle Argon
×2
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Schematics of Argon Circuits

Maria's Argon

Haleigh's Argon

Code

Maria's Argon Code

C/C++
This code publishes an event to Haleigh's Argon and subscribes to an event from Haleigh's Argon.
// Maria's Argon Code//

double temperature = 0; // Initalize variable for the temperature data coming f 
int pinvalue = 0; //Initalize variable for the pin input from the temperature sensor

int lunchtemp;

void setup()

{
  
  pinMode(A0, INPUT); // Get input from this pin
  pinMode(D7, OUTPUT); // Set D7 as output
  Particle.subscribe("unsafe", safety, MY_DEVICES); // Subscribe to Haleigh's Particle

 }


    void loop()
    { 
        
      delay(8000); // Delay the loop iterations for eight seconds
    
      pinvalue = analogRead(A0); // Get the value from the A0 pin
      
      temperature = (pinvalue*-.05+107); // Calibrate the input from the sensor 
      
      Particle.publish("temp", String(temperature), PRIVATE); // Publish Temperature data to Haleigh's Argon and Thingspeak
      
    }



void safety(const char *event, const char *data){
    
  String temp = data; // This takes data from the Subscribe and sets it to a new variable name
  
  int  lunchtemp = temp.toInt(); // Changes the string into an integer that the Argon can use
    
    if (lunchtemp < 11){ // Interact with the event being published by Haleigh's Argon. If numbers are less than 11, turn the D7 on
          digitalWrite(D7, HIGH); // Triggered when Haleigh's Particle notes that the lunch is at an unsafe temperature
      }
      else { //Otherwise, the light will be off
      digitalWrite(D7, LOW);
    }
  
 
}

Haleigh's Argon Code

C/C++
This code subscribes to an event from Maria's Argon and publishes an event to Maria's Argon.
// Haleigh's Argon code //

int temp1;// Initialize a varible for the temperature input from Maria's Argon

void setup() {
    pinMode(D7, OUTPUT); // Set the D7 as an output

    Particle.subscribe("temp", lunchbagtemp, MY_DEVICES); // Subscribe to Maria's Argon event
}
    

void loop() {
    
    if (temp1 <= 40){ //When the temperature is less than 40 degrees, everything is fine so no need to blink the light
       
    }
    
    else if (temp1 >= 41){ //If the temperature is greater than a food-safe temperature, the light comes on
    
        digitalWrite(D7, HIGH); // The light comes on if this is the case
        
        String safety = String(random(5,10)); // Create random numbers to create an event when the D7 light is on
        Particle.publish("unsafe", safety, PRIVATE); // Create a private event that publishes a random number when the light is on
        delay(3000); // Wait three seconds before sending a new event
        
    }
   

}

  void lunchbagtemp(const char *event, const char *data){
    
    String temp = data; // Change the variable data name
    
    temp1 = temp.toInt(); // Change the string into an integer that the Argon can use
 
}

Credits

Maria Adkins
1 project • 1 follower
Haleigh Grose
0 projects • 1 follower

Comments