Maker Magnus Thomé has give you a technique to interface a low-cost capacitive rain sensor with Dwelling Assistant and different MQTT-compatible residence automation platforms — utilizing an Espressif ESP32 microcontroller and a 3D-printed housing to maintain issues neat and tidy.
“I’ve beforehand used these frequent resistive sensors which have copper traces that the rain falls on. The issue is that these boards are likely to deteriorate after some time as a consequence of oxidization,” Thomé explains of his transfer to a capacitive sensor. “A capacitive sensor is completely electrically remoted from the rain and damp. By having no exterior electrically linked sensor elements the primary issues with put on in an outside setting are eliminated. A bonus I discovered with the capacitive sensor I take advantage of is that it reacts a lot quicker to adjustments in rain depth in comparison with the resistive one I had beforehand.”
Housed in a wise 3D-printed case, this capacitive rain sensor avoids the corrosion issues of resistive variations. (📷: Magnus Thomé)
The sensor in query is the RC-SPC1K from Italy’s Radiocontrolli SRL, a low-cost system which mixes the sensor itself with a built-in heater — a bonus for deployment in Thomé’s residence of Sweden, the place issues typically get snowy and frosty. What the sensor would not have is any smarts of its personal — which is why Thomé put one below the management of an Espressif ESP32 microcontroller, writing code to maintain the sensor ticking over and to speak its findings to Dwelling Assistant over MQTT messages.
“When the sensor detects rain or snow the code retains the sensor at round 45 levels Celsius [113°F] by sensing the NTC resistor worth and turning the heater on and off (with a transistor) fairly shortly round a small temperature hysteresis,” Thomé explains. “The measurement of the capacitance is finished by first ensuring the capacitor/sensor is totally discharged by pulling the GPIO pin linked to it to floor.
“Then that pin is turned to a excessive impedance enter and one other pin goes excessive and begins charging the capacitor slowly via a 1Mohm resistor whereas the primary pin is measuring the rising voltage immediately on the capacitor. When the voltage reaches 63 per cent of the total voltage the time between the beginning and cease of this charging sequence is saved. The bigger the capacitance, when raining, the longer the charging time.”
The one complication — bar conserving the electronics dry — is the necessity to drive the sensor’s heater with 12V however an ESP32 with 5V. (📷: Magnus Thomé)
The elements require for the construct are comparatively restricted — simply the sensor, an NPN transistor, two 1kohm resistor and one 1Mohm resistor, plus an ESP32 board — however there’s one catch: “The sensor’s heater runs on 12V, so that’s the voltage it’s worthwhile to provide to your construct,” Thomé writes. “You usually want a DC-DC buck converter to energy the ESP32 at 5V, [but] I occurred to have an ESP32 board that may run on 12V natively so I simply had so as to add a couple of parts to interface it with the rain sensor.”
A wiring diagram, supply code, and STL/STEP recordsdata for printing the sensor housing and its mount can be found on Thomé’s GitHub repository below an unspecified license.