Kenta CasagrandeWill Troxell
Published

MEGR 3171 Popcorn Monitor

Want to know how long you've got once you've popped a fresh bag of popcorn before it gets soggy and cold? Now you'll know!

BeginnerWork in progress5 hours88
MEGR 3171 Popcorn Monitor

Things used in this project

Hardware components

Argon
Particle Argon
×2
Grove Shield for micro:bit v2.0
Seeed Studio Grove Shield for micro:bit v2.0
×1
Breadboard (generic)
Breadboard (generic)
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×2
Grove – Button(p)
Seeed Studio Grove – Button(p)
×1
Jumper wires (generic)
Jumper wires (generic)
×19
Battery, 3.7 V
Battery, 3.7 V
×1

Software apps and online services

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

Story

Read more

Schematics

Popcorn Data Collector

To begin data collection, plant the DHT11 inside of the bag of popcorn and then hit the switch to begin collecting data!

Ambient Data Collector

To begin data collection, place the whole circuit in a control environment and hit the switch to begin data collection.

Code

Popcorn Data Collection Code

C/C++
#include <Grove_Temperature_And_Humidity_Sensor.h>

#include <ThingSpeak.h>

//An example of DHT11 for PHOTON

#define DHTPIN  D2     // set pin

TCPClient client;

unsigned long myChannelNumber = 2104394;    // change this to your channel number
const char * myWriteAPIKey = "RODMICSZJO6WF0YK"; // change this to your channels write API key

unsigned long previousMillis = 0;

DHT dht1(DHTPIN);

// Initialize Grove Button on digital pin D4
const int BUTTON_PIN = D4;

// Initialize variables to track the state of the button
bool buttonState = LOW;
bool lastButtonState = LOW;
bool isOn = false;

// Set the interval for taking readings
const unsigned long INTERVAL = 500; // in milliseconds

// Set the interval for printing readings
const unsigned long PRINT_INTERVAL = 5000; // in milliseconds
unsigned long lastPrintTime = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("DHT11 Begin!!!");
  ThingSpeak.begin(client);
  pinMode(BUTTON_PIN, INPUT_PULLUP);

/////////
Particle.subscribe("A_Humidity", myHandler);
Particle.subscribe("A_Temp", myHandler);
/////////

}

void loop() {
  // Read the button state
  buttonState = digitalRead(BUTTON_PIN);

  // Check if the button state has changed
  if (buttonState != lastButtonState) {
    // If the button is pressed, toggle the state of isOn
    if (buttonState == LOW) {
      isOn = !isOn;
    }
    // Delay for debounce
    delay(50);
  }

  // Save the current button state for comparison
  lastButtonState = buttonState;

  // If the code is on, take and print readings
  if (isOn) {
    // Check if it's time to take a reading
    if (millis() - lastPrintTime >= INTERVAL) {
      //Read Humidity
      float h = dht1.getHumidity();
      // Read temperature as Celsius
      float t = dht1.getTempCelcius();
      // Read temperature as Farenheit
      float f = dht1.getTempFarenheit();

      Serial.print("Humid: ");
      Serial.print(h);
      Serial.println("%  ");
      Serial.print("Temp: ");
      Serial.print(t);
      Serial.println("*C ");
      Serial.print("Temp: ");
      Serial.print(f);
      Serial.println("*F ");
      Serial.println();

      String Humidity = "{" + String(h) + "}";

      String Temp = "{" + String(f) + "}";

      Particle.publish("Temp", Temp);

      Particle.publish("Humidity", Humidity);

      ThingSpeak.setField(1,String(h));
      ThingSpeak.setField(2,String(f));

////////
void myHandler(const char A_Humidity, const char data)
{
ThingSpeak.setField(3,data);
}

void myHandler(const char A_Temp, const char data)
{
ThingSpeak.setField(4,data);
}
////////

      // Update the last print time
      lastPrintTime = millis();

      // Write to ThingSpeak, field 1, immediately
      ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

      delay(15000); // ThingSpeak will only accept updates every 15 seconds.
    }
  }
  else {
    // If the code is off, reset the last print time
    lastPrintTime = millis();
  }
}

Ambient Data Collection

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

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

//An example of DHT11 for ARGON

#define DHTPIN  D2     // set pin

TCPClient client;

unsigned long myChannelNumber = 2112283;    // change this to your channel number
const char * myWriteAPIKey = "HOLN2M104BOAPV74"; // change this to your channels write API key

unsigned long previousMillis = 0;

DHT dht1(DHTPIN);

// Initialize Grove Button on digital pin D4
const int BUTTON_PIN = D4;

// Initialize variables to track the state of the button
bool buttonState = LOW;
bool lastButtonState = LOW;
bool isOn = false;

// Set the interval for taking readings
const unsigned long INTERVAL = 500; // in milliseconds

// Set the interval for printing readings
const unsigned long PRINT_INTERVAL = 5000; // in milliseconds
unsigned long lastPrintTime = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("DHT11 Begin!!!");
  ThingSpeak.begin(client);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  // Read the button state
  buttonState = digitalRead(BUTTON_PIN);

  // Check if the button state has changed
  if (buttonState != lastButtonState) {
    // If the button is pressed, toggle the state of isOn
    if (buttonState == LOW) {
      isOn = !isOn;
    }
    // Delay for debounce
    delay(50);
  }

  // Save the current button state for comparison
  lastButtonState = buttonState;

  // If the code is on, take and print readings
  if (isOn) {
    // Check if it's time to take a reading
    if (millis() - lastPrintTime >= INTERVAL) {
      //Read Humidity
      float h = dht1.getHumidity();
      // Read temperature as Celsius
      float t = dht1.getTempCelcius();
      // Read temperature as Farenheit
      float f = dht1.getTempFarenheit();

      Serial.print("Humid: ");
      Serial.print(h);
      Serial.println("%  ");
      Serial.print("Temp: ");
      Serial.print(t);
      Serial.println("*C ");
      Serial.print("Temp: ");
      Serial.print(f);
      Serial.println("*F ");
      Serial.println();

      String Humidity = "{" + String(h) + "}";

      String Temp = "{" + String(f) + "}";

      Particle.publish("Temp", Temp);

      Particle.publish("Humidity", Humidity);

      ThingSpeak.setField(1,String(h));
      ThingSpeak.setField(2,String(f));
////////
void myHandler(const char A_Humidity, const char data)
{
ThingSpeak.setField(1,data);
}

void myHandler(const char A_Temp, const char data)
{
ThingSpeak.setField(2,data);
}
////////
      // Update the last print time
      lastPrintTime = millis();

      // Write to ThingSpeak, field 1, immediately
      ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

      delay(15000); // ThingSpeak will only accept updates every 15 seconds.
    }
  }
  else {
    // If the code is off, reset the last print time
    lastPrintTime = millis();
  }
}

Credits

Kenta Casagrande

Kenta Casagrande

1 project • 2 followers
Will Troxell

Will Troxell

1 project • 1 follower

Comments