April 25, 2020

Toilet roll roller

This week someone kindly left a box of industrial sized toilet rolls in our building's foyer for people to take. The large size roll isn't going to fit in my bathroom, but maybe I can improvise something. Hey it was free!

My first thought was maybe I can wind some onto an empty roll. Perhaps there is a way to fit the roll to my drill to help wind.

While it looks broadly feasible, the fit is not good enough. Maybe I could make some kind of roll holder that attaches to the drill, and fits inside the cardboard roll to help roll it. At this point I'm thinking of just doing the minimum to get something working.

I have plenty of time at home at the moment, what with COVID-19 and isolation. Captain Over Engineering to the rescue. Why not just 3D print the roll itself, along with an attachment for the drill. I sketched it up to help with my thinking.

Maybe slots in the roll, and some kind of spoke things in the drill attachment. I made a design in OpenSCAD and printed a proof of concept.

It seems broadly feasible. My roll was a bit too thin, but the fit between the parts is good. Not too loose. Time to print the design at full size. A toilet roll is 10cm long, and 4cm in diameter.

With the roll a bit thicker (and so stiffer), the fit was tighter. I needed to sand the joints a bit.

I needed a way to spool the paper off the large roll easily. Luckily I still had some metal piping left over from my towel rail project. Add some chairs, and I'm in business.

Now it's winding time. I wondered how easy it would be to wind consistently. The tension is a bit tricky, but I didn't have any problems with side-to-side movement.

Cut the paper, and I have a bathroom-sized roll.

Now the end cap detaches until I'm ready for my next refill.

If you would like to print one yourself, the STL files (and the OpenSCAD source) are on Thingiverse at https://www.thingiverse.com/thing:4309439

March 09, 2020

Adding a second towel rail in the bathroom

My bathroom only has one towel rail. That's fine when there is only one person living here, but a bit inconvenient when there are two.

The company that makes the bathroom fittings do make a double towel rail, and you could probably get one for around $100. The down side is that they are very hard to find, and also the length is slightly different to the existing one. Once you had paid a tradesperson to tidy up the wall where they removed the old one, it is not going to be a quick job.

Enter the towel rail extension.

This is a bracket that attaches to the existing towel rail and allows you to attach a second one.

First you'll need a second rail that's similar to the first one.

This cost me $5.49 at Bunnings for a 900x19mm rail.

My existing rail is only 600mm so I needed to cut it to fit. This leaves a tube with open ends, so I designed and 3D printed some black end caps.

I worked out the angles and the rough design on paper, and then built it in OpenSCAD. I made the sizes customisable, so if you don't have the exact same diameter of tubing you can easily adjust it. The mock up in OpenSCAD looks like this.

I designed screw holes to put it together, and then I split the bracket into 3 pieces.

There's a piece that rests against the wall to hold the second rail in place. With the first 2 pieces attached it looks like this.

You can see the detail of how it is screwed together.

Now with 2 brackets in place I can fit my second rail and screw on the end pieces.

Works nicely.

If you are interested in making one you can see the design on Thingiverse.

Things I would do differently next time:
  • The angle is still not quite right. Making the wall pieces slightly shorter would work better.
  • I could incorporate an end cap into the bracket itself, rather than making it a ring around the second rail. That makes cutting the second rail to size more tricky though.
  • The bracket fits the existing rail just slightly too loosely. I would probably make it 0.5mm smaller, but it's close enough.

April 21, 2019

ePaper to display weather information

This project was to use an ePaper display to display weather information in my lounge room. Really it was an experiment to see what you could do with ePaper, because the ePaper module was an impulse buy while looking around Waveshare's web site.

The display module is a 4.2" monochrome display. Given I wanted this to connect by WiFi, it made sense to use their ESP8266 based driver board.

After connecting up the display to the driver, I powered it on to see the test mode. That seemed to work OK so I tried some code to display the current time.

You cannot really see from the photo, but the display is very thin. Thinner than LCD.

I had thought about designing and 3D printing a case for the display, but that's a bit above my Blender/OpenSCAD skill level. There are a couple of cool cases for similar boards on Thingiverse though.

In the end I repurposed a 6x4" photo frame. I cut a mask out of paper (just as a test), and it kind of looks OK.

