Project tutorial
An IoT controlled temperature monitor (S1.3)

An IoT controlled temperature monitor (S1.3) © GPL3+

Use the Arduino IOT Cloud to set a temperature goal and switch a red and green LED on /off to represent

  • 1,994 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

Introduction:

In this hands on lab, you will build a temperature sensing device that simulates the turning off circuits when the desired temperature or (goal) is reached.

This is the third in a series of labs in the SMART Cities Program and introduces a simple application of the Internet of Things with the ability to sense and control.

Putting it together:

There are five parts to this tutorial:

  • Installing the Arduino Create plugin
  • Assembling the circuit
  • Setting up your board in the cloud
  • Setting up the IOT Cloud
  • Adding your code

Part 1 - Installing the Arduino Create plugin

A quick tutorial for installing the plugin can be found Here

Part 2 - Assembling the circuit

Using the below wiring diagram as a reference assemble your device

Note:

  • The temperature sensor (TMP36) is connected to pin A0
  • When inserting the Temperature sensor make sure that the flat side is facing towards you.
  • The Red LED is connected to pin 0
  • The Green LED is connected to pin 1

Part 3 - Setting up your board in the cloud

To configure your board navigate to Arduino Create and complete the following steps (highlighted in orange)

You will now see your MKR1000 board listed and named "MyThing" as shown below (circled in orange)

This completes the registration of the board in the cloud

Part 4 - Setting up the IOT Cloud

With the device registered in the cloud navigate to Arduino Create and complete the following steps (highlighted in orange)

This completes the setup of the device in the Arduino IOT Cloud.

Part 5 - Adding your code

Step 1 -On line 18 enter the Temperature Sensor variables (Snippet 1)

// Temperature Sensor variables
int sensorPin = A0;      // Sets A0 as the input pin for the sensor
int sensorValue = 0;     // initialise a variable to store the value coming from thesensor
int Dres = 1024;         // set max 10-bit digital value
int VCC = 3300;          // set VCC voltage milliVolts
int offset = 500;        // set tolerance of 500 milliVolts
int scaling = 10;        // set the voltage scaling at 10mM / deg C
float voltage = 0.0;     // set the initial voltage to 0
int redPin = 0;          // set the output pin for the Red LED
int grnPin = 1;          // set the output pin for the Green LED 

Step 2 - On line 34 add the following setup functions (Snippet 2)

// Set 10bit read resolution
analogReadResolution(10);
 // Set theoutputPins for the LEDs
 pinMode(redPin,OUTPUT);
 pinMode(grnPin,OUTPUT);

Step 3 - On line 59 add the main code (Snippet 3)

  // Read the value from the sensor:
  sensorValue =analogRead(sensorPin);
  Serial.print("sensorValue = ");
 Serial.print(sensorValue);
  // Calculate the voltage
 voltage = sensorValue * (VCC/Dres); // milliVolts
 Serial.print(" voltage = ");
 Serial.print(voltage);
  Serial.print(" VCC = ");
 Serial.print(VCC);
  // Calculate the temperature
 temperature = (voltage - offset ) / scaling;
  Serial.print("temperature(C) = ");
  Serial.println(temperature);
 // If the temperature is < than the goal temperature then
 // Turn the Green LED on!
  if (temperature < setTemp) {
   digitalWrite(grnPin, HIGH);
    digitalWrite(redPin, LOW);
   }
  // If the temperature is >= than the goaltemperature then
  // Turn the Red LED on!    
  else {
   digitalWrite(grnPin, LOW);
    digitalWrite(redPin, HIGH);
 } 
  Serial.print(" Set temperature(C) = ");
 Serial.println(setTemp);

Step 4 - Navigate to the Secret tab, enter your Wifi Network Name and password

Step 5 - Save and Verify the code

Step 6 - Upload the code

You have now completed the coding of your device !!!

The Final Result

On completion the device allows for the setting of the Temperature (Set Temperature) on the Arduino IOT Cloud dashboard that triggers the Red LED if the temperature exceeds the goal set.

Code

Snippet 1Arduino
Temperature Sensor variables
// Temperature Sensor variables
int sensorPin = A0;       // Sets A0 as the input pin for the sensor
int sensorValue = 0;      // initialise a variable to store the value coming from the sensor
int Dres = 1024;          // set max 10-bit digital value
int VCC = 3300;           // set VCC voltage milliVolts
int offset = 500;         // set tolerance of 500 milliVolts
int scaling = 10;         // set the voltage scaling at 10mM / deg C
float voltage = 0.0;      // set the initial voltage to 0
int redPin = 0;           // set the output pin for the Red LED
int grnPin = 1;           // set the output pin for the Green LED 
Snippet 2Arduino
Board setup instructions
  // Set 10bit read resolution
  analogReadResolution(10);
  
  // Set the outputPins for the LEDs
  pinMode(redPin, OUTPUT);
  pinMode(grnPin, OUTPUT);
Snippet 3Arduino
Main program code
  // Read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.print("sensorValue = ");
  Serial.print(sensorValue);

  // Calculate the voltage
  voltage = sensorValue * (VCC/Dres); // milliVolts
  Serial.print(" voltage = ");
  Serial.print(voltage);

  Serial.print(" VCC = ");
  Serial.print(VCC);
  
  // Calculate the temperature
  temperature = (voltage - offset ) / scaling;
  Serial.print(" temperature(C) = ");
  Serial.println(temperature);

  // If the temperature is < than the goal temperature then
  // Turn the Green LED on!
  if (temperature < setTemp) {
    digitalWrite(grnPin, HIGH);
    digitalWrite(redPin, LOW);
    }
    
  // If the temperature is >= than the goal temperature then
  // Turn the Red LED on!    
  else {
    digitalWrite(grnPin, LOW);
    digitalWrite(redPin, HIGH);
  } 

  Serial.print(" Set temperature(C) = ");
  Serial.println(setTemp);
Project Repository
All project code

Schematics

Wiring diagram
Wiring cesvmc50oh

Comments

Similar projects you might like

Connecting to the Arduino IOT Cloud (S1.2)

Project tutorial by greg

  • 1,373 views
  • 0 comments
  • 2 respects

Portable Temperature Station

Project tutorial by Isaac100

  • 13,670 views
  • 10 comments
  • 42 respects

Anomaly Detection & Temperature Monitoring Using Bolt IoT

Project tutorial by ashish anand

  • 7,153 views
  • 2 comments
  • 24 respects

Portable Temperature Station V2: IOT Edition

Project tutorial by Isaac100

  • 4,888 views
  • 0 comments
  • 9 respects

Cayenne Temperature Monitor

by VinothKumar

  • 3,903 views
  • 0 comments
  • 5 respects

Home Temperature while you're on holiday ...

Project tutorial by Giovanni Gentile

  • 3,341 views
  • 1 comment
  • 2 respects
Add projectSign up / Login