App Inventor + Iot: Temperature Sensor
App Inventor + Iot: Temperature Sensor
min
This tutorial will help you connect App Inventor + IoT with a temperature sensor
on an Arduino 101 controller. We are also using a Seeed Grove shield for this
tutorial. You do not need to use this board, but it does make things easier. The
temperature sensor we recommend is the Grove temperature & humidity sensor.
Before you start you should first complete the App Inventor + IoT Setup tutorial to
set up your Arduino device.
The remaining steps all build off of the the starter code for Basic Connection
tutorial and .aia:
● Drag a Label from the User Interface Palette and drop it between
LabelStatus and ListBLE
○ Rename the Label "LabelData".
○ Change its text to “Data: “.
Next, we need to store the data we receive from the sensor. From the Variables
drawer in the docs pane, drag an initialize global name to block and name it
"Temperature". From the Math drawer add a number block and set it to "0". We'll
use this to keep track of the sensor value.
Let's make a new procedure to display the current readings in the LabelData
when we get new data. You can create a procedure by dragging out a purple
procedure block from the Procedures drawer in the Blocks pane. Let's rename it
updateDataLabel.
○ from LabelData in the Blocks pane, add set LabelData.Text to.
○ from the Text drawer connect a join block.
■ From the Text drawer, connect a text block and type
"Temperature: "
■ From the Variables drawer connect a get global Temperature.
○
Finally, we need to call the procedure when this data is received.
● From the Arduino101Humidity1 drawer in the Blocks pane, drag
when Ardunio101Humidity1.TemperatureReceived
○ from the Variables drawer, add set global Temperature.
○ Hover over the orange "temperature" in .TemperatureReceived to see
the get temperature block. Drag the get temperature block from this
window and snap to set global Temperature.
○ from the Procedures drawer, add call updateDataLabel.
Your app should now be working! Connect your Arduino device using the MIT
AI2 Companion (if you haven't already). Test it out by closing your hand around
the sensor, or placing it under a lamp. If it is working, you should see the data
label change. If it is working, you should see the data label change (but probably
very slowly).