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.
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
A quick tutorial for installing the plugin can be found Here
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
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 CloudWith 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 codeStep 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 ResultOn 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.
Comments