Alex RamosErik RathkeSean Lusk
Published

MEGR 3171 Temperature Control Project

Temperature Tracking

IntermediateFull instructions provided20
MEGR 3171 Temperature Control Project

Things used in this project

Hardware components

Push Button Sensor
×1
Argon
Particle Argon
×3
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Breadboard (generic)
Breadboard (generic)
×3
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×3
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Argon 3 Schematic

Argon 2 Schematic

Argon 1 Schematic

Argon 1 Photo

Argon 3 Photo

Code

Temperature Sensor

C/C++
#include "Adafruit_DHT.h"

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#define DHTPIN 5     // what pin we're connected to D5

// Uncomment whatever type you're using!
#define DHTTYPE DHT11		// DHT 11 
//define DHTTYPE DHT22		// DHT 22 (AM2302)
//#define DHTTYPE DHT21		// DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
	Serial.begin(9600); 
	Serial.println("DHTxx test!");

	dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
	delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a 
// very slow sensor)
	float h = dht.getHumidity();
// Read temperature as Celsius
	float t = dht.getTempCelcius();
// Read temperature as Farenheit
	float f = dht.getTempFarenheit();
	
	Particle.publish("TEMPERATURE",String(f));
	
	delay(10000);
  
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		Particle.publish ("ERROR","DHT 11 READ FAILURE");
		return;
	}
    delay(10000);
// Compute heat index
// Must send in temp in Fahrenheit!
	float hi = dht.getHeatIndex();
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();

	Serial.print("Humid: "); 
	Serial.print(h);
	Serial.print("% - ");
	Serial.print("Temp: "); 
	Serial.print(t);
	Serial.print("*C ");
	Serial.print(f);
	Serial.print("*F ");
	Serial.print(k);
	Serial.print("*K - ");
	Serial.print("DewP: ");
	Serial.print(dp);
	Serial.print("*C - ");
	Serial.print("HeatI: ");
	Serial.print(hi);
	Serial.println("*C");
	Serial.println(Time.timeStr());
}

LCD and Button

C/C++
LiquidCrystal_I2C *lcd;

void setup() {
    /**
     * How this single line of code works:
     * 
     * the first parameter "temperature" subscribes to variable "temperature" from the temperature argon code. When you write
     * Particle.variable("temperature",....) the cloud now has a variable called "temperature". Here, you are "subscribing" or
     * tuning into that variable "temperature" whenever it is published to. So if your temperature argon publishes an update
     * to the "temperature" variable, this argon will respond via the second parameter 
     * 
     * the second parameter represents the function that is immediately called whenever the cloud variable "temperature" is 
     * published to. In this case, it should just print the temperature found to the LCD. So again, whenever the temperature
     * argon publishes an update to the "temperature" variable, this argon will execute the function called temperature.
     * Just make sure that all this project knows about all the argons to work.
     */
    Particle.subscribe("temperature", temperature); 
    lcd = new LiquidCrystal_I2C(0x27, 16, 2); // Initialize 16 column by 2 row LCD at default address of hex-27.
    lcd->init(); // Initialize (does magic).
    lcd->backlight(); // Startup the backlight.
    lcd->setCursor(0 ,1 ); // Print at beginning of bottom row.
    lcd->print("Temperature");
}

void loop() {
}

void temperature(const char *event, const char *data) {
    String message = "Temp: " + String(data);
    lcd->setCursor(0 ,1 ); 
    lcd->print(message); // Prints the temp at the beginning of the bottom row.
}

Credits

Alex Ramos

Alex Ramos

1 project • 0 followers
Erik Rathke

Erik Rathke

0 projects • 0 followers
Sean Lusk

Sean Lusk

0 projects • 0 followers

Comments

Add projectSign up / Login