The final version of the code has the time and date in the top left; the weather conditions in the centre left; the network status on the bottom left; and then the indoor and outdoor temperature on the right. You can see the source code (along with details on how it gets the temperature updates) at GitHubhttps://github.com/eb3nezer/mqtt_epaper

So of course now I have a photo frame with a micro-controller hanging out the back. I had a look around to see if anyone had designed a suitable case, but didn't see anything, so I ended up designing one myself.

I went through a few prototypes:

This is the final model:

The screw holes allow it to be mounted onto the stand of the photo frame:

If you are interested, the design for the case is available at https://www.thingiverse.com/thing:3576172

April 10, 2019

WiFi controlled fan - build

Warning: Home appliances have high voltages inside. Danger. Don't attempt a project like this unless you know what you're doing, and take appropriate safety precautions.

See also:
Inside of fan
In the picture above you can see the inside of the fan. Important components:
  • Rotary switch that used to control power to the motor windings (top left)
  • Capacitor to help motor start (black rectangle in top left)
  • Fan motor (behind the fan in the centre - the wires for the motor run up from the fan, obscured by the blade in this picture)
  • AC power cord (bottom)
  • 5V power supply (black rectangle in bottom left - 5V side not yet connected in this picture)
  • Relay board (top right)
  • NodeMCU board soldered to protoboard (bottom right - not yet connected to power supply or rotary switch)
Originally the capacitor was in the top right, but I needed to move it somewhere to make space.

Starter capacitor

This fan also had a mechanical timer switch in the top left. You could turn this, and it would supply power for (say) 30 minutes, and then disconnect the power.

Clockwork timer switch

I figured given this will be run by my home automation system I didn't need a clockwork timer any more, so maybe I could remove it, and move the capacitor there.

Out with the dremel tool. You know you're committed once you start chopping up appliances that were previously fully functional!

With the timer gone, now there was plenty of space to move the capacitor there. Fortunately the capacitor had a long-ish cable.

I needed to figure out how the existing wiring harness connected, plus I knew I would need to get AC power from somewhere. It was time to investigate what was behind these insulation bundles.

Removing the cable tie and the insulation revealed some crimp connectors.

Here brown is active and blue is neutral. I need to patch some wires in here to take AC power for my 5V power supply, so I'm going to need to take those connectors off.

I had a look in my tool box to see if I had any to replace them with, but I don't. Generally I don't trust crimp connectors, and so I solder them anyway. I added my wires to get an AC feed for my power supply, soldered the joins together, added heat shrink, and then put them back in their insulation bundle.

Then the other ends of those wires I added go to the AC in terminals of the 5V power supply.

Again covered with heat shrink, as I don't want any live wires hanging around. Make sure you don't solder to the wrong side of the power supply!

Here is the power supply back inside the fan.

It is loose for the moment, but I will hot glue it into the corner later.

Here you can see how the back of the rotary switch was connected. The connector on the bottom is the input (AC active), and the top 3 connectors are for the 3 different speeds. I tested which colour is connected for which speed so that I know how to wire up the relay outputs later.

The active wire previously connected first to the clockwork timer, and then to the rotary speed switch. With the timer removed I just joined the wires up in its place and put heat shrink over the join.

Now instead of the rotary speed switch, the active wire needs to go to the relay board to be switched on to each of the motor windings.

Here the active wire connects to the common terminal of the first relay, and then to the common terminals of each of the other relays.

The wires from the rotary switch to the motor were not quite long enough, so I needed to extend them, and then cover the join with heat shrink.

I had to buy a hair dryer for the heat shrink. I keep the hair dryer in the bathroom, but I should keep it in the tool cupboard, because I only ever use it for heat shrink.

Now to connect the motor wires to the relays.

Below the relays you can see the opt-isolators, diodes (to protect from back-current) and indicator LEDs.

The black wire goes to the oscillator motor, and then red for high speed, white for medium speed, and blue for low speed.

At this point all my AC wires are connected and insulated. (OK only mostly insulated. More on that later.)

Now it's time to connect up the low voltage logic wiring. I attached the NodeMCU board to some proto board. Although not necessary, I find this useful in terms of soldering.

