The project was a great DIY starting point, as it required no soldering as everything was connected with Dupont jumper wires and everything was held in place with hot glue.
Issues with the original multi-sensor
There were a few minor issues with this design however (besides the big bulky appearance). The first had to do with the PIR motion detector. The sensor box used an AM312 PIR sensor.
|
AM312 PIR Motion Sensor |
While these sensors are inexpensive and generally pretty reliable, for my particular situation in the garage, there were two primary problems. The first had to do with range and coverage:
Because our garage is an L-shaped 'tandem' 3-car garage, the motion detector could not see motion in the back part of the garage. Nor could it detect at the side service door, since the maximum range (in perfect conditions) is only around 5m / 16ft. and the garage is approximately 20 ft. wide.
Even the addition of a second standalone PIR sensor still left blind spots and areas without detection. And this was under ideal conditions... which leads to the biggest problem with the PIR sensors.
Our garage is not heated or air-conditions. In the summer months, it is not unusual for the ambient temperature in the garage to exceed 90°F.
Since the PIR sensors basically work by detecting heat, as the garage warmed, the effective range of the PIR sensors dropped to only a couple of feet (or less), basically rendering them useless in the summer months.
The second issue was also temperature-related. The temperature and humidity were reported by a DHT22 sensor:
|
DHT22 Temperature and Humidity Sensor |
And while also relatively inexpensive and reliable, my use has found that the temperature reported is always 1-2°F high and humidity is 2-3% high when compared to other devices, including standalone thermometers and hygrometers.
Building a Better Mousetrap
So, my new multi-sensor would attempt to solve the motion issue by using different technology and the DHT22 would be upgraded with a sensor reported to be more accurate. The components would be more securely soldered onto a prototype board and I'd also utilize the 3D printer this time around to make a smaller and hopefully less obtrusive enclosure.
The remainder of this article will cover the build process.
Parts List
As always, I like to start with the parts I used in my project. Each component will be described in more detail during the build, and I'll also indicate where alternatives might be considered.
Some of these links may be Amazon affiliate links. Use of these links will not affect your pricing, but this blog may earn a small commission if you make a purchase. Use of these Amazon links is one the best ways to show your support for the blog... at absolutely no cost to you!
Just a couple of follow-up notes regarding these parts. You need a way to power the NodeMCU and connected components. This is a 5 VDC board and the easiest way to power the system is through the NodeMCU's micro-USB port. Any device that provides 2-3A should be adequate to power the board. This could be a USB port on a power strip or outlet... or you can use just about any USB phone charger for power.
The link to the project box is the same box I used in the original version.. and it could still be used for the new version if you do not have access to a 3D printer.
Primary Components and Testing
This section will provide an overview of each primary sensor/component and how I tested each one for functionality and suitability before building the final version. If you just want to get to the build, skip ahead to the 'Assembling the Multi-Sensor' section.
NodeMCU (ESP8266)
I'm not going to cover all the various features here, as I've used the NodeMCU (and its cousins, the D1 Mini and the ESP32) in lots of projects. But since the original multi-sensor was the first time I used one (and if it is your first time), here's the very basics:
The NodeMCU is a microcontroller that has various pins (called GPIO for general purpose Input/Output) to accepting input from external devices or sending output to control other devices. It can be flashed (or programmed) with various languages, including C/C++, Python and more. For this project, we will be using something called ESPHome. More on that later.
More importantly, they are very low cost.. generally just a few dollars apiece. If you are just starting out with DIY electronics, odds are you are going to run into an ESP8266 or ESP32 soon! I did mention the NodeMCU's cousins... the D1 Mini which is a smaller version of the NodeMCU... and the ESP32 which is an upgraded, more powerful version. Both the D1 Mini and ESP32 could be substituted in this project. That's all I'm going to cover on the ESP board. There is a plethora of additional information and videos online if you want to learn more.
RCWL-0516 Microwave Radar Motion Sensor
This is the first major upgrade from the original PIR motion sensor version. Instead of infrared (IR) to detect motion, this sensor uses microwaves. Not only does this have the advantage of not being impacted by ambient temperature, but also penetrates through walls, meaning I may be able to eliminate the extra sensor in my garage and shouldn't need an opening in the enclosure box for the purposes of detecting motion. Furthermore, it has a published range of 7m (~23 ft) and a signal reset time as short as two seconds (vs. the 5 seconds on the PIR).
The range can be shortened by applying a resistor to the R-GN pads and signal time can be adjusted via a capacitor added C-TM. To test this, I soldered temporary wires to the R-GN and C-TM pads and mounted everything on a breadboard:
This will allow me to easily try different resistor and capacitor levels to tune it to my needs.
The sensor has an operating voltage of 4-28V, so we can power it from the 5V available on our board. For testing, I flashed a simple Arduino sketch that turns the LED on when motion is detected and back off again. For my initial testing, I didn't use a resistor or capacitor, so it is the sensor's default settings.
In a very unscientific test using a tape measure, I tried moving at various distances to test the motion detection. As you can see above, at 23 ft. from the sensor, motion is still detected. I did get detection a couple of times at close to 25 ft, but it was inconsistent. Anything from about 23 ft and closer resulted in consistent and accurate motion detection. I also tested from the side and by turning the sensor around (e.g. from the back) and found the range to still be at least 20 ft. According to published information, the range is the greatest from the 'front' of the sensor, but my testing showed at least a consistent detection for at least 15-18 ft. on all sides.
With this range and the fact that it detects through walls, a single sensor should cover the entire garage area. In fact, it is likely that motion could be detected from just beyond the garage or even from within the house. But since I don't use motion to turn on the lights, just to keep them on as long as motion is detected (the lights are turned on via door switches), this should be perfect, as even those particular areas inside the house are generally low traffic. More importantly, the range should not be impacted by the ambient garage temperature.
As far as signal time, it appeared that the signal time was slightly longer than the advertised 2 seconds, but more like 3-5 seconds. But again, for my purposes this is just fine. For these reasons, I won't need to add any resistors or capacitors to the sensor. If you are interested, there are numerous articles online for resistor and capacitor values to use. Just search for RCWL-0516.
AHT20 Temperature and Humidity Sensor
Next, I wanted to test the new temperature and humidity sensor and compare it against other sensors.
Unlike the DHT22, which uses a single signal wire, the AHT20 is an I2C device, meaning it uses two wires to connect to the controller.
By default, the NodeMCU uses D1 for SCL and D2 for SDA. And the AHT20 has a voltage operating range of 2 - 5.5V so we can also use the 5V rail to power this device. So again, I connected the AHT20 to the NodeMCU on a breadboard and flashed another simple Arduino sketch to report out temperature and humidity.
I started up the breadboard/AHT20 version and placed it next to two external independent temperature/humidity meters and two DHT22's connected to D1 Minis (running ESPHome). I let everything equalize for one hour then took readings from all the devices:
Device
|
Temperature
|
Humidity
|
External Device #1
|
75.9°
F
|
42%
|
External Device #2
|
75.9°
F
|
42%
|
|
|
|
DHT22 Sensor #1
|
76.6°
F
|
47%
|
DHT22 Sensor #2
|
77.1°
F
|
47%
|
|
|
|
AHT20 Sensor
|
75.7°
F
|
44%
|
As you can see above, both DHT22 sensors reported higher temperature (1-1.5°F) and about 5% higher on humidity. I found this to be pretty consistent on multiple DHT22's that I've used. It seems that they always report slightly higher temperature and humidity when compared to other devices.
The AHT20 on the other hand agreed with the external devices within 0.2°F on temperature and was only 2% higher on humidity. This is by far from scientific as there is no guarantee that the external devices are accurate either, but the AHT20 does seem to be more in alignment with other devices, so I will be using it in the new multi-sensor.
Photosensitive Light Detection Module
I use this module to prevent my garage lights from turning on when a door is opened if there is already adequate ambient light... such as when the main overhead door is open during the daytime.
Now, you could get the light level from just a simple photoresistor along with a second resistor to adjust the level. In fact, this is exactly when I did for my Dryer Notifications. But this particular module adds some nice features that will make my Home Assistant automations a bit easier.
First, this module has an operating voltage range from 3.3V - 5.0V, so once again it can be powered by our 5V rail. And it will output an analog light level via the A0 pin similar to how a photoresistor would be used. This can be connected to the A0 pin on the NodeMCU to get a voltage reading between 0 - 1, which can then be converted to a light level (e.g. lux).
But this module also has a digital output pin (DO). When the light level is above a certain detected value, this pin will read low (off). When below the light level, it will read high (on). The actual light level that triggers the pin can be adjusted via a small potentiometer on the board (small blue square in the above photo). This means that we can connect D0 to any appropriate GPIO pin and treat it as a binary sensor. Another example where you might use this is to only turn a lamp on when the room was at a certain darkness level. In my case, I will use this binary sensor as a condition in my automation so that the garage lights won't turn on if this sensor is "off" - light level is high.
Since this actually used like a binary sensor, similar to the motion detector, I used the same Arduino sketch for testing, except I had the LED turn red when the sensor reported "off" (e.g. light level above the threshold) and green when "on" (light level below the threshold).
By simply placing my hand over the sensor and blocking the light, you can see that the LED turned green. I did play with the potentiometer adjustment and found that I could set the value to trigger on very low light levels or only when the light was fairly bright. I will connect both the analog AO and the digital DO pins to the NodeMCU so that that I will have both values available in Home Assistant, but will likely use the digital binary sensor for my automations.
Update: A sharp-eyed viewer of the YouTube video noticed that the pins on my photosensitive module were 'reversed'... in other words, the pins came out of the back of the module instead of protruding from the front. To enable the module to be mounted flush against the enclosure and align with the openings for the photoresistor and adjustment potentiometer, I de-soldered the existing pins and re-soldered them from the back side of the module.
Common Cathode RGB LED
This is pretty basic and doesn't need a lot of explanation, but if you've only worked with LED strip lighting (like WS2812b), this is a little bit different.
|
Common Cathode RGB LED |
Unlike RGB strips where there is just a single data line plus a positive voltage and ground, the common cathode LED has four separate leads.
The long pin is the ground pin and will connect to ground on the controller board. Then each individual color (Red, Green and Blue) will connect to a separate GPIO pin on the NodeMCU. Each color can be individually turned off or on. By using two or more individual LEDs, we can get additional colors. For example, turning on the red and green LEDs will result in yellow. Blue and red will give a purplish color. The max voltage rating is technically 3.2V for the LED and each pin on the NodeMCU outputs 3.3V. But I've been running mine for 3+ years without issue. If you wan to be cautious, you could add a resistor to assure the voltage remains under 3.2... or to reduce the voltage even further to limit the maximum brightness.
With all the individual components tested, it's time to bring all of it together into a single multi-sensor.
ESPHome Code
You can find a complete copy of my ESPHome code for my multi-sensor in this gist, but I'll highlight the individual component sections here:
sensor:
# Temperatue / Humidity
- platform: aht10 #Also for AHT20
temperature:
name: "Garage Temperature2"
unit_of_measurement: "°F"
device_class: temperature
humidity:
name: "Garage Humidity2"
device_class: humidity
update_interval: 120s
# Analog Light Level
- platform: adc
pin: A0
name: "Garage Analog Light Level"
unit_of_measurement: lux
device_class: illuminance
update_interval: 10s
filters:
- lambda: |-
return (2800/x) - 2700; #only relative - not true lux
binary_sensor:
# RCWL-0516 Motion
- platform: gpio
pin: D6
name: "Garage Motion Front"
device_class: motion
# Photoresistor module DO light level
- platform: gpio
pin: D7
name: "Garage Digital Light Level"
# RGB LED
light:
- platform: rgb
name: "Garage Sensor LED2"
red: output_component1
green: output_component2
blue: output_component3
# LED output
output:
- platform: esp8266_pwm
id: output_component1
pin: D3
- platform: esp8266_pwm
id: output_component2
pin: D4
- platform: esp8266_pwm
id: output_component3
pin: D5
Again, note that I am bringing in two different light levels, using both the AO and DO pins on the light sensor. One (DO) is brought in as a binary sensor, and the other (AO) is brought in as an analog level and converted to approximate lux level via a lambda. The lamda calculation is only a relative approximation and will likely vary based on your particular installation. See the ESPHome documentation or other online sources for a true analog to lux calculation or for more details on the code if desired.
Full Breadboard Testing
With the ESPHome code loaded onto the NodeMCU, it's time for a final breadboard test... and to assure we can fit all the components on the ElectroCookie prototype board and that we are getting good readings from all the sensors in Home Assistant.
Don't get too concerned over all the wires here! A full wiring diagram is provided below as part of building the final sensor on the ElectroCookie board.
As soon as the NodeMCU is powered up after the ESPHome code is loaded, Home Assistant will automatically prompt to add the new multi-sensor. Once the integration is completed (basically you just need to copy/paste the encryption key if one is in your ESPHome code... then enter an optional area), the various sensors and controls should be shown... and if working properly, give valid values:
As you can see, the LED indicator is available as a control and can be toggled off or on via a switch. Under the sensors, both the analog light level and the digital on/off light level are available. So are temperature, humidity and motion. Just slight movement (like typing this sentence) is enough to trigger the motion detector which is approximately 3 feet away. I can cover the light sensor with my hand and see both the lux drop and the digital light level switch from off to on. And both the temperature and humidity seem to be in an acceptable range.
So, everything appears to be working! The next step is to now transfer everything from the breadboard to a soldered version on the prototype board. And then probably the most difficult part... designing and 3D printing an enclosure for everything!
Assembling the Multi-Sensor
Now it's time to move everything to a final version. Here is the wiring diagram I will be following:
|
Click on the above image to view larger version |
The NodeMCU, RCWL-0516 sensor and RGB LED will be mounted directly to the ElectroCookie board. The AHT20 and photoresistor module will be connected to the ElectroCookie with wire leads. This is so that the AHT20 temperature and humidity sensor can be mounted above the enclosure that holds the NodeMCU. The NodeMCU will generate slight heat when running that could impact the temperature reading if the sensor was in the same box. Similarly, the actual photoresistor should point outside the box for the light reading and the adjustment potentiometer should also be accessible from outside the enclosure. This is much the same as on the original project box version:
And since the ElectroCookie board will be mounted on offsets within the 3D printed enclosure, it will permit wiring and soldering to occur underneath the board as well as on the top surface.
But the first step is to solder small jumpers to the power rails on both ends of the ElectroCookie board. This means that 5V and ground will be available on both sides of the board for wiring the other components.
How you opt to run and solder the remaining wiring is somewhat dependent upon your personal choice and if/how you are going to mount your multi-sensor in an enclosure. In my case, my 3D printed enclosure will include stand-offs to raise the board up slightly. The stand-offs, or offsets, will also allow me to use small M2 screws to secure the board inside the enclosure:
|
Not the actual enclsosure - this is from another project |
Since the board is slightly raised, it allow me to run wiring connections on the underside of the board as well as on the top. I generally opt to run any board-to-board connections on the underside of the board and any wires that are going to connected to another device externally on the top side of the board, but this depends on the particular install.
|
Underboard wiring |
In this case, I ran the connections for the onboard microwave motion detector and the RGB wires for the LED on the underside of the board.
Now, if you are going to complete any underboard wiring and those connections will be under a soldered component, you obviously need to make these connections before soldering the components onto the board (otherwise you won't be able to get to them with the soldering iron!). In addition, assure your solder joints are low enough (or snip them off) so that the soldered joint does not come in contact with the component that mounts on top. You can also go ahead and complete any top side wiring that you like... or that might be difficult to solder once the components are in place. In the above photo, I've gone ahead and soldered the 5V and GND connection from the NodeMCU to the power rails. I also opted to add the ground connection for the LED on the top of the board.
Once any onboard wiring is completed, I go ahead and solder the components onto the board. I wait to add the external component wiring (in this case, that's the temperature sensor and the light level sensor) until I have my final enclosure and installation design completed, so I know about how long those lead wires need to be.
Project Enclosure
If you are fortunate enough to have access to a 3D printer, you can custom design an enclosure to exactly meet your needs.
I'm definitely not an expert at creating 3D objects. I use a simply free online applications called TinkerCad to create most of my enclosures, and pretty much stick to basic geometric shapes likes squares and circles! But I will make a couple of comments here in case you want to design your own enclosure. First, as I mentioned above, the enclosure has mounting offsets to hold the ElectroCookie board. This not only allows the board to be securely mounted in the enclosure (I design mine to accept M2 screws), but also raises the board which allows wiring to occur both on the top and bottom of the board. You can find the 3D design files for my enclosure on Thingiverse.
The temperature/humidity sensor are broken out above the enclosure. The NodeMCU does generate a little bit of heat. While not significant, it is enough that it would affect the temperature reading if the temperature sensor was enclosed in the same box. Instead the temperature sensor fits through a small slot in the top of the main enclosure. The slot is then sealed with a little hot glue to keep any heat from leaking up to the sensor.
What if I don't have a 3D Printer?
I get this question a lot since many of my projects make use of a 3D printed enclosure. Not to fear! One option would be to use an online service to print the part(s) for you. You simply submit a design file (usually a .stl file) online, the service then prints and ships you the completed part. But this is probably not the most cost-effective solution. As an example, I uploaded the above enclosure to an online service an the cost was going to be about $9 for printing... before tax and shipping.
Another option that you can check out is if you live near a university or in a town that might have a maker space. You may be able to get an occasional part printed at those locations for a much cheaper cost. Some libraries even have 3D printers available now.
Finally, you can just pick up a low cost project box or adapt another container for your project.
There are a variety of different sizes of project boxes available online at places like Amazon (the larger black box and the one I used for my original multi-sensor is linked in the parts list above). These project boxes are relatively easy to drill and cut to make openings. Or even check out your local dollar stores or flea markets. Things like a soap box can even make decent project enclosures. The point is that many projects similar to this can be completed without using a 3D printer.
Final Assembly
Once I had my final enclosure designed, it was just a matter of dropping in the board, securing it and connecting temperature/humidity sensor, light sensor and the RGB LED.
For the sensors that weren't soldered onto the main board, I opted to keep the female Dupont jumper connections for the device pins. I cut the Dupont connectors off from the other end and soldered those directly to the board. I did have to de-solder the pins from the photo-detector module and flip them to the back side so that the module would sit flush with the side of the enclosure. The only other really tricky part of this step was trying to get the LED at the proper height so that it would just come out flush with the hole in the lid. I didn't want the LED to protrude out the front... and the LED couldn't be glued or the lid wouldn't come off later if needed!
Once that was completed, it was time to move it to the garage, mount it on the wall and see if I succeeded in improving the limitations of the original multi-sensor.
Final Testing And Results
Hey there, I stumbled across your youtube videos earlier this month and even built a few of your projects (my wife loves the new parking sensor!) After getting this garage multi sensor setup, I have noticed that the microwave motion sensor seems to trigger a lot when no one is in the garage, I have a house with brick siding and have the sensor pointed away from the walk way and towards the side of the garage that doesn't see any foot traffic. I was wondering if you are seeing a lot of accidental triggers? My first thought was maybe it is bugs flying around, but I took the cover off the sensor box and anecdotally saw less aberrant triggers. I ended up using the project box you used in your first iteration from Amazon. Unfortunately, I don't have a 3D printer...yet. Anyway, I know this isn't a place for technical support, but figured I would reach out and see if you have noticed the same or different. On another note, I have really enjoyed following along your tutorials on youtube and the blog, it literally got me into Home Assistant (from HomeKit - the two play well together to my mild surprise) and I have been having a blast adding LEDs to different things around the house. Keep up the great content!
ReplyDeleteYeah... the motion sensor triggers a lot. But recall that this is a 360 degree sensor that also penetrates walls. So, motion is detected even when we walk in certain areas of the kitchen with walls adjacent to the garage. That's why this particular motion sensor isn't ideal for some use cases... such as triggering a light to turn on. In my case, it was ideal because it is only meant to keep the lights on during motion after they have been triggered by another event (e.g. a door opening in my case). But I would not want to use this sensor to actually turn on the lights... just for the reason you specify. The garage lights would turn on whenever we walked near our kitchen table! Note that you can adjust the range with a resistor. Others have claimed that they also reduced the field of view by placing some sort of metal behind the sensor to block sensing in that direction... but I have not tried that, so I can't confirm that this works (but I suspect it would).
DeleteSo, this sensor is great for certain use cases... but there are better options for others. For me and my use case, this was a much better solution than PIR (due to temperature changes in the garage and its ability to penetrate walls), but for other situations, a PIR or even time-of-flight or ultrasonic distance sensors might be a better solution.
Thanks for watching all the videos and reading the blog articles! Just as an FYI, I am preparing to launch a Discord server soon. It is a much better platform for support or to just chat about projects, Home Assistant, etc. Initially this will be a pretty small group... by invitation only at the start. But if you do have a Discord account and can get me your Discord handle, I'll make sure to shoot you over an invite.
Thanks for the reply! Yes, please add me to your Discord when you have it all setup (Incognitoflux) I would love to join the chat and learn more. Excellent points all around, I actually have the automation set to trigger the lights when the door is opened (via contact sensor on the entry door from the house) and then remain on until no motion is detected after running out a 10 minute timer. I think this is similar to your automation? Either way, it works great and I love having the temp/humidity of the garage. I am still not sure of the utility of the ambient light sensor since in my testing it doesn't appear to be sensitive enough in low light conditions (or I have the lamda code set poorly, but no significant change after commenting it out and trying again).
DeleteAre you using the digital or analog sensor for the light level? The digital can be adjusted via the screw on the sensor... and is a simple on/off binary sensor and can be adjusted to whatever light level you need to use as a trigger or condition. I actually use both in my automations... but the digital version is a bit more reliable, as it doesn't rely on any sort of lamba. I guess this is the kind of thing that is easier to chat about and troubleshoot in Discord!
DeleteOh...and on that front, your Discord handle should include a #xxxx with four numbers for the "x"s. That's what I'll need to issue an invite. So, it should be something like Incognitoflux#1234. You can find it on Discord down in the lower left corner (web version) or just look at your account.
Once again Thank you!!! This will replace a couple devices in each room with just 1!! I was looking for something to keep a light for instance if I'm still in the room... like resetting a 30 second timer if it still detects I'm there :) So I can now get rid of my motion sensors and temp/humidity sensors...cutting down the number of actual hardware!! :)
DeleteThat is exactly how I use it for my garage lights. It's not the best sensor to use to turn the lights off/on because of its range and ability to penetrate walls, but for something like keeping the lights on as long as motion is still detected (via a timer reset like we are both doing), it is definitely an improvement over PIR sensors... and is not temperature sensitive like the PIR sensors were in my garage. Glad you found the article helpful!
DeleteI can't wait to build one!! 3d Parts all ready and just waiting on a couple things from Amazon :)
Delete