Fun with Sensors
Putting the Pieces Together
Here is a diagram of how all the pieces connect:
And here's what the actual sensors look like:
Now that you know the parts involved, let's connect everything we'll need to the AWS IoT EduKit:
- Insert the wire on the GPS Unit into Port C on the EduKit as shown below.
- Insert the wires from the Encoder and the ENV III into the Grove Connector hub as shown.
- Insert the wire from the Grove Connector hub into Port A on the EduKit (keep in mind that Port A is next to the USB-C port and is the only port that is NOT labeled).
Setting Up Your Sensor Demo Project
- Create a Project with the
sensordemo
template, making sure to use a unique name for the Project that does not match any other Team member's:
iot project add --name=Sensor-{your name} --template=sensordemo
- List the components installed:
iot project list --name={project} --full
Pro Tip: Set the environment variable IOT_PROJECT
to the name of your project and you can leave out the --project={project}
in all subsequent commands. Check out Joining the Team to see how if you haven't already done so. We'll be doing this going forward!
On the Mac Terminal or iTerm:
export IOT_PROJECT="my-project"
On Windows Powershell:
$env:IOT_PROJECT="my-project"
- List the Model information:
iot model list --name=SensorDemoModel --full
Yet Another Pro Tip
You can also set the environment variable IOT_MODEL
to the name of your project and then leave out the --model=SensorDemoModel
in all subsequent commands. Again, check out Joining the Team to see how. We'll be doing this going forward as well.
On the Mac Terminal or iTerm:
export IOT_MODEL="SensorDemoModel"
On Windows Powershell:
$env:IOT_MODEL="SensorDemoModel"
- If you followed the two Pro Tips above, enter:
iot datatype list
If you didn't set the evironment variables, enter:
iot datatype list --project={project} --model=SensorDemoModel
- As detailed in the Hello World instructions, make sure your WiFi credentials are set appropriately:
On Windows:
$env:IOT_WIFI_SSID="{your ssid}"
$env:IOT_WIFI_PASSWORD="{your password}"
On Mac:
export IOT_WIFI_SSID="{your ssid}"
export IOT_WIFI_PASSWORD="{your password}"
- Add a device instance with a unique serial number of your choosing (assuming
IOT_PROJECT
andIOT_MODEL
environment variables were set):
iot device add --serial={unique serial number}
- Generate the code (note: names are case-sensitive).
iot firmware generate --serial={serial number} --name=sensordemo
(Optional) Expand the zip file that has been generated in your directory and inspect the contents that were generated.
The file will be named sensor-demo-m5-arduino-esp32.zip.
- With your EduKit connected to your computer via the USB-C cable, build and flash the firmware:
iot firmware flash --zip=sensor-demo-m5-arduino-esp32.zip
- Open the monitor in your terminal screen via:
iot device monitor --serial={serial}
- Wait until the device is connected to the cloud. Once connected, you should see data on the screen.
- Breathe on the ENV III sensor, and the humidity should go up as noted in the monitor.
Data is not sent unless it goes past a certain delta threshold. This is to avoid flooding your AWS Account with irrelevant or unnecessary sensor data.
Place the GPS Unit component (still attached to the EduKit, naturally) against a window to get a GPS signal. After a few minutes, you should see the EduKit screen icons change and will also see raw data that is being sent to the cloud displayed on your monitor.
Use CTRL-C to get out of your monitor.
Send a command from the console to your EduKit, as you did in Hello World example. Similar to that example, values can be red/green/blue/off, but this command changes the colors of the light bars on the side of the EduKit:
iot data set --project={project} --serial={serial} --name=color --value=red
Congratulations!!!
You have successfully mastered setting up and demonstrating the various sensors.
Cleanup
- To delete a single Device, enter:
iot device delete --project={project} --serial={serial}
- To delete the entire Project:
iot project delete --name={project}
3To confirm that the Project is gone:
iot project list
What you learned
- How to connect wired sensors to the EduKit.
- To generate code to communicate with sensors and send data securely to/from the cloud.
- To send environmental, location-based/GPS, and user-controlled (rotary knob) data to the cloud.
- How to send real-time commands from the cloud back to a hardware component (the LED bars).