Here you see red and black on the right to connect to +3.3V/0V for the relay board, and 4 wires for each of the logic level inputs to the board. (One each for oscillate, low, medium and high.)

Now to connect the other ends of the wires to the terminals on the relay board.

The relay board has screw terminals. The high voltage side was fine, but I kept having problems with the low voltage wires falling out. I ended up tinning the ends of the wires with solder, and this helped them stay in the screw terminals more securely.

I don't have the 5V power supply or the speed switch connected up yet, but it's probably worth doing a test to see that everything connects, and that I can still control the relays from inside Home Assistant. Prior to this I only tested the design on a breadboard.

While all my connectors are insulated, the underside of the relay board has exposed connectors from the through-hole components. Although I'm not connecting the AC here, I don't want any short circuits, so I improvised with some paper. (For the finished product I have some electrical insulation tape covering the under side of the relay board, with a layer of insulating foam covering that.)

At power on I get a power light on the relay board. So far so good.

The WiFi connect sequence for my code does a slow flash of the onboard LED while it connects to WiFi, and then quick flash while it logs in to MQTT. Once connected OK the LED goes off. All goes according to plan.

Now to test from Home Assistant. Power on, low power, and the low power relay clicks on! A test of the speed and oscillate combinations shows that the relays are working as expected!

Now to complete the wiring, I soldered wires to the 5V out of the power supply, and connected them to Vin and Ground on the MCU. Note that the NodeMCU board has an on-board voltage regulator, so a supply of more than 3.3V is OK for the Vin pins.

This is how the rotary switch looks.

The red wire goes to +3.3V, which connects to the terminal for high speed. Then a 1k resistor between high and medium, 1k between medium and low. There is actually another 1k resistor between the low terminal and the black wire, but it is hidden inside the heat shrink. I needed the voltage for low to be different to the voltage for off, so I didn't want low to connect directly to 0V. The orange wire connects to the "rotor" of the switch, which connects to the analog pin on the MCU.

Thus the resistors act as a voltage divider. The voltage on high speed is close to 3.3V, with less for medium, and less for low. I checked what reading the ESP8266 reads for each setting so that the code can determine where you positioned the switch, and if you changed it. Note that the ESP8266 itself wants a voltage between 0 and 1V for the analog pin, but the NodeMCU board lets you supply a voltage between 0 and 3.3V. This is handy, as the supply voltage is 3.3V.

You know what? I think I'm ready. Screw it all back together, for a test.

Be careful with AC wiring! We stood clear, turned on the power, and prepared for the release of magic smoke. With the smoke retained, I went to Home Assistant to try to get some airflow.

Thanks heaps to my assistant, and to the maker community at my workplace.

April 07, 2019

Wifi controlled fan - Design

A word of warning: If you proceed with making this project yourself, you run the risk of electrocuting yourself and dying. Fan motors use high voltages inside. More than enough to give you a serious shock.

See my previous post on what I'm trying to do, and why I chose this kind of fan.

My prototype circuit uses a NodeMCU ESP8266 board, and a 4-way 3.3V relay board to control the fans. The relay board should be able to safely switch the AC voltage your fan uses. (240V in my case.)

The MCU connects to the 3.3V relay board. The inputs for each of the relays connect to one of the digital data pins on the MCU. When the MCU sets that pin to high, the relay turns on. When the MCU sets that pin to low, the relay turns off. The relays will act in place of the original switch on the fan. Instead of sending power to the appropriate motor winding by turning the knob on the fan, the MCU will turn on the relay that connects to that motor winding.

My fan also has a switch for a little motor that makes the louvres on the front of the fan rotate, so I use the 4th relay to turn this motor on or off.

The fan is designed to work with my home automation system. I use Home Assistant, which includes an MQTT message bus. The code will connect to my MQTT bus and listen for updates, changing the relays as appropriate. Home Assistant provides a fan component that can send messages on MQTT to appropriate topics depending on the features of your fan. My code is written to support a fan that has 3 speeds ("high", "medium" and "low"), that can turn on and off (obviously), and that can turn the "oscillate" motor on and off.

My fan uses a 4-way rotary switch. (One of those settings is off, where it doesn't connect to anything.) My circuit diagram above shows 3 switches. How this actually connects will depend on what kind of switch your fan has, but you could mock up something on a breadboard to prototype.

Some fans have push buttons, where pushing one button in pops out any other button that was previously pushed in. In this case there are generally 4 buttons, where 3 of them connect to the 3 motor windings and the 4th button connects to nothing (for off).

The theory seems sound, so I ordered some parts.

These things are cheap and commonly available, but for the sake of illustration I have used Ali Express links.

I wired this up on a breadboard to test. Note that in this picture the speed control switch wasn't connected, so no 1k resistors.

The relay board needs +3.3V and ground from the MCU. I then connected the input lines on the relay board to digital output pins on the MCU. (If you were using an MCU based on a 5V system, like an Arduino, you could use a relay board that needed 5V, which are also readily available.)

Note that although the ESP8266 module runs on 3.3V, the NodeMCU board has an onboard voltage regulator. You can power the board from up to 12V pretty safely. I used a 5V power supply, knowing that this would work fine.

While prototyping I just powered the board from the micro-USB connector connected to the PC.

My ESP8266 code is available under a GPL 3.0 license. You can see it here: https://github.com/eb3nezer/mqtt-fan

Check out the README.md in the code to see what configuration changes you might need to make, depending on how you wire up your circuit. It also describes how the code will set up as a WiFi access point initially to let you complete the rest of the configuration via your web browser.

This is designed to work with Home Assistant, and so you need to add the fan component to Home Assistant. The configuration looks like:

  - platform: mqtt
    state_topic: "ha/boxfan/on/state"
    command_topic: "ha/boxfan/on/set"
    oscillation_state_topic: "ha/boxfan/osc/state"
    oscillation_command_topic: "ha/boxfan/osc/set"
    speed_state_topic: "ha/boxfan/speed/state"
    speed_command_topic: "ha/boxfan/speed/set"
    name: Box Fan

Note that the topics you configure in Home Assistant should match the topics you set in the web UI for the fan's access point.

Once installed in Home Assistant the control looks like this;

If you don't include the oscillation topics, then Home Assistant won't give you a control to turn oscillate on/off.

Time to test. Power on turns on the "high" relay. Change the speed to medium turns off the "high" relay, and turns on the "medium" relay. Turn on the Oscillate switch, and the oscillate relay turns on. Power off turns off all relays.

Success! Time to cut up a fan!

WiFi controlled fan - Options

My quest (spoiler: ultimately successful) to smart-ify a pedestal or box fan.

Spoiler: The finished product


I have a Xiaomi smart socket that could turn my fan on or off at the wall, and to be honest that's quite useful, but I wanted more. I wanted to be able to control the speed remotely as well. Fans are not that complicated right? It should be easy enough to modify the internals of a fan to support this.

My list of requirements:

  • The solution must work with a fan that is domestically available, and ideally not too expensive.
  • I need to be able to turn it on and off remotely, as well as control the speed remotely.
  • It should integrate with Home Assistant.
  • Ideally the existing controls on the fan should also work, so it can be controlled manually or remotely.
The first phase of this project was to find out how the speeds of these fans are normally controlled, and how they might be controlled by a micro-controller.

Pulse Width Modulation (PWM) for DC

For a fan that uses a DC motor, PWM might be a good solution. I'm planning on some kind of ESP8266 module as the MCU, and a circuit using the ESP8266's PWM output to switch a suitable MOSFET should work nicely. (I have used this approach for LED lighting in the past.)

While I'm sure they do exist, I looked around for a cheap fan with a DC motor, but didn't find one. I suspect this is partly because fans with 3-speed AC motors are cheap, very common, and they do the job.

If I were to find one, I would still like to build this kind of control. Your maximum speed is when your PWM is at 100% duty cycle. You'd need to do some testing to find out what your minimum duty cycle is for the fan you have. Below a certain minimum and you won't have enough torque to get it started.

PWM for AC

Dimmer circuits often use PWM, but you can't just vary the duty cycle at the 3kHz that your MCU supports. You need to vary it in phase with the AC (50 or 60 Hz). It is possible to get triacs that can switch higher AC voltages (240V for me).

I did explore this option a bit, but there were a few show stoppers for me:
  • Motors that have windings that suit this kind of control are not commonly used in cheap desktop cooling fans. (Common in ceiling fans though.)
  • In order to vary the duty cycle in phase, you need a circuit to detect when the voltage crosses zero, so you know when to turn your triac on and off. This is not such a complex circuit, but there's a high voltage side to this circuit, so a bit of extra care is involved. The former point was more of a problem really.

An AC motor with distinct windings

These kinds of motors are very common. The fan has a concrete number of speeds (generally 3). Each speed has its own winding inside the motor. The switch (or knob) selects which winding to supply power to.

Fan Motor Windings: Gene Haynes http://waterheatertimer.org/How-to-wire-3-speed-fan-switch.html
What if I swap out the speed switch for a set of relays (controlled by the MCU)? The relays would switch power to the windings. Then if I wire up the original switch as a voltage divider, I can get the MCU to detect the switch position by measuring the voltage. Thus the MCU can change the speed if someone moves the switch.

Sounds like a plan.

February 24, 2018

Adding WiFi to an LED strip

A while ago I saw a 5m roll of RGBW LED strip lights at Aldi. The pack included the 5m of lights, along with a 12V power supply and an IR controller for effects.

My reading online told me that it should be relatively simple to connect up some MOSFET transistors to an ESP8266 module so that the different LED colours could be controlled independently. The ESP8266 has WiFi of course, so with the correct software this should integrate easily with my home automation system (Home Assistant).

This post documents my build.

The LED strip was a special buy at Aldi, but there are plenty of products like this available. e.g. This is an Arlec one. It is 3m and has only RGB, but the concept is similar.

I found this great page on Adafruit describing a suitable circuit. https://learn.adafruit.com/rgb-led-strips/usage

They suggest using IRLB8721 MOSFETs. Their circuit is for an Arduino which uses 5V logic, but they suggest that these transistors switch on at about 2.2V, so they are fine for the ESP8266's 3.3V logic.

To test this I bought a few and set up a test circuit on a breadboard.

My test circuit used only the red channel, and my code used PWM to change the value of one of the pins every couple of seconds. The red LEDs got brighter and dimmer as expected.

Initially I had included a 5V voltage regulator chip. The ESP8266 board I'm using works fine with 5V, but I didn't think it would like the 12V that the LED power supply put out. As it turns out, this board can actually work fine with up to about 20V (it has its own onboard voltage regulator), so my final design omitted the voltage regulator.

The next step was to build something more permanent. I ended up using some prototyping board.

I bought a 12V barrel connector at Jaycar that connects to the original power supply that came with the LED strip. It connects to the Vin on the ESP8622 board. The digital outputs from the ESP8266 connect to pin 1 of the MOSFETs (the "base"). I used red, green, blue and white wire to remind me of which channels these will go to on the LEDs. If you only have an RGB strip, then you don't need the white channel.

Here is the completed board.

The negative wire from the power supply goes to pin 3 of the MOSFETs (the "emitter"), and then pin 2 of the MOSFETs (the "collector") goes to the LED strip. I re-used one of the joining connectors that came with the LED strip to connect them to my prototyping board. The end that connects to the LED strip is also hot-glued so it won't come unclipped.

If I had thought about it a bit more I would have put some kind of connector in the middle. The LEDs are going to be mounted on the skirting board in my lounge room, so this means the circuit board has to be right next to them. Oh well.

My software is a post in itself (coming soon). There are a couple of great examples of code for ESP8266 that uses MQTT to do PWM control for LEDs. I was able to enhance someone else's code to get something that works well.

For now, here's the final product in use.

I have a bit of an overrun on the right, which I have now trimmed to size.

I am very happy with the finished product. It integrates well with my home automation system (letting me set colour and brightness), and it is extremely reliable.

If you are thinking of making something like this yourself, on top of the LEDs and power supply you'll need:
  • ESP8266 module. I paid about AU$5 for mine.
  • IRLB8721 MOSFETs. These were about $2 each. You need one per channel, so for a single colour LED strip you only need 1. For RGB you need 3. For RGBW you need 4.
  • A barrel connector to suit your power supply. About $2.
Note that some LED strips that you can buy come without power supplies. It is probably worth getting some that come with a suitable supply, as otherwise finding a cheap 12V supply with a suitable current output might be difficult.