Building an sensor for environment data on the outside can be done easily by using the HomeDing Arduino library, Here many different sensors and other functional elements can be used without hardcore coding by defining elements and actions on the configuration.
This walkthrough about using a simple DHT22 sensor to capture temperature and humidity and you can find other sensor configurations in the linked documentation. A ESP8266 based board is used that allows directly accessing the device by WiFi as there is a built-in Web Server.
Some weather parameters are interesting to be measured by using an outside sensor like
- Temperature
- Humidity
- Sun light
- Air pressure
- Rain
There are many sensor elements supported by the library and it is easy to used a different sensor or add other sensors as this is just done by configuration.
This project is a good starter project as well to explore the possibilities for building sensors gadgets yourself.
In contrast to the sensor that must be exposed to the outside air the microprocessor board should be placed into a water proof housing. Only the USB power line and the sensor wires are going out.
This sensor should be placed in a location where direct rain and sunlight could not reach it so there is no need for special high water resistant shielding required.
Also USB power is available and the device can be powered all the time.
You can start the sensor building on a breadboard first and put it into a housing later.
To see the current values from the sensors and to change the configuration the device has a built-in web server.
There are extensions like logging or other sensor types that can be added by configuration.
Prepare Arduino Environment for ESP8266To build the software you need a working Arduino environment for ESP8266:
- Install latest version of Arduino IDE (currently version 1.8.13).
- Use Board Manager to install the install the esp8266 support.A detailed instruction can be found here: <https://arduino-esp8266.readthedocs.io/en/latest/installing.html#boards-manager>
- Setup the board options for a NodeMCU 1.0 with 1MByte SPIFFS File System
To install the HomeDing library use the Arduino Library Manager and search for HomeDing.
When you install the HomeDing library you will see a popup with some required libraries that can be installed automatically as the HomeDing library relies on some common extra libraries for sensors and displays to work.
The Standard Example already includes all that is needed so simply use this example.
For simplicity on adding the new device to the network you may add the SSID and passphrase of your home WiFi in the secrets.h file next to the standard.ino sketch file.
Now upload the sketch / firmware and find the interim device name on the Serial Output:
00:00:10 sys:i ESP-5D3132 192.168.2.125
00:00:10 sys:i Connected to DEVNET unsafe
Here the name of the device ESP-5D3132 and its IP-address can be found.
The configuration will be required, see below.
Upload the web UIThis steps enables the Web UI of the device by uploading the required files into the filesystem. This method is very useful when starting with a new board.
The simplest way to do this is by using the Builtin Web based Upload Utility that can be reached at http://ESP-xxxxxx/$update.htm.
By pressing the start button all required files from the homeding documentation website are transferred to the device.
The files are also available at <https://github.com/HomeDing/homeding.github.io/tree/master/v02> it you like to know what will be uploaded.
After the upload has finished you can navigate to the next step to select an icon for the device. Take DHT and press "start" to place some icon files on the device.
When navigating to the next step the embedded IDE will be started and we are ready for configuration.
Configuration FilesThe embedded IDE can be opened from the homepage using the IDE menu item.
2 configuration files must be used to configure the sensor. To do this we can used the built-in micro IDE to create these 2 files.
env.json
The env.json
contains only the system settings that do not change while configuring a specific functionality. Enter the following configuration on the right side and save. When requested enter /json.txt
into the filename field.
{
"device": {
"0": {
"name": "outdoor",
"reboottime": "24h",
"description": "Outdoor sensor",
"logfile": 1,
"safemode": "false",
"homepage":"/board.htm",
"led": "D0",
"button": "D4"
}
},
"ota": {
"0": {
"port": 8266,
"passwd": "123",
"description": "Listen for 'over the air' OTA Updates"
}
},
"ssdp": {
"0": {
"ModelUrl": "https://www.mathertel.de/Arduino"
}
}
}
config.json
The `config.json` contains the sensor specific settings and also includes some value logging.
To create a `config.json` file on the device just open the IDE from the menu and copy the following configuration into the right text area and then click the save button.
When requested enter `/config.json` into the filename field.
{
"dht": {
"on": {
"type": "DHT22",
"description": "Temperature and Humidity sensor",
"pin": "D5",
"readtime": "30s",
"restart": "true",
"powerpin": "D6",
"powerinverse": "true",
"onhumidity": "log/h?value=$v",
"ontemperature": "log/t?value=$v"
}
},
"ntptime": {
"0": {
"zone": "CET-1CEST,M3.5.0,M10.5.0/3"
}
},
"log": {
"h": {
"description": "log humidity",
"averagetime": "00:05:00",
"filesize": "10000",
"filename": "/humlog.txt"
},
"t": {
"description": "log temperature",
"averagetime": "00:05:00",
"filesize": "10000",
"filename": "/templog.txt"
}
}
}
Wiring (simple)Please detach the USB cable while adding the sensor.
The principle wiring of a DHT22 sensor can be seen in this picture:
As you can see in the config.json file the data pin that was configured on the software side is the D5 GPIO pin so data from the sensor chip must be connected here.
More details on the DHT22 connecting options can be found in the DHT Element description and below.
RestartNow re-connect the device. The LED will blink several times while connecting to the network.
After a reboot the device is renamed to "outdoor" (as specified in the configuration) and is available using the link http://outdoor/board.htm.
More Robust Sensor wiringThe DHT22 sensor sometimes stops working. This happens more often when 3.3V is used as a power supply and occurs sometimes after many days of operation.
As a corrective measure it is possible to use the sensor reset mechanism if the DHT Element to enable power some seconds before a sensor reading is required and then cut off power after getting a value.
The DHT22 wiring has to be changed so that the GND pin is attached to a GPIO (D6 is used here).
Device DashboardThe information the device is gathering can be found on the device dashboard.
Open http://outdoor/board.htm to open the dashboard and see current sensor values.
After some time some historical log data will also be displayed.
Further OptionsThe HomeDing library offers a lot of options that can be used to create more value from your sensor device.
- There are many sensors available in the HomeDing library. See List of sensors.
- You can add more sensor values like air pressure and see high and low weather effects and trends.See the story Build a In-house IoT Air Quality sensor
- You can setup a new device with a display and then configure the sensor to send over the actual values using remote actions.
- The same sensor type can be used in-house also to log temperature and humidity, just build another one.
- The HomeDing Library documentation has a more detailled introduction and there are many Elements you can configure without writing code.
- If you have special requirements you can also implement your own elements and integrate them into the eco-system.
Comments