🔨〽️💦diy filament humidity sensor

If you dive in to the deep ocean of 3D printing, you will face the situation of storeing your filament in a proper way sooner or later. To be more precise, you want to keep your filament as dry as possible because most filaments absorb moisture. If you store your filament in a large box like I do, the humidity value in that box is kinda important. That was exactly the motivation behind this diy project. Of course, that’s not the only case for such a sensor. You can use it in many different scenarios where the humidity and or temperature value becomes important 😉.

Topview of the complete sensor.
The finished sensor ready to use

The Idea

I wanted to create a relatively small sensor, which is battery powered, rechargeable and can be easily integrated into Home Assistant. After some research, I decided to go with the following setup. A simple ESP8266 (D1 Mini) including a battery shield in combination with DHT-11 humidity & temperature sensor. This setup can be easily driven by an ESPHome sketch and seamlessly integrated into Home Assistant. It’s also small enough to fit into a small container which, in my case, was originally made for hair gel.

Parts list

For this project we will use the following components:

*Some links are affiliate links. If you use them to buy the parts for your project you will help me and my next project. These links will cause no extra fee or costs to you

Top view of all components used in this project.
All components

Prepare the D1 Mini

Start with soldering the female pin header to the D1 Mini. Mostly the D1 Mini comes with a variety of pin headers, select the female ones that fits best. Solder the pins to downside of the D1 Mini so that the WIFI antenna isn’t blocked by the battery shield if it’s connected.

Soldering process of the female pin headers
Soldering the pin headers

Prepare the battery shield

The battery shield will provide the power for the D1 Mini and will also take care of the battery charging process. That’s pretty neat, but with a slight modification, we can make the board even more useful. If you add a 100K Ohm resistor between the plus pole of the battery and the analog A0 pin, you can read the battery operating voltage, which can be used to calculate the capacity of the battery. With that value, you can create an automation in Home Assistant, to inform you if the sensor needs to be recharged.

Closeup of the resistor modification of the battery shield
Modified battery shield

Prepare the DHT-11

To connect the DHT-11 sensor to the D1 Mini grab some wires and presolder the ends on one side. Next snip of some heat shrinks and slide them over the soldered wires.

Presoldered cables with heat shrinks
Prepared cables

In the next step we will solder the wires to the DHT-11. The DHT-11 has 4 pins in general where the third one f.r.t.l isn’t in use. Solder the wires to DHT-11 as shown on the picture. I used red for positive, white for GND and green as the data wire.

The DHT-11 with soldered wires
The DHT-11 with soldered wires

Make a Sandwich😉

In this step we will connect the sensor to the D1 Mini and the battery shield. So flip the D1 Mini and slide the sensor wires into the females pin header. White goes to the GND pin, red to the 5V pin and green to the D4 pin of the D1 Mini. Further we will connect the RST pin with the D0 pin.

Downside of the D1 Mini with connected sensor and bridged reset pin.
D1 Mini with connected sensor and bridged pins

Connecting RST and D0(GPIO16) is very important, because our sensor will run on battery and not be continuously on. That would consume too much power and the battery would be empty within one or two days. To prevent this, our sensor will use a feature called deep sleep. With this feature enabled, the D1 Mini will only wake up every couple hours, take some measurements, send the data to Home Assistant and fall back into sleep / energy saving mode. This way is super efficient and will max out the battery life up to two weeks instead of two days. To enable deep sleep on an ESP8266 device you have to bridge these two pins, otherwise the D1 Mini will never wake up again.

If everything is setup properly, connect the battery shield and the D1 Mini. Keep an eye on the pins, the labels on the battery shield must match with the ones on the D1 Mini.

Close up of the battery shield connected to the D1 Mini
The senors sandwitch

Prepare the battery

Before we flash the D1 Mini with our sketch, we will prepare the battery to our sensor. If you don’t have a connector, you can simply solder the wires to the battery socket of the D1 Mini battery shield. In my case, I had a spare connector lying around, so I soldered it to the battery to make disconnections simpler. It’s also recommended to disconnect the battery from the D1 Mini while flashing. If you don’t use a connector, you have to disconnect the D1 Mini from the battery shield for the flashing process.

Battery with soldered connector
Battery with soldered connector

Flashing the D1 Mini

To flash the sketch to your D1 Mini, go to the ESP Home section in your Home Assistant installation and create a new project and start with a project name. I named mine diy-humidity-sensor.

Setup to name your device
Add a useful name

Next choose the board type. Because we are using a D1 Mini click on ESP8266.

Setup an new project in ESP HOME
Select the board

After that click on next and then on install to choose a preferred installation method. I always use the manual download option because I like to flash my ESP’s using ESP Home Flasher.

Finished setup

Install the sketch

To finish the installation, copy the script below to your editor, compile it and flash it to the D1 Mini. If you don’t use secrets, change the WIFI credentials to your needs. This sketch will create several sensors in Home Assistant including the battery percentage one. Further it will use the deep sleep function to operate 1 minute and then goes into sleep for 3 hours.

esphome:
  name: diy-humidity-sensor

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "SuperSecr3t"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Diy-Humidity-Sensor"
    password: "SuperSecr3t"

captive_portal:

sensor:
#VCC on batter
  - platform: adc
    pin: A0
    id: "LIFEPO"
    name: "A0 voltage x 3.0"
    update_interval: 18s
    accuracy_decimals: 3
    filters:
      - multiply: 3.0
  - platform: template
    name: "diy-humidity-sensor-battery-voltage"
    unit_of_measurement: 'V'
    update_interval: 18s
    accuracy_decimals: 2
    lambda: |-
      return (id(LIFEPO).state);
  - platform: template
    name: "diy-humidity-sensor-battery-percentage"
    unit_of_measurement: '%'
    update_interval: 18s
    accuracy_decimals: 0
    lambda: |-
      return ((id(LIFEPO).state-2.2) /0.8 * 100.00);

#Temperature and humidity
  - platform: dht
    model: DHT11
    pin: D4
    temperature:
      name: "diy-humidity-sensor-temperature"
    humidity:
      name: "diy-humidity-sensor-humidity"
    update_interval: 18s
    
deep_sleep:
  id: deep_sleep_1
  run_duration: 60s
  sleep_duration: 180min

Finish the installation

After flashing the D1 Mini, grab your enclosure and ensure that the DTH-11 will be exposed to the air. I drilled some holes into the lid of my container to ensure that.

Topview of container lid with holes
Lid with holes

Last not least connect the battery to the battery shield and place everything inside the container.

Sensor in the container
Sensor in the container

UPDATE: During my tests, I found out that the LED on the D1 Mini uses a quite large amount of power. This will decrease the run time of the sensor, so I desoldered the LED from the D1 Mini 😬.

Check Home Assistant

After connecting the battery to the sensor, you will find a new ESPHome device in Home Assistant which provides the sensors, which were defined in the sketch.

Home Assistant entity list
Entity list

These entities can simply added to a dashboard or used in an automation.

Dashboard card
Values in the dashboard

Sum up

And that’s it. Your diy filament humidity sensor is ready to go 😁 You can now measure the current humidity and temperatue inside you filament storage. You can also use the sensor data in an automation which informs you if the humidity in your filament storage increases or exceeds a certain level. Or you can display the information on a dashboard like I did.

I hope you like this project and I’m looking forward to your comments and shares.

🔋🏃💡Battery powered PIR outdoor light

Smart devices, especially lights, are super cool. But with the smartness of a device mostly comes a trade off in manner of power consumption and complexity. This is not always needed and makes the problem to solve often bigger than it actually is. I ran in this situation recently and caught myself standing in the front yard thinking hard about how to increase my WiFi range for installing a smart light🤦. Because I couldn’t solve the WiFi problem, I started from scratch and ended up with a much more simple solution which works out perfectly. A DIY battery powered PIR outdoor light 🤓.

Top view of Battery powered PIR outdoor light
Battery powered PIR outdoor light

Parts list

For this project we will use the following components

*Some links are affiliate links. If you use them to buy the parts for your project you will help me and my next project. These links will cause no extra fee or costs to you

All parts for this project
All components

How does it work?

The PIR sensor, the LED’s and the MOSFET are connected to the DC-DC step up converter which is powered by the battery. If the sensor recognizes motion from dusk on, it will trigger the gate of the MOSFET, which than acts as a switch and turns the LED’s on for a certain amount of time. If the battery runs out of power, it can be simply recharged via USB. Last not least, the whole circuit can be turned off using the button. And all this without a single line of code 😍.

Start with the power

We will start with building the power circuit first. So grab the rechargeable battery and solder the some wire to the plus and minus pole. To prevent shorts later on, ensure that you will wrap the open sides of the contacts in isolating or Kapton tape.

Rechargeable battery with soldered wires
prepared battery

Grab now the push button and solder two wires to it. In my case I used red wires, because I want to disconnect the positive side of the circuit with the button. As same as on the battery protect the solder joins with heat shirks or isolating tape.

Regular button with two soldered wires
prepared button

Combine the charging unit with the battery and the button in the next step. Solder the battery to the battery pads and the switch to the positive load pad. Grab and extra piece of wire and, black in my case, and solder it to the negative load pad. So you end up with two wires which can be connected to a load.

Battery connected to the charging unit and the regular button
Connected batter charging unit

Because the HC-SR501 needs at least 5V to operate, we have to adjust the DC-DC step up converter in the next step. I selected 6V at this point, because I needed 6V for the arrangement of the LED’s I used. If you want to use e.g. a 5V led strip instead, simply adjust the voltage to your needs.

Adjustment of the DC-DC step up converter
The adjusted converter

If the converter is adjusted solder the input side to the two wires of the previous circuit. This completes our power supply.

If the button is pressed it connects the battery through the charging unit with the step up converter which provides 6V. If we want to charge the battery we disconnect the step up with the switch and can safely plugin a USB cable to the charging unit.

Power providing circuit top view
The finished power providing circuit

Move on to the enclosure

In the next step we will focus on the enclosure of the outdoor light. Grab the lid of the electric box and cut a hole into it so that the cover of the HC-SR501 fits in. Have a close look at the orientation. I had to place it diamond ways so that it will fit with the LED’s.

Electric box lid with HC-SR501 inside
Electric box cutout

Secure the sensor cover with hot glue form both sides to make it kinda weather proof. Next, grab a drill and drill 6 holes for the LED’s inside the lid.

Glued lid with 6 holes in it
Lid prepared for the LED’s

In the next step, place the LED’s inside the lid and connect them with a piece of wire. I decided to use two pairs of three LED’s in parallel, connected in series. That way three LED’s in parallel will need 3V and the two LED packages in series (six LED’s) can be powered with 6V without any problem. Thats also the reason why I chose white LED’s because each of them has a operating voltage of 3.2V max. If you solder the LED’s keep an eye on the polarity, if you mixed them up, they will not work.

Lid with LED's inside
Prepared LED’s

BTW: I know many people will now yell: “You have to use dropping resistors for the LED’s🤯 “. Yes I should… but YOLO!! We’re working with six cheap LED’s in this outdoor light and it works perfectly that way, trust me 😉.

To finish the lid, solder two wires to the positive and negative side of the LED’s and flood them in hot glue for a better weather resistance.

Finished lid with LED's and wires connected
Finished lid

Prepare the MOSFET and the PIR sensor

Lay the lid with the LED’s aside and prepare the PIR sensor. Take a close look at the board. You will find two wholes above the infrared sensor, with the marking “LR”. Take the LDR and solder it in that place. Be aware of touching the infrared sensor with your fingers, this would affect the functionality of the sensor.

PIR sensor with soldered LDR
Prepared sensor

Lets now move to the funny part of the project and grab the IRLZ44N MOSFET to solder the 47KΩ resistor on it. Solder the resistor between the gate and the source of the MOSFET. This ensures that the gate is always pulled low if now signal is provided from the PIR sensor. If you’re unsure which pins to use, checkout page 8 in the MOSFET datasheet.

FYI💡: In general you can use any kind of NPN MOSFET as long as it is a logic level one.

47k resistor soldered between gate and source of the IRLZ44N MOSFET
Resistor + MOSFET

In the next step we will wire up the MOSFET. Grab two pieces of black wire and one red one. Remove some isolation from the two black wires, twist the ends and solder them to the source of the MOSFET. In my case it’s the third leg. Then take the red wire and solder it to the gate of the MOSFET, in my case that’s the first leg. Add some heat shrinks to prevent shorts.

Last not least, grab the lid of the electrical box and solder the black wire of the LED’s to drain of the MOSFET. In my case that’s the center leg. After connecting the wires, you should end up with something like the picture below.

MOSFET with soldered cables on it
The MOSFET wired up

Connect the MOSFET, the PIR sensor and the LED’s

We will now connect the MOSFET and the LED’s to the PIR sensor of the outdoor light. Grab the PIR sensor, the red wire and one of the black wires of the MOSFET. Solder the red wire which comes from the gate of the MOSFET to the OUT pin of the PIR sensor and the black wire to the GND pin. As always, don’t forget the heat shrinks 😉.

PIR sensor and MOSFET connected
MOSFET soldered to the PIR sensor

To connect the PIR sensor to our power circuit we’ll need one more piece of wire. This piece, in my case a red one goes to the VCC pin of the PIR sensor.

Top view of the lid and PIR sensor with all wires connected
Sensor with soldered MOSFET and power wire

All in all you should end up now with the connected MOSFET, PIR sensor and the LED’s. From this combination you should have one black wire and two red wires left. If not, something went wrong so feel free to start over at the beginning of this section🙈.

If you have the correct amount of wires left, take the red ones and twist them together. Then grab the power circuit and solder the red wires to positive output pad of the step up converter. If that is done solder the black wire to the negative side of the converter. Finish everything by placing the sensor back onto the lid. If you want, add a lager heat shrink to the MOSFET so it will cause no shorts when it will be jammed in the box.

All components wired up
The complete circuit.

Test it and squeeze it in the box

If you’re now pressing the button you should see the outdoor light LED’s light up. This is the normal calibration behavior of the HC-SR501. If the leds turn of after some time, they will not light up again until it’s dark. That’s the reason why we added the LDR to the sensor😉.

First test of the outdoor light
First bench test

Use the two potentiometers on the sensor to adjust the sensitivity and the light duration of the sensor. Take also a look at the jumper for selecting the operation mode. In my case I set it to “repeat trigger”, that ensures that the light stays on if there is motion again during the on time of the LED’s. For more information about the configuration of the sensor, checkout the HC-SR501-datasheet .

Detail view of the potentiometers and the jumper
Adjustment of the sensor

After finishing the adjustments we can squeeze everything into the electric junction box. It’s a tight fit but it worked for me.

View of the inside of the electric junction box
Everything in a box

Final thoughts

And that’s it, a complete analog DIY battery powered PIR outdoor light 😊. It was so much fun to built it and I learned a lot about transistors and circuits in general. Further more, it teached me that not everything must be “smart” to be smart.

If you like this project or you already built your own version, feel free to share your results with me on twitter 🤓

🎄 Xmas tree moisture sensor 🎄

This little Xmas tree moisture sensor is a perfect give away for family and friends. I soldered about 10 of them this year to give them away and the feedback was just awesome. This little helper prevents your Xmas tree to dry out and loose pine needles early. This usage is quite easy, hang the ball into your Xmas tree and place the two electrodes into the water reservoir. If the reservoir is filled, the led is off, if it’s on, the reservoir is empty and you have to water your tree.

Xmas tree moisture sensor

Parts list

For this project we will use the following components

  • A transparent Xmas ball
  • A 2N2222 NPN transistor
  • A 220 Ohm resistor
  • A CR2032 battery holder + battery
  • A red led
  • About 2m of 26 AWG wire (2x 1m)
  • Wire ferrules
  • Hot glue
All components

Solder it up

Bend the legs of the transistor and the led, then solder the collector of the transistor to the cathode (short leg) of the led. Because the transistor has no markings for the pins ensure that flat side of the transistor faces downside. In this orientation the pinout is, (f.l.t.r) collector, base, emitter.

Led and transistor soldered together

Now take the CR2032 battery holder and flip it and solder the led transistor package to. Keep an eye on the polarity, the led must be soldered to the positive side of the batter holder.

Tipp: Pre solder the legs and the pins on the battery holder.

Soldered battery holder

In the next step we will solder the risitor between the anode of the led and the base of the transistor. This will ensure that we have matching current on the base if the circuit is closed.

Resistor between anode and base

With the resistor in place, the circuit is complete and we can now have a look at the wires. So grab the wires and pre solder the two ends. This way it becomes much easier to solder the wire to board later.

Presoldered wires

After that solder the wires to the base and the emitter of the transistor and cover the everything with hot glue.

Wires soldered and ready for hot glue

Prepare the Xmas ball

Until the hot glue gets cold, we can focus on the transparent Xmas ball. To get the wires through we have to drill a hole inside the ball. I use a 5mm metal drill and place the hole about 2cm away from the edge of the half ball. If you drill the hole more to the edge it might crack the plastic.

Ready to drill

Now take the ends of the wires and put them through the drilled hole. Then grab the ferrules and applie them to the end of the wires. Don’t add the ferrules first, because then they wont fit trough the hole.

Cables with ferrules on it

Last not least, put add a CR2032 battery into the battery holder and add both halfs of the ball together. The led should light up beacuse there is no contact between the probes.

Probes with no contact

Now, hold the probes into water. The led should turn off because the contact is closed.

Probes with water contact

Tipp: To hold the probes of the Xmas tree moisture sensor near to each other, you could use an insulating screw joint.

Sum up

And that’s it. You have successfully build your own Xmas tree moisture sensor 😃 So, start over again and build some more of these guys for sharing them with your family and friends.

If you like this project, feel free to share the article or an image of your Xmas ball 😉