With an increasing number of hot days in the summer, I started to think about investing in an AC system. It is a proven solution, but on the other hand it can significantly increase my ecological footprint (and the electricity bill too). This made me think about alternative methods to cool down the flat.
Most people who do not use AC, deal with the summer heat by opening windows at sunset and closing them before the sun rises. This way they profit from the cold air outside at night and at the same time do not let the sun heat up the room during the day. I tried out this solution, and noticed three things:
- There is a real potential in this method, but you have to perfectly sync your schedule with the daylight.
- The collected temperature data showed that it is not the air that defines the temperature in the room after closing the window. It turns out that the heat capacity of everything that makes up your flat is so significant that it must be managed.
- After a few days of my absence, the flat was so heated up that I was not able to cool it down even after a full week of manual ventilation.
With those findings I came up with the simple conclusion: it is time to make it smart, by automating a window or a door leaf. To make it more effective – I decided to use the balcony door.
Since about that time Nordic announced the Smarter Sustainable World Challenge, I decided to take part in it and use the Thingy:53 as the brain for the system.
The ideaTo automate the door leaf, I will replace the handle with a 3D printed mechanism. Once the door leaf is unlocked, I would need a second mechanism to move it. To power both of those mechanisms I will use a single stepper motor, controlled by the Thingy:53.
To control the leaf in a smart way, data from two sensors will be collected:
- The Thingy:53 onboard temperature sensor, indicating the inside temperature.
- The second Thingy:53 or off-the-shelf Zigbee temperature sensor, indicating the outside temperature.
Regardless of the current temperature difference, I still want to use the balcony at my wish. For that purpose, I will use the Thingy:53 onboard button as a manual override.
To split a torque into two axis in such a way, that one shaft may rotate while the second is stationary, a special gear arrangement must be used. The most common one is the differential:
It is used in cars to propel both of the wheels from a single motor. The main problem with this arrangement is the housing for the gears, which cannot be easily 3D printed. The second option that I came up with is to use the planetary gear arrangement:
It is bigger than the first one, because the outer gear must house three other gears, but on the other hand the outer gear may be used as the wheel and all of the parts may be printed vertically without support structures. With no other, better ideas I decided to use this arrangement.
The second issue with the single-motor design is the fact, that it can move the handle only in the fully closed position. To solve it, I will add a spring (or rather rubber) loaded unidirectional mechanism that will deactivate once the door is at the fully closed position.
After initial tests I found out that the amount of force required to move the handle is so high (some of the designs were broken into pieces in the process), that a worm gear arrangement is necessary.
I decided to choose the 18650 Li-Ion batteries as the power source. They are commonly used in power banks, deliver a lot of instant current and capacity, but require a special care, such as protection circuitry.
To powered the mechanism with a NEMA17 stepper motor. This kind of motors are very common and accessible, because most of 3D printers use them.
I prepared the build in such a way that it accepted all 40, 48 and 60mm long NEMA17s, although the schematics presented in this post does not allow to get the full potential out of the 60mm motor.
Stepper motors require a lot of current to produce a torque, and thus a special stepper motor driver is required. I decided to use the low voltage STSPIN220 driver, because it can be connected directly to the motor and batteries on one side and to the Thingy:53 debug board on the other.
To connect all the things together I decided to use the 30AWG wire. It is thin enough to fit 5 pairs of it inside the 8mm wide aluminium tube. Since it was available only in two colors in my local shop: red and black, I decided to twist it into pairs to easily find the matching wires on both ends. To pass the higher current, the batteries are connected using two pairs of the wire.
The firmwareThe Smeeze device defines and implements several logical devices, attached to different endpoints:
- Endpoint 42: implements Zigbee Weather sensor, including temperature, humidity and pressure measurements
- Endpoint 43: implements Zigbee door lock, allowing to read the current state and overwrite the logic from the home automation hubs
- Endpoint 44: implements Zigbee FOTA allowing to update the device over the air
- Endpoint 45: implements a custom device, that allows to control the automatic door closing and opening remotely. It uses On/Off cluster to enable the automatic logic and Level Control cluster to set the desired room temperature. Although the Level Control cluster is not intended to be interpreted as the temperature, I found it easier to use it because it is well supported in most of the home automation hubs (in fact, the control logic is implemented in a dimmable light bulb device).
The firmware uses several pieces from the Nordic SDKs:
- Project structure and sensor readings from the nRF Connect Zigbee Weather Station application
- Battery level and status readings from the nRF Connect Matter Weather station application
- Zigbee FOTA support based on the nRF Connect Zigbee Light Sample application
- Door Lock device definition from the nRF5 SDK for Thread & Zigbee
It also extends the device definitions and adds several new features:
- The new stepper motor driver (see appendix for more details)
- The new LED library, for indicating the Zigbee connectivity and device status
- The sensor finder library for discovering the external sensor, based on the Zigbee Finding & Binding procedure
- The power config cluster to monitor the current battery level
The source code for the Smeeze application can be downloaded from my GitHub fork.
The print time!All of the CAD files with the print parameters can be found in the attachments. It is wise to plan the printing ahead - it takes around 25 hours and over 300g of filament is needed.
For the filament I advise to use PLA or PETG for all parts, except for the tire. The latter should be printed using flexible materials or simply replaced with a few layers of sticky, self-fusing tape. The tape option is highly recommended if you have a slippery floor.
The build time!The device consists of two parts - the bottom one that propels the door leaf and the top one that works as a handle replacement.
To guide you through the process easily, I prepared an assembly sketch, that shows how the parts will eventually come together:
Step 1: Secure the 18650 batteries.
The 18650 Li-Ion batteries are usually sold without protection circuitry. However, to make this build safer, I strongly recommend to supplement them with a protection circuitry.
The protection circuit usually consist of:
- PCB with the protection logic
- Plastic disk
- Nickel belts
- Heat shrinkable tubes
The assembly process is fairly simple and should be described in the product documentation. In my case I had to:
- Solder the nickel belts to the PCB.
- Wire the belts through the plastic disk.
- Cut the negative belt to the battery diameter and put the positive one around the battery.
- Tape the metal cap to the positive end.
- Secure everything with a heat shrinkable tube.
- Heat the tube with a low temperature - it is important to avoid overheating the batteries.
Once assembled, the batteries will be connected in parallel, so it is very important to fully charge them now. Connecting two batteries with a different capacity (and voltage) will result in a huge current draw, which may produce excessive heat.
Step 2: Prepare the wires
To organize the wires and make them distinguishable, I decided to twist them in pairs. As a bonus - twisted wires do not tangle with each other that much, so I suggest twisting them even if you have wires with a higher diversity of colors.
Please prepare the following twisted pairs:
- The "battery power supply" pair: 2x red + 2x black
- The "power control" pair: 1x red + 1x black
- The "micro-stepping" pair: 2x red
- The "motor control" pair: 2x black
To make the twisting faster and easier - I used an electric drill (see pictures above).
Step 3: Assemble the power supply
To accomplish this part, you will need:
- The 16_smeeze_drive_battery.stl 3D printed part
- Two, single-cell 18650 battery cases
- The STSPIN220 stepper motor driver
- The "battery power supply" twisted pair
The build process has the following steps:
- Put the battery cases inside the 3D printed part. Guide their wires through the smaller hole. Pay attention to the polarity - the same pole should be at the same side.
- Guide the twisted pair thorough the larger hole.
- Solder all wires with the same color (polarity) together.
- Solder the red wires to the "VMOT" input and the black wires to the "GND" input of the STSPIN220.
Step 4: Solder the motor driver
To accomplish this part, you will need:
- Remaining (3) twisted pairs
- NEMA17 stepper motor
The build process has the following steps:
- Guide all twisted pairs through the larger hole.
- Solder the "power control" pair: red wire to the "VCC" input and black wire to the "nSTBY" input pad.
- Solder the "micro-stepping" pair: you should use the "M1" and the "M2" input pads.
- Solder the "motor control" pair: you should use the "DIR" and the "STEP" input pads.
- Solder the stepper motor wires: keep in mind that the "A1" and the "A2" input pads should be connected to the same coil (and the "B1" and the "B2" other one). Please use the multimeter to verify the wiring of the motor (a single coil should have resistance lower than 10 Ohms).
- Secure the other end of the "battery power supply" pair - we are going to guide it through an aluminium tube, which can easily shorten the wires.
- Prepare all wires for further guiding by puling them on the motor driver side and securing the other ends with a single, shorter but stiffer wire.
Step 5: Assemble the wheel
To accomplish this part, you will need:
- The 6x100mm aluminum tube
- The 02_smeeze_drive_tire.stl 3D printed part
- The 04_smeeze_planetary_ring.stl 3D printed part
- The 05_smeeze_planetary_sun.stl 3D printed part
- Three times the 06_smeeze_planetary_planet.stl 3D printed part
- The 07_smeeze_washer_6mm.stl 3D printed part
- The 08_smeeze_planetary_output_pins.stl 3D printed part
- The 09_smeeze_planetary_output.stl 3D printed part
- A paper clip
As the preparation task, please cut the pipe as shown in the image above and drill all of the necessary holes (4) with a 1.5mm drill.
The build process has the following steps:
- Insert a paper clip through the first hole on the right, turn it around and cut with pliers, so that it makes a nice end stop for the gears.
- Insert the tire onto the planetary ring.
- Insert the tube into the planetary ring.
- Prepare a location-lock with a paper clip: fold one end into a parallel pin, cut it around 7mm below the fold.
- Insert the pin into the second hole inside the pipe.
- Slide in the sun gear and lock its position by the inserted pin.
- Slide in the distance ring.
- Glue the solar output disk pins into the solar output disk.
- Put all three planets onto the solar output disk pins with the embedded distance disks facing up.
- If available, add some lubricant onto the gears and slide the output disk onto the tube.
- Move all gears to the edge and verify if the planetary output gear can rotate freely and the tube is not blocked.
Step 6: Assemble the unidirectional locking mechanisms
To accomplish this part, you will need:
- A small rubber band
- A piece of 30AWG wire
- A 30mm long M3 bolt with a nut
- The 10_smeeze_drive_ratchet.stl 3D printed part
- The 15_smeeze_drive_base.stl 3D printed part
The build process has the following steps:
- Make a small loop from the wire.
- Insert the wire between the side of the base and the 3mm through-hole support block (see image above).
- Insert the rubber band from outside, through the wire loop and through the support block. Grab and hold the rubber band from the bottom and pull the other end of the rubber band using the wire.
- Connect both ends of the rubber band using the wire.
- Insert the ratchet into the slot inside the base.
- Secure the ratchet using the M3 bolt.
- Load the ratchet with a rubber band by pulling the ends with a wire and placing the rubber band loops on top of the flat area of the ratchet.
Tip: since from now on it will be harder to reinstall the rubber band, it is a good idea to keep the wire attached through the entire build.
Step 7: Assemble the base
To accomplish this part, you will need:
- Previously assembled parts
- The 12_smeeze_drive_output.stl 3D printed part
- The 13_smeeze_washer_8mm.stl 3D printed part
The build process has the following steps:
- Slide in the base onto the battery holder from the side with the batteries.
- Pinch the wire with twisted pairs through the hole inside the base and pull them through the hole.
- Guide the "pilot" wire through the hole at the bottom of the support block in the middle of the base and through the 8mm hole (see pictures above).
- Pull the twisted pairs.
- Slide in the 8mm distance disk onto the twisted pairs.
- Slide in the 8mm bevel gear onto the twisted pairs.
- Guide the twister pairs through the 8mm hole outside the base. The bevel gear and the distance disk should snap into their place between two support blocks.
- Push the stepper motor driver and the excess wires into the pocket.
- Secure the stepper motor with M3 bolts. You may use the 4.5mm access holes at the front or the allen key to accomplish this task.
Note: images illustrating this step show a planetary wheel already assembled. I definitely advise not to make this mistake - adding the planetary wheel will prevent you from using access holes intended for securing the stepper motor.
Step 8: Install the planetary wheel
To accomplish this part, you will need:
- Previously assembled parts
- The 03_smeeze_drive_plug.stl 3D printed part
- The second 07_smeeze_washer_6mm.stl 3D printed part
- The 11_smeeze_drive_bevel.stl 3D printed part
- The remaining part of the paper clip
The build process has the following steps:
- Slide in the bevel gear between the side and the support structure.
- Slide in the planetary assembly into the base, through the bevel gear (see pictures above).
- Slide in the 6mm distance disk onto the aluminium tube.
- Create a double sided locking mechanism with a paper clip (the same way as it was done at the beginning of the step 5).
- Glue a plastic cap at the end to hide the pipe.
Step 9: Attach the main tube
To accomplish this part, you will need:
- Previously assembled parts
- The remaining part of the paper clip
- The 1000mm long 8mm wide aluminium tube
- The M2 tap
- The M2 bolt
- Heat shrinkable tube
To prepare for the build process:
- Drill two holes at the ends of the 8mm tube (see picture above).
- Drill the third though-hole for locking mechanism.
- Tap both holes.
- Prepare the M3 insert: screw-in the bolt and cut it roughly 1mm above the surface of the tube. The screw should not stick out inside the tube - the clearance is necessary to guide the twisted pairs through the tube.
- Prepare the M2 insert for the other end.
- Glue in the M2 insert that is further from the third hole.
The build process has the following steps:
- Add a heat shrinkable tube to protect all of the twisted pairs. The idea is to provide an extra reinforcement for the wires around the M2 inserts.
- Slide in all the twisted pairs to the 8mm tube from the side with two holes.
- Slide in the tube into the base, through the support hole, output bevel gear and 8mm distance disk.
- Screw in the M2 insert between the distance disk and the bevel gear.
- Glue the distance disk onto the bevel gear. After this step it should be impossible to rotate the 8mm tube without rotating the bevel gear assembly.
- Add a locking mechanism, made out of a D-shaped paper clip piece on the outside of the base. After this is done, it should be impossible to push the tube into the base and disconnect the bevel gear from the M2 insert.
Step 10: Finalize the first part
To accomplish this part, you will need:
- Black nail polish
- Double sided, thick tape
- The 01_smeeze_drive_lock.stl 3D printed part
- The 17_smeeze_drive_case.stl 3D printed part
The build process has the following steps:
- Paint the inside of the "smeeze" logo with nail polish.
- Clean the edges using a knife or a file.
- Slide in the case onto the base.
- Fill the back of the base with lines of double-sided tape.
- Fill the back of the locking mechanism with lines of double-sided tape.
- Glue both parts onto the window leaf. The base should be on the moving leaf and the locking mechanism on the stationary one.
Congratulations! You have just accomplished assembly of the first, more complex part!
Before we will go into details of the build process of the handle replacement, please take a look at the assembly sketch:
The handle replacement is the part that will be easily detachable, allowing you to make all sorts of adjustments.
Step 11: Assemble the door handle pin
To accomplish this part, you will need:
- The ball bearing (see parts list for details)
- The 21_smeeze_handle_pin.stl 3D printed part
- The 20_smeeze_handle_worm_wheel.stl 3D printed part
The build process has the following steps:
- Press in the bearing into the worm wheel. The bearing should be flush with the most slippery side of your print and stick out approximately 1mm on the other side.
- Glue the pin with the worm gear. Use the bearing as the locating pin. Make sure that the bearing rotates afterwards.
Step 12: Replace the door handle
To accomplish this part, you will need:
- The previously assembled door handle pin.
- The 19_smeeze_handle_worm_gear.stl 3D printed part
- The 22_smeeze_handle_base.stl 3D printed part
The build process has the following steps:
- Open the door.
- Rotate the M5 bolts cover, unscrew them and remove the handle.
- Attach the door handle replacement base using the M5 bolts.
- Insert the worm gear into the slot.
- Insert the assembled pin. Keep in mind that it should be properly aligned with the mechanism inside the leaf to be fully inserted.
Step 13: Attach Thingy:53
To accomplish this part, you will need:
- All previously assembled parts
- Heat shrinkable tube
- The 18_smeeze_handle_input.stl 3D printed part
- The 23_smeeze_handle_lid_thingy.stl 3D printed part
- The 24_smeeze_handle_lid_wires.stl 3D printed part
- Three M3, 15mm long bolts with nuts
The build process has the following steps:
- Guide twisted parts through the drive connector part and slide it onto the aluminium tube.
- Add a heat shrinkable tube on the twisted pairs to protect the wires.
- Guide the twisted pairs through the worm gear and the support structure inside the handle replacement base.
- Insert M3 nuts inside the slots and mount the larger top lid with three M3 bolts.
- Slide in the second, smaller top lid and guide the wires underneath.
- Attach Thingy:53 with a double-sided tape.
- Cut the twisted pairs to the proper length and solder them to the Thingy:53 debug board (see the schematics in the previous sections of this post for details).
- The "battery power supply" pair: connect both red wires together and attach them to the first pin of the first 2-pin connector of the debug board. Connect the black wires together and to the "GND" pad.
- The "power control" pair: connect the red wire to the "VDD" pad and black wire to the "12" pad.
- The "micro-stepping" pair: connect them to the "10" and "11" pad.
- The "motor control" pair: connect them to the "4" and "5" pad.
Step 14: Install FW on the Thingy:53
Using one of the available methods, transfer the zip distribution file onto the Thingy:53.
The Thingy:53 should start slowly blinking with the red LED indicating that it searches for an opened Zigbee network. Once pressed, the blue LED should lit up and the stepper motor should start to move the door leaf!
Congratulations! You have completed the whole build!
See it in action!Appendix: Controlling the motorMy first attempt to move the leaf by applying PWM signal to the motor driver was not successful – the motor started to squeak and the leaf did not move even a tiny bit. This issue was solved when I changed the PWM signal frequency to very low value. This reminded me of the second Newton’s law:
From the equation above we we can conclude that if you can push the leaf with the limited amount force F produced by the drivetrain, and it does not fall apart (the mass m does not change), there is a limited acceleration a that it can have.
In other words, it is incorrect to assume that the door leaf can accelerate instantly to any desired velocity, defined by the PWM signal frequency, because the motor can generate only a limited amount of torque.
With that in mind, I started to look for a suitable driver in the nRF Connect SDK. Unfortunately I was not able to find one, so I decided to write one on my own.
Due to the limited maximum allowed acceleration, the new driver should split the door movement into three phases:
- Gentle acceleration at the beginning
- Constant movement close to the desired position
- Braking, with the full stop at the programmed position
The main challenge here is the fact, that there is no way to pass the acceleration value to the stepper motor - it is controlled only by the time between the steps, called interval i.
With each step, the motor moves a fraction of a degree (usually 1.8 or 0.9 degree), that after all of the gear arrangements will result in a movement d of the leaf.
The path that the leaf will pass can be calculated as the area below the v(t) graph.
This gives us the following formulas for the distance in the uniformly accelerated and decelerated motion:
The acceleration is defined as the change of the velocity over time:
which means we can rewrite the formulas for the distance as:
If we know the current velocity v, there is only one variable left in the formulas above – the time t, which is the unknown interval, after which the stepper should reach the next distance d.
After moving all parts to the left side of the equation, we get the following quadratic equations:
The quadratic equation has two roots if the discriminant has a positive value. Let’s take a look at these conditions:
for the accelerated movement, both v and a are positive, thus this condition is always satisfied.
For the decelerated movement, it is satisfied only if:
After dividing both sides by 2 and multiplying by positive interval t we get:
If we look closely at the transformed condition, we can understand when this condition is not satisfied:
- the left side represents the path that the leaf will make if it comes into a full stop after time t, while moving with a uniformly decelerated motion, starting from the velocity v
- the right side represents the path, that the leaf will make while accelerating from the full stop in time t in a uniformly accelerated motion
It means, that this describes the situation, in which the leaf should stop in the middle of the interval t. In such situation it should be completely safe to hit the breaks and set the interval to zero.
Now let’s try to understand the meaning of the possible roots of the equation.
For the accelerated movement there are two points on the time axis that meet the distance requirement:
One of them is negative, thus can be discarded.
For the decelerated movement, the condition can be met for two positive intervals:
Since the root with a larger value points to a negative velocity, it can be discarded.
In all cases, the velocity after moving by a single step will be equal to:
Comments