David Proano
Published

IOT Temperature Sensor

In this project 2 Particle argon were used in order to communicate to each other and be able to accurately read temperature and display data

BeginnerFull instructions provided566
IOT Temperature Sensor

Things used in this project

Hardware components

Argon
Particle Argon
×1
ELEGOO Upgraded 37 in 1 Sensor Modules Kit V2.0
ELEGOO Upgraded 37 in 1 Sensor Modules Kit V2.0
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

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

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

Light Sensor Argon

Temperature sensor argon

Light Sensor Argon

Temperature sensor argon

Code

Temperaure

C/C++
This code is used to read temperature data and also to send data to think speak to create graphs.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>



int analogvalue = 0;
int temp_f;
TCPClient client;

unsigned long myChannelNumber = 1574559;
const char * myWriteAPIKey = "VRFK6KC0JT3ZWCNG";

void setup(){

  ThingSpeak.begin(client);
  
  Particle.variable("analogvalue", analogvalue);
  Particle.variable("temp_f", temp_f);
 
Serial.begin(9600);

  pinMode(A0, INPUT);
}

void loop()
{
    delay(1500);
  // Read the analog value of the sensor (TMP36)
  analogvalue = analogRead(A0);
  //Convert the reading into degree 
  temp_f = (analogvalue*-.08099688473520249+151.99688473520249); //To be accurate
  //temp = 69;
  
  
  Particle.publish("temperature",String (temp_f), ALL_DEVICES);// sends data to cloud
  ThingSpeak.setField(1,temp_f);
  Serial.print(temp_f);
  Serial.println("temp_f");
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);

}

Light Sensor

C/C++
This code is used to receive data from could and command a light to turn on.
//Sets pin D7 as the power toggle pin
const int tog = D7;

//initializes temperature
int temperature_f;
int Light_Position;

void setup() {
    pinMode(tog, OUTPUT);
    //The relay is wired as normally closed and is non-latching so that if the photon loses power the light will remain on, setting the pin value to high defaults the light to the off position by opening the relay circuit.
    digitalWrite(tog, HIGH);

    //Subscribes the device to the  temperature data coming from the first photon and send it to the temperature handler function
    Particle.subscribe("TempSensor", temperatureHandler, ALL_DEVICES);
    //Compares the temperature value pulled from the cloud to the values set by the user to prevent the well from freezing
}
void loop() {
    if (temperature_f >= 60){
        //At a temperature greater than 60 degrees F it opens the circuit and turns off the light
        digitalWrite(tog, LOW), Light_Position = 0;
    }
    else if (temperature_f <= 55){
        //At temperatures lower than 55 degrees F it will close the circuit and turn on the light
        digitalWrite(tog, HIGH), Light_Position = 1;
    }
    else{
        //Reading any temperature in the "deadzone" restarts the loop
    }
    Particle.publish("Light", String(Light_Position), PUBLIC);
    delay(4000);
}   

//Takes the string data retrieved from the cloud and converts it to an integer for comparison

void temperatureHandler(const char *event, const char *data){
    //sets a new string, which i have defined as "pew" to take in the temperature data
    String pew = data;
    //Converts this new string "pew" into the previously defined integer "temperature"
    temp_f = pew.toInt();
}

Credits

Team 52

Posted by David Proano
Thanks to David Proano and Alex Juzwick.

Comments