Time to cook: 120min
Difficulty: +++++
With this recipe, you can build a monitoring system for a solar boiler. The device measures the boiler temperature, solar power temperature and hot water outlet temperature. The device is also capable of actuating a relay which can be used to turn on/off an additional electrical heating element in case the solar production is not sufficient during winter times.
The device is based on a nodemcu which hosts the popular ESP8266. This is a low-cost (<$5) arduino compatible WiFi module. I used the Grove sensors to be able to build an easy to use prototype.
The sensor data is sent to the AllthingsTalk Maker platform, which is ideal to build our own made device, aggregate the data and expose the data to other systems.
Ingredients
NodeMCU
Grove Base shield for NodeMCU
Grove Relay
Grove I2C HUB
Grove One wire temperature sensor (3x)
European 5V power supply
USB Micro cable
Enclosure
220V relay
Prerequisites
Tools
Arduino IDE
The Building Plan
Assembling the hardware
Let’s first assemble the hardware.
An overview of all electronic components is given in the image below
I am a fan of using the Grove system, it is an easy and hassle free way of wiring sensors. No soldering involved.
For this project I opt to use the one wire temperature sensor. They are based on the popular Dallas DS18B20 temperature sensor. The DS18B20 Digital Thermometer provides 9 to 12-bit (configurable) temperature readings and comes in this version with a waterproof shielding and a 2m long cable including a Grove connector with a resistance pre-assembled inside. Ideal for our project! A Grove relay is added, able to actuate an electric heating resistor.
Wire the IC2-HUB to the Grove Shield (I2C) connector
Wire the One-wire sensor to the IC2-HUB
Insert the NodeMCU onto the Base shield
You can put the electronics in an appropriate enclosure. A mains relay can be connected to the Grove relay to actuate an electric heating resistant in the solar Boiler.
The result could look like the picture below.
Creating the Digital representative on AllthingsTalk Maker
The next step is to create the digital representative of the solar boiler on AllThingsTalk Maker.
Create an account on AllThingsTalk Maker
If you don’t have an account yet, go to maker.allthingstalk.com and register an account.
Add a device
Select your playground
Click + add device
Select your own device
Give your device a name
Click connect
In Settings -> Authentication under your device you can find the device ID and DeviceToken. We will need this in the next step.
The assets under the device are created by the sketch. As soon as you execute the sketch on the NodeMCU, the assets will be created under your device.
Building the sketch
Next, we are going to upload the sketch onto the NodeMCU. The NodeMCU is based on the popular ESP8266 using the Arduino IDE.
To support the onewire temperature sensors, we can use the onewire library. OneWire is currently maintained by Paul Stoffregen and you can find the latest version on his website (https://www.pjrc.com/teensy/td_libs_OneWire.html)
Addressing a OneWire device
Each 1-Wire device contains a unique 64-bit 'ROM' address, consisting of an 8-bit family code, a 48-bit serial number, and an 8-bit CRC. The CRC is used to verify the integrity of the data.
Before sending a command to a single slave device, the master must first select that device using its unique ROM. Subsequent commands will be responded to by the selected device, if found.
To connect to the AllThingsTalk Maker platform we can use the Arduino WiFI SDK from AllThingsTalk. (https://github.com/allthingstalk/arduino-wifi-sdk)
The complete sketch can be downloaded here :
In the above sketch, replace the WiFi credentials with your local WiFi settings. Replace the device credentials with the DeviceId and DeviceToken in the previous step.
auto wifiCreds = WifiCredentials("WiFiSSID", "WiFiPassword"); // Your WiFi Network Name and Password
auto deviceCreds = DeviceConfig("DeviceID", "DeviceToken"); // Go to AllThingsTalk Maker > Devices > Your Device > Settings > Authentication to get your Device ID and Token
Compile and upload the Arduino sketch.
An extract from the debug window output:
Connecting to AllThingsTalk..
Connected to AllThingsTalk!
ROM = 28 69 6D 69 5 0 0 80
Chip = DS18B20
Data = 1 41 1 4B 46 7F FF F 10 AA CRC=AA
Temperature = 20.06 Celsius, 68.11 Fahrenheit
> Message Published to AllThingsTalk (JSON)
ROM = 28 D3 72 6A 5 0 0 D3
Chip = DS18B20
Data = 1 4D 1 4B 46 7F FF 3 10 D8 CRC=D8
Temperature = 20.81 Celsius, 69.46 Fahrenheit
> Message Published to AllThingsTalk (JSON)
ROM = 28 33 EC 5F 5 0 0 26
Chip = DS18B20
Data = 1 36 1 4B 46 7F FF A 10 30 CRC=30
Temperature = 19.37 Celsius, 66.87 Fahrenheit
> Message Published to AllThingsTalk (JSON)
No more addresses.
Test the solution
When you run the sketch on the NodeMCU for the first time, the necessary assets defined in the sketch are created under the digital representative in AllthingsTalk Maker. and you should see the data uploading with an interval of 1 minute.
What’s next?
From here you can go different ways. All asset data is available via the AllThingsTalk message broker and can be accessed over mqtt on the various topics.
In this cookbook you can find a recipe which shows how you can log the sensor data in a google sheet.
Comments