Craig BlackwellRigo Marulanda
Published

MEGR 3171 IoT 2 Refrigerator Check

Learn how to monitor your refrigerator temperature. This allows users to protect the food against the heat.

BeginnerFull instructions provided12 hours3
MEGR 3171 IoT 2 Refrigerator Check

Things used in this project

Hardware components

Argon
Particle Argon
×2
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Resistor 100 ohm
Resistor 100 ohm
×2
Jumper wires (generic)
Jumper wires (generic)
×14
Breadboard (generic)
Breadboard (generic)
×2
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Resistor 330 ohm
Resistor 330 ohm
×2
LED (generic)
LED (generic)
×2
Resistor 220 ohm
Resistor 220 ohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Adafruit IO

Story

Read more

Schematics

Ultrasonic Distance Sensor Wiring Diagram

The schematic view of the Ultrasonic Sensor, Argon, Voltage Divider, and LED. The LED circuit had a 330 ohm resistor added to regulate voltage.

Ultrasonic Sensor with Argon and LED

HC-SR04:
Trigger is connected to D4
Echo is connected to D5 a Voltage Divider was created at the Echo pin with 2 100 Ohm resistors placed in series to provide the correct voltage reading to the Argon
VCC is connected to Main Power on breadboard and to USBV for 5V
GND is connected to GND on breadboard and GND pin on Argon

DHT-11 Temperature Sensor

Circuit Diagram: The particle Argon is connected to the computer as a power source. It powers the circuit through 3.3 volts. The resistor (220 Ohms) is content in series with the LED. The DHT-11 sensor is connected to 3.3v as a power source and the D2 pin as an output. All components are connected to a ground line.

Code

Ultrasonic Distance Sensor

C/C++
Activating this code calculates distance based on the sound waves emitted by the ultrasonic sensor. If the sensor reads out of range or within 6 inches, it returns a value of 0. This value indicates that an individual is not within range of the refrigerator. If the distance is recorded in the correct range, Verify is published. This notifies the Argon with the temperature sensor to report its temperature to this Argon. When doing this, it activates the LED connected to pin D7. This notifies the user that the temperature reading is requested so that one can know the temperature inside of the refrigerator. The distance reading is also sent to io.adafruit and graphed over time.
// This #include statement was automatically added by the Particle IDE.
#include <HC_SR04.h>

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



double cm = 0.0;
double inches = 0.0;

int trigPin = D4;
int echoPin = D5;
int receivedinteger = 0;
int led = D7;
int readings = 0;
/*
Connect an HC-SR04 Range finder as follows:
Spark   HC-SR04
GND     GND
5V      VCC
D4      Trig
D5      Voltage divider output - see below

Echo --|
       >
       < 470 ohm resistor
       >
       ------ D5 on Spark
       >
       < 470 ohm resistor
       >
GND ---|

Test it using curl like this:
curl https://api.spark.io/v1/devices/<deviceid>/cm?access_token=<accesstoken>

The default usable rangefinder is 10cm to 250cm. Outside of that range -1 is returned as the distance.

You can change this range by supplying two extra parameters to the constructor of minCM and maxCM, like this:

HC_SR04 rangefinder = HC_SR04(trigPin, echoPin, 5.0, 300.0);

*/

HC_SR04 rangefinder = HC_SR04(trigPin, echoPin);
//receivedfloat = String(data).toFloat();



void setup() 
{
    //Particle.publish("")
    Spark.variable("cm", &cm, DOUBLE);
    Spark.variable("inches", &inches, DOUBLE);
    //Particle.subscribe("Craigs_Distance", Craigs_Distance_Handler);
    pinMode(led, OUTPUT);
    digitalWrite(led, LOW);
    Particle.subscribe("readings", temp);
}

void loop() 
{



    cm = rangefinder.getDistanceCM();
    inches = rangefinder.getDistanceInch();
    delay(100);
    
    
    
    //Particle.publish("reading", String::format("%4.2f", inches));
    
    if (inches >= 6 && inches != -1){
        Particle.publish("Verify", String::format("%4.2f", inches));
        }
        else{
            Particle.publish("Craigs_Distance","0", PUBLIC);
        }
        
        //Particle.publish("Craigs_Distance", String(inches), PUBLIC);
    
    delay(1000);
}

void temp(const char *event, const char *data){
    readings = atoi(data);
    if (readings>=0){
    digitalWrite(led, HIGH);
    delay(500);
    digitalWrite(led, LOW);
    delay(500);
    }
    else{
        }
}
        //Particle.publish("Subscribed_Data", receivedfloat);
    
   // receivedinteger = String(data).toInt();
    //Particle.publish("YES", "%4d", receivedinteger);

DHT-11 Temperature Sensor

C/C++
This code activates an Adafruit DHT-11, a thermometer, and a humidity sensor. The part for the humidity sensor was deleted. This sensor would be located inside the refrigerator and measures the inside temperature of this. The measurements would be sent to the Particle console and to Particle #1. Each time Particle #2 sends data to Particle #1, the LED blinks every 4 seconds. The pin used for it is D7, the same as when Particle #2 receives data from Particle#1. It is connected to Adafruit IO through Webhooks to send the data and get some graphs with the values measured.
#include <ThingSpeak.h>

#include <Adafruit_IO_Particle.h>

#include "Adafruit_DHT_Particle.h"

#define DHTPIN D2   

#define DHTTYPE DHT11		


DHT dht(DHTPIN, DHTTYPE);
int loopCount;
int i = 0;
int led = D7;
void setup() {
    Particle.subscribe("Verify", Craigs_Distance_Handler);
	Serial.begin(9600); 
	Serial.println("DHTxx test!");
	Particle.publish("state", "DHTxx test start");

	dht.begin();
	loopCount = 0;
	delay(2000);
	
	
    pinMode(led, OUTPUT);
    digitalWrite(led, LOW);
    
}
void loop() {
    digitalWrite(led, HIGH);
    Particle.publish("Temp", "HOLA", PUBLIC);
    delay(300);
    digitalWrite(led, LOW);
    delay(4000);

	float h = dht.getHumidity();
	float t = dht.getTempCelcius();
	float f = dht.getTempFarenheit();
  
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}


	float hi = dht.getHeatIndex();
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();


	Serial.print("Temp: "); 
	Serial.print(t);
	Serial.print("*C ");
	
	Serial.println(Time.timeStr());
	//String timeStamp = Time.timeStr();
	Particle.publish("readings", String::format("%4.2f", t));
	delay(20000);
	

	
   
}

SerialLogHandler logHandler; 
void Craigs_Distance_Handler(const char *event, const char *data) {
    int distance = atoi(data);
    if (distance == 0) {
        digitalWrite(led, HIGH);
    } else {
        digitalWrite(led, LOW);
    }
}

Credits

Craig Blackwell

Craig Blackwell

0 projects • 0 followers
Rigo Marulanda

Rigo Marulanda

0 projects • 0 followers

Comments

Add projectSign up / Login