Joseph WuoriMaxwell GeorgeNicholas Romero
Published

MEGR 3171 Temperature Sensor Project

Temperature sensor built for the MEGR 3171 IoT project

IntermediateShowcase (no instructions)579
MEGR 3171 Temperature Sensor Project

Things used in this project

Hardware components

Argon
Particle Argon
×3
Resistor 10k ohm
Resistor 10k ohm
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Jumper wires (generic)
Jumper wires (generic)
×18
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1

Software apps and online services

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

Story

Read more

Schematics

Temperature

Sensor Circuit

LED Circuit

Temperature Sensor

LED

Particle Argon

Humidity

Code

Back and Forth

C/C++
This code fulfills the two way communication requirements for the project
//Code Heavily Borrows from Professor MacAlpine's "useless machine" Code
int switchstate = 0; //a variable holding curr state
int lastswitchstate = 0; //prev star


int switchpin = D1; //input switch 
int ledpin = D7;  // We utilize the onboard LED

void setup() 
{
Particle.subscribe("GeorgeRomero", GeorgeRomeroRespond, MY_DEVICES); //when GeorgeRomero occurs in the cloud (viewable by console.particle.io) run the GeorgeRomeroRespond
pinMode(switchpin, INPUT_PULLUP);
pinMode(ledpin, OUTPUT);
}




void loop() {  //high freq loop
lastswitchstate = switchstate;  //puts prev switch state to current switch state
switchstate = digitalRead(D1);  //triggers when input goes from high to low 
if (switchstate == 0 && (lastswitchstate ==1)){ //if equal returns value of '1'
    Particle.publish("GeorgeRomero", PRIVATE);  //send the event to the particle cloud
    }

}

int GeorgeRomeroRespond(const char *topic, const char *data){ 
    digitalWrite(ledpin,HIGH); //blink the led for visual feedback
    digitalWrite(ledpin,LOW); //turn the led off
    delay(500);
}

Temperature Sensor

C/C++
This is the main code for the project. It is what allows the sensor to upload the data so it can be shown in Thingspeak.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

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

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

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

#define DHTPIN  4

// Define the type of sensor
#define DHTTYPE DHT11        // DHT 11 

DHT dht(DHTPIN, DHTTYPE);
bool humid = false;
TCPClient client;


unsigned long myChannelNumber = 915641;
const char * myWriteAPIKey = "O2JM9AHA7YJ0XT02";


void setup() {
    
    ThingSpeak.begin(client);
 Serial.begin(9600); 
 dht.begin();

}

void loop() {
    // Wait a few seconds between measurements.
    delay(3000);
    
    float h = dht.getHumidity();
    
    // Read temperature as Fahrenheit
    float t = dht.getTempFarenheit();
    

        Particle.publish("GeorgeRomero", String (t), PUBLIC);
        Particle.publish("GeorgeRomero", String (h), PUBLIC);

        ThingSpeak.setField(1,h);
        ThingSpeak.setField(2,t);
        ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 
  
  Serial.print(dht.getHumidity());
  Serial.println("h");
  Serial.print(dht.getTempFarenheit());
  Serial.println("t");
}

LCD Code

C/C++
This code is for the LCD Monitor. The purpose was to show the instantaneous temperature and humidity. The LCD stopped functioning partway through one of our tests.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

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

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

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

#define DHTPIN  4

// Define the type of sensor
#define DHTTYPE DHT11        // DHT 11 

DHT dht(DHTPIN, DHTTYPE);
bool humid = false;
TCPClient client;


unsigned long myChannelNumber = 915641;
const char * myWriteAPIKey = "O2JM9AHA7YJ0XT02";


void setup() {
    
    ThingSpeak.begin(client);
 Serial.begin(9600); 
 dht.begin();

}

void loop() {
    // Wait a few seconds between measurements.
    delay(3000);
    
    float h = dht.getHumidity();
    
    // Read temperature as Fahrenheit
    float t = dht.getTempFarenheit();
    

        Particle.publish("GeorgeRomero", String (t), PUBLIC);
        Particle.publish("GeorgeRomero", String (h), PUBLIC);

        ThingSpeak.setField(1,h);
        ThingSpeak.setField(2,t);
        ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 
  
  Serial.print(dht.getHumidity());
  Serial.println("h");
  Serial.print(dht.getTempFarenheit());
  Serial.println("t");
}

Credits

Joseph Wuori

Joseph Wuori

1 project • 0 followers
Maxwell George

Maxwell George

1 project • 0 followers
Nicholas Romero

Nicholas Romero

1 project • 0 followers

Comments