By Alexander Pettersson (ap222ju at Linneaus unniversity)
Overview of the project
This project is about how to make an IoT device that senses humidity and temperatarure using a DHT11 and the built in rgb-led and temperature sensor and also an external RGB-led to control just for fun with an arduino RP2040 connected to the arduino IoT cloud.
Approximated time: Depends on your level of experience, for me it took several hours but for someone with more experience it could take maybe just 2-3 hours.
My first thought of this project was to create a device for a greenhouse to read temperature and humidity. My first sketch of this device it included a soil moisture sensor to check when to water the plants, but since it is a time limited project I didnt have time to add that sensor.
So on how the device came out I can still check the temperature and the humidity in my greenhouse.
The project should give insights in basic concepts of IoT, sensors and programming. The device will create awareness of the environment in a greenhouse.
Hardware | Usage | Price |
---|---|---|
Arduino RP2040 | Microcontroller | 299 SEK |
Battery holder 3xAAA with switch | Powering for device | 19 SEK |
USB cable | For powering device and to upload code when commisioning | 39 SEK |
Jumper wires 30cm female/male | Connecting sensors | 29 SEK |
Jumper wires 30cm male/male | Connecting sensors | 29 SEK |
Resistor metal film 0.6W 1% 330ohm (330R) | Resistor for connecting RGB-led module | 3 SEK |
DHT11 Temperature and humidity sensor | Sensor to read temperature and humidity | 100 SEK |
RGB-led module | RGB-led | ca. 19 SEK (Included in sensor package) |
In the first sketch of this project I had choosen an heltec microcontroller for this project but due to the electonic components situation in the world the supplier were unable to provide this devices so I went with the arduino instead wich were one of the recomended microcontrollers.
IDE
To write and upload your code you need an IDE.
Arduino got thier own IDE simply called Arduino IDE. To install the IDE and to connect your device they have a really nice tutorial that you can follow here. If you are going to use the IoT cloud and dont want to test the sensor skip to Setting up Arduino cloud.
To test ot your DHT11 you need to install a couple of libraries for DHT and Unified sensors by following these steps:
Open the library handler.
Install the DHT sensor library
Install the Adafruit Unified Sensor library
4.Open up the example code for DHT sensors. (DHTtester)
In the first box you need to change to wich pin yor sensor i connected (in my example it is connected to pin 5). And you need to uncomment the DHT11 and delete/comment the DHT22 in the second box.
Upload your code and open the seriell monitor under tools or ctrl+shift+m.
The result should be something like this.
Setting up Arduino IoT cloud
I started out using the IDE 1.8.19 to connect my device and to test out my sensors. But because I wanted to use the Arduino IoT cloud I needed to connect my device to the cloud, which were very easy to do by just following this tutorial.
Unless you want to be able to read/write to more then five variables you can use the free version of the cloud.
To make the same setup as I did you need to setup your variables as following picture:
And under network (down to the right) you need to put in your ssid and password for your Wifi.
Now under Sketch you will have som code already written for you and you just need to add what you want to do with your varaibles. If you are using the same set up as me you can just copy my code.
And then edit your dashboard as expained in the tutorial for Arduino IoT cloud.
The sensors has been connected to a breadboard with jumperwires to the microcontroller as the figure below:
I wanted to go with a cloud based platform for my application so the Arduino IoT cloud was a good option for me. It uses on-change or periodically based triggers. It uses MQTT as communication protocol.
It is easy to set up the variables and you can write and upload the code directly from the cloud.
Its limited as a free user so if you want more functions you need to subscribe to get more functions. I use the free plan, which works fine for me and my application.
The data is sent periodically from the humidity and the temparature sensors in an inteval of 5 sec, this is a time I will raise later on but I used 5 secs for testing my device, the RGB-leds is sent on a trigger.
I use WiFi for this application.
MQTT is the communication protocol.
The data will be saved for 1 day as a free user of Arduino IoT Cloud.
Heres a picture of the dashboard:
I had a hard time getting the sensors to work out. I started to try and program i Thonny and microPython but I had a hard time with the libraries. Then after a while I decided to go with the arduino IDE and arduino language (c++?). I think it would have been a bit easier if I had choosen to go with a pycom instead. But I think the arduino environment and its all tutorials were really good and it help me alot in this project though I would have liked to program in micrPython.
After all it worked out pretty nice and heres some pictures of my device.