It's Summer and you just came home from a tough and hot day so you throw your bag on the ground, lay down on the couch, get your phone out, scroll endlessly through your social media feed and chill a bit. Suddenly you notice that it's getting hotter and you need a fresh breeze but you made yourself comfortable and you're too tired to get up and open the window. You wouldn't sacrifice comfort for fresh air right ? Yeah, neither would any of us. Wouldn't you have wished that you could just open an app from your phone, press a magic button and your window gets opened?
What if we told you that you wouldn't have to sacrifice comfort for fresh air and that the sacrifice stops today? You don't believe me?
Check out this GIF and see for yourself. ( PARTY POOPER: The window is not that fast in real life)
So, do you believe us now? Well, you better do, because we're about to explain to you how you can build this thing. We know what you're thinking, if I'm too lazy to just get up and open the window myself, then I'm definitely way too lazy to make a whole Smart-Window Opener. From experience We can tell you that lazy people tend to come up with the smartest ideas to get even more lazy on the long run (for my fellow investment bankers, this project has a high ROI (Return on Investment) in laziness right here).
So be smart (just like this window), be lazy and let's build this thing together!
2) Overall conceptTo give you an overview about the overall concept:
This project is divided into 3 basic aspects:
- Lock/Unlock mechanism - Moving the window handle in a position to open/close the window
- Open/Close mechanism - Opening and closing the window
- Communication/Control - Techniques to be able to communicate and control the mechanism
Now we will refer to these three topics when describing hardware or software parts.
For our test window we used a home-made window frame which won't be covered within this article.
3) Prepare the programming environmentsWe don't want to bore you with some quotes, but a wise man once said: "..preparation is the key to success" , then he went on and invented something called the telephone, does that ring a bell? Anyways the telephone is obviously not as awesome as this Window Opener but let's just listen to him and prepare ourselves first.
We need a working Arduino IDE which you can get from here.
Then pay a visit to this GitHub repository, you will find some basic information about the XMC1100 Boot Kit. Additionally this repository shows you how to implement XMC microcontrollers into the Arduino IDE which we will need later. Please also make sure to install the corresponding J-Link software mentioned in the Github page.
Assuming that you have a running Arduino IDE with an implementation of the XMC microcontroller family, please go ahead and download the Modus Toolbox to program the Psoc 6 Prototyping Board.
HINT: When importing an example project please select TARGET_CY8CPROTO-062-4343W as target.
4) So long good ol' handleAfter giving you an overview of what you'll be going through to get the job done, let's get down to business!
We start off with the window handle replacement, the Lock/Unlock mechanism. We will explain the used hardware, software and mechanical parts that are necessary to build this mechanism.
In general we use the TLE493-W2B6 3D-magnet sensor connected to an XMC2Go for the angle measurement of the Lock/Unlock big gear to position the gear in the way we want so we can e.g lock the window, fully unlock the window or just to partially-unlock it. You can find more details about how generally angles are being extracted from the 3D Sense Shield2Go in this Protip.
These actions depend on the simple inputs of the two digital lines coming from the XMC1100 BootKit of the Open/Close mechanism (labeled as D1, D2 in pic 4.6 below). The controller then interprets the incoming data and then moves to the corresponding position.
Once an action is completed, the XMC2Go sets its third cable (labeled as D3 later in section 6) connection to HIGH so that the XMC1100 BootKit knows the current state.
The XMC2Go controls the H-Bridge depending on these values via 2 digital connections. One of them defines the rotation (rotpin) and the other one starts and stops the motor (startpin)
4.1) Printing and AssemblyTo implement the concept described above you can start out by printing these parts for the Lock/Unlock mechanism of the project from the attachment section:
- Lock/Unlock Base Plate
- Lock/Unlock Big Gear
- Lock/Unlock Small Gear
- Lock/Unlock Closure V2
After succesfully printing the parts listed above let's assemble them and mount them on the window instead of the old school handle, because who needs handles these days, right?
First of all remove all the screws from your lame old window handle, throw the handle away if you want but keep the screws because, we don't want to screw this up, get it? (We're kidding don't throw the handle away)
Anyways, use these same screws to mount the Lock/Unlock Base Plate on the exact same spot where the old handle was on the window (see pic 4.2 below).
PARTY POOPER: In some cases your window might have different handle dimensions, i.e the space between the holes on the window might not match the space between the holes from the Lock/Unlock Base Plate. In this case you have to modify the .stl files to go with the dimensions you have. (If you're a beginner in 3D Modelling, TinkerCad is a free online and very simple tool which you can use -at your own risk- to adapt the dimensions)
After succesfully mounting the base plate on the window, the next step would be to insert the Lock/Unlock big gear into the hole, where previously the axis of the window handle was located. After that, place a small cylinder magnet with a radius of 3mm and a height of approx. 15mm. Please make sure its properly inserted and also of its polarity.
HINT: You can use the TLE493D-W2B6 to sort of "guess" the polarity of your cylinder magnet. Read out the values from the Serial Monitor of the Arduino IDE later on and if the changes of the angle values are accurate enough, then you're good to go!
Then use three M3 screws to attach the motor to the Lock/Unlock base plate and fiddle the Lock/Unlock small gear (See pic 4.2 and pic 4.4.3) onto the motor axis coming out from underneath.
Lastly, you want to glue the TLE493D-W2B6 Breakout to the Lock/Unlock Closure V2 and attach it to the base plate with the four M2 screws you've inserted in the previous step. Please make sure that the previously placed magnet aligns properly with the magnet sensor for optimal angle detection.
After you've completed these steps, the Locker/Unlocker should look something like this (see also pic 4.4.4 above) :
If you want to be more organized and neat, you can print out the following files:
- Lock/Unlock Closure V2
- H-Bridge Base Plate
- H-Bridge Cover
You can mount the H-Bridge on the H-Bridge Cover and glue the H-Bridge Base Palte to the frame of the window. It is possible to hide the cables inside the assembled H-Bridge-Housing. Due to the new version of the lock closure (Lock/Unlock Closure V2) it is also possible to organize the cables along the closure (see pic 4.7.1).
4.2) Wiring Diagram and ElectronicsBy the way the fritzing file is located in the attachent section and there's also a picture of the whole wiring diagram in the attachment section as well.
We know what you're thinking: "ahhh...too many wires and ahhh no one said anything about resistors... ahhh this is way too complicated" Calm down, now is not the time for fear, that comes later!
This extra circuit board is necessary as the I2C protocol, which the TLE493D-W2B6 uses to communicate with the XMC2Go, needs a pullup resistor on both the SCL and SDL lines - that's all.
Please connect the devices as shown in the schematic above (pic 4.6). The H-Bridge on the top left connects to the 11V supply voltage, the motor and the yellow cables represent the start and rotation pin (startpin, rotpin) mentioned earlier. The XMC2Go is connected to the circuit board with the resistors as well as the previously mentioned D1, D2 and D3 lines.
As described please make sure to align the parts on the Lock/Unlock covering to ensure correct wire length.
As you can see from the caption it's time to run, but not actually run, it's time to run the code on the Microcontrollers we have.
In order to do so, use the Arduino IDE and the sketch "HBridge2GoUnlocker" from the attachments section. Make sure to select the Board as "XMC1100 XMC2Go" from the Arduino IDE and that you've selected the correct USB-Port and also double-check the pins in the sketch, will ya! Thanks
Then do the same with "XMC2Go unlocker" on the XMC2Go board.
In case you prefer to use different pins, you can have a look at the pinout for the H-Bridge 2Go here, and look for the corresponding Arduino pin.
5) Open SesameNow, that you have successfully assembled the Lock/Unlock mechanism what's left to do (mechanically) is to assemble the Open/Close mechanism.
We already gave you an idea earlier of how this should work , you should press a button on your phone, which is communicating with the PSoC6 Board connected to the XMC1100 BootKit. This gives the signal (via D1,D2 from the XMC1100 BootKit to XMC2Go) to partially open, fully open, close the Lock of the Window. The D3 wire gives away the status if an action is completed. Now, what should happen is, that the XMC1100 BootKit with the BTN8982 DC Motor Control Shield on it should start the motor and the window should start opening. As the window is opening we get feedback of its position from another XMC2Go-TLE493D-W2B6(Breakout) Combo. This is why we insert some magnets in the long Rod that you've probably noticed (pic 2.1).
Anyways enough talking, let's start acting!
5.1) Printing and AssemblyTo enable both the opening and tilting of the window, we created a combination of a bar connected to a knuckle as you can see in the following picture. This bar is connected to a suspension which can be moved along the bar by a DC motor attached to a gear.
Here comes the fun part: Open up Netflix,Hulu,Disney+ or any (legal) streaming website and prepare some movies to watch or a small TV Show to binge, because it's probably going to take some time before these following files (from the attachment section) are printed out:
- Open/Close inside joint
- Open/Close outside joint
- Open/Close guide beginning
- Open/Close guide end
- Open/Close guide
- Open/Close rack
- Open/Close rack start
- Open/Close magnet slide
- Open/Close gear
- Open/Close guide wheel
- Open/Close guide wheel axle
- Open/Close motor mounting
- Open/Close board plate
- Open/Close window clamp
- Open/Close guide wheel mounting 2x
Long list huh? Good luck to the 3D printer thats gonna print out these files.
"Are you still watching?" If yes, finish off your episode/movie and let's start assembling this thing together!
Below is the CAD representation with a following step by step guide:
HINT: Make sure that the M3 screws do not hinder the joint and that they are not too tight. Please use Open/Close inside joint and Open/Close outside joint for the following assembly
To fix the joint use strong glue or screws. For testing purposes a double sided tape is sufficient.
1) Insert four M3 nuts into the Open/Close motor mounting and the Open/Close back plate.
2)After that, insert two M3 screws into the lower two wholes where previously the nuts where placed.
3) Now mount the motor with five M3 screws (3) on the Open/Close motor mounting (leave the one close to the magnet sensor blank).
4) Attach the Open/Close gear and fix the magnet sensor with glue.
Did we lose you ? Stay with us, we still need you!
5&7) The left hand side is a little bit more difficult. Use screws or the provided plastic print (Open/Close guide wheel mounting) to mount the axis (Open/Close guide wheel axel) of the wheel.
6) As a spring is needed (get it from here), slide it over the screw whilst pushing the screw in. If it is of proper length and the Open/Close guide wheel axle is on, the spring won't jump out on its own.
8) After that put the wheel (Open/Close guide wheel) in.
9) Then insert the screw and spring as done previously. In order to have a smooth tilting experience make sure to use strong springs otherwise tilting might not be possible.
10) The body may be screwed to the window by boring a hole with the same diameter into the window. Or you can use the claws can be used to mount the contraption on top of the frame.
After surviving those 10 steps you should have something that looks like in pic 5.3.1
This procedure is followed by attaching the plate containing the Boards (Open/Close board plate) (pic 5.3.1-5.3.2).
The Boards are attached with four M3 screws (XMC1100), and 2 M2 screws (Psoc6) as shown in pic 5.3.3.
Then we move on to the the rack assembly is described in the following.
Use two M3 screws and corresponding nuts. The rod is held in place with several M2 screws with corresponding nuts.
The nut slides in place at the rail containing the magnet holes (more about that shortly). Due to that, make sure that they are still slideable and aren't blocked by the nuts not fitting into place.
Tired yet? If you've assembled the rack and the body of the Open/close mechanism then you can probably see the light at the end of the tunnel, stay with us!
Make sure that the Open/Close guide only covers two holes as shown in the animation above. Start by using the Open/Close rack start and increase the length of the rod by repeating the step that is shown and using the Open/Close rail instead. The uncovered holes at the beginning of Open/Close rack start and the end are covered using Open/Close guide beginning and Open/Close guide end respectively. We use M2 screws for the rack.
Now Connect the Joint and the rack (Open/Close inside joint and Open/Close rack start to be precise) using an M3 screw as shown in the picture below. Again please make sure that the rack can tilt freely. The picture shows the bottom side of the rack, meaning the rail in the rack containing the magnetic slides is facing downwards.
Additionally we added three magnets (pic 5.6.1) into the bar (in the holes we've talked about earlier) to be able to detect the exact location of the window and to keep track of its condition whether it is opened, closed or tilted (Open/Close magnet slide).
HINT: You can also do the same as you did with the magnet from the Lock/Unlock mechanism earlier, where we guessed the polarity based on the readings we got from the TLE493D, if they were accurate enough then you're good to go!
On the left hand side of the magnet slide is space for a tiny M2 screw to fix the slide in place however as the dimensions are designed to fit tightly it can be used to move this slide in the rail. On the right hand side is a bucket where the magnet can be placed. Magnets can also be crafted to fit in this space but make sure that their magnetic fields can still be detected from the TLE493D-W2B6 (several mT).
5.2) Wiring Diagram and Electronics...Again!Our fellow mechanical engineers can relax now because here comes the electrical part!
As we defined all needed components for now we can proceed with the wiring.
Take care when soldering the parts and keep in mind that wires that are too long can cause issues within the I2C connection, so keep those wires as short as possible!
We know you love challenges, so here's another one, which is the different levels between XMC1100 Boot Kit (5V) and 3D magnetic sensor TLE493D-W2B6 (3,3V) PSOC6 Wi-Fi BT Prototyping Kit (3,3V) or XMC2Go (3V3). This can be solved either by desoldering the 0 Ohm resistor close the 5V Pin and soldering it onto the connection dedicated for 3V3 use.
You can also apply proper voltage level shifting (at your own risk). to double-check the voltage provided you can upload the blink example sketch, change the Led Pin from 'LED_BUILTIN' to 3, and measure the voltage of the pin. Don't forget to choose the right board, in this case the XMC1100.
ATTENTION: XMC 1100 in 3.3V mode is not swappable with an Arduino Uno!
As for the DC Motor, it requires a voltage of 12V so a Step Down Buck Converter comes into play to get the required 3.3V.
The following circuit layout shows the wiring of all components, that are related to the Open/Close mechanism (pic 5.8).
DISCLAIMER: The BTN8982 is designed to be plugged directly into the BootKit (Get an overview on its protip here). So you just have to connect the OUT1 and OUT2 to the DC Motor and you're good to go.
REMINDER: if you want to have a better look, navigate to the attachments section you will find the fritzing file there and a pic of the wiring diagram as a whole!
The communication between the PSOC6 Wi-Fi BT Prototyping Kit and the XMC1100 Boot Kit is established by using the UART protocol to be able to display sensor data. Do not forget about the pullup resistors (1.5kOhm) and wire resistance (47Ohm) on the I2C lines on either side. The setup is similar to the one used previously. The three incoming yellow lines (XMC1100) are the ones from the Lock/Unlock mechanism (D1, D2, D3).
This is what it should like before without the rod and before mounting the PSoC 6 Board.
DISCLAIMER: You may notice in the picture below that the wires between BootKit and Cypress PSoC6 Board do not match the wires in the Fritzing photo above. The Fritzing picture is the updated version that works with the codes attached.
You can also print out the following file: "Open/Close XMC2Go Clip" so you can easily hang the XMC2Go on the left as you can see in pic 5.10.2.
In order to not get a messy look because of all the wires hanging around, you can print out the files in "Cable Cover", mount them along your window frame and hide the wires inside them.
After some cable managment and after everything gets screwed into place
you should have something that looks like this:
VOILA! There you have it folks! There's your fully built bad boy, doesn't he look cute ?
Now our fellow electrical engineers can rest and the computer freaks can come in, because we're about to switch to the soft(ware)-side, get it? Not really? Anyways...
First let's do some calibration. The magnetic field detection of all the magnets used in this project is done with the help of the TLE493D-W2B6. It is also able to detect these different states (fully open, open tilt) because it features a 3 dimensional measurement of the magnetic field (x, y and z). This feature can be used to measure the position of the magnets. For example you could use the following three positions:
- North-South axis in line with the bar
- North-South axis in line with the bar - the other way around
- North-South axis vertically to the rail.
Please adapt the values of the code in line 88 (TLE493D-W2B6-Sensor.ino) depending on the strength and orientation of your magnets.
if(sensorValueX > 4.0 && sensorValueZ < 4.0)
For improved detection the motor speed is decreased if the amount of the vector (x, y and z magnet values) surpasses a certain threshold. It is set in the line 82+ to 3mT, you can change this as well if you want:
if(normSensor > 3.0) {
digitalWrite(SPEED_PIN, HIGH);
}
else {
digitalWrite(SPEED_PIN, LOW);
}
Now everything should be set up and we shoud be able to dive into the programming part. First upload the sketch "XMC1100 open/close" to the XMC1100 and also the "TLE493D-W2B6-Sensor" to the XMC2Go using the Arduino IDE.
After that please download the example provided by Enrico Migilino and replace the source and header files with the ones provided in the attachments. Make sure to edit the following headers: mqtt_client_config.h set IP address of broker (depending on the setup username and password), wifi_config.h SSID and password according to the setup. If you do not have a broker setup then please look into section 6. Use the KitProg3_MiniProg4 Launcher to compile and upload whilst the board is connected.
The flow of the Communication between PSoC6 and XMC1100 BootKit looks like the following:
The PSOC6 subscribes to a topic called "SmartWindowOpener/control". The Client (setup in section 6) sends various messages defined in the XMC1100 Boot Kit .ino file (XMC1100 open/closing) for example "opentil". The XMC1100 Boot Kit deals with these messages and every 5 seconds sends a string composed of the current magnet sensor level in the format xvalue:yvalue:zvalue:tmpvalue
or an error/log message starting with ":" and then the error message. The PSOC splits on the delimiter (specified by MQTT_UART_VALUE_DELIMITER, if changed please change it in PSOC6 as well!) and publishes them to corresponding topics defined in mqtt_client_config.h.
Last but not least a raspberry pi using the Raspberry Pi OS is needed to setup the communication between Phone and PSoC 6. Here there are several options either:
- An mqtt infrastructure already exists then this step can be skipped entirely
- There is already an existing router, in this case RaspAp does not need to be configured and the SSID and PWD of the router should be used.
Please install RaspAp and configure it. Secondly install the Mosquitto server and enter the ip-adress of your server and the SSID and PWD of RaspAp into the corresponding header files of the PSOC6 (PSOC6 - headers/wifi_config.h, PSOC6 - headers/mqtt_client_config.h). Thirdly install the preferred HomeAssistant setup, setup the mqtt extension (localhost and default port 1883) and add the vital parts of the HomeAssitant configuration.yaml file in the attachments. Make sure to adapt the ip address to your setup or omit trusted section entirely if password is necessary (recommended).
Now you can connect to the RaspAp (or Wifi according to the infrastructure) and are able to control the Open/Close mechanism via your smartphone.
To Summarize the whole concept now after we've built this monster together:
Let's say you want to open the window while you are chilling on the same couch you were sitting on earlier in the motivation and you need some fresh air to make this miserable hot day a little bit easier to withstand.
So you grab your phone open up the Home Assistant app and press "Open" (the button from pic 6.1). Now the following happens backstage:
1) Now the message "open_ful" is published to the topic the PSoC 6 subscribes to.
2)This prompts the PSOC6 to send the same words via UART to the XMC1100 .
3) The XMC1100 sets the D1,D2 bits to 0,1 respectively meaning "open".
4)These 2 lines are connected to the XMC2Go in the Lock/Unlock section, which acts accordingly and starts the to turn the gear with the help of the H-Bridge.
5-6) The gear keeps turning until the TLE493D shows an angle of the roughly specified degrees in XMC2Go Unlocker.
7) This prompts the XMC2GO to shut off the H-Bridge.
8-10) XMC2Go sets the status line (D3) to HIGH which in turn makes the XMC1100 set the two digital lines D1, D2 into the "wait" state.
11) The BootKit then begins to spin the motor of the opening mechanism.
12-13) Motor keeps spinning till the set threshold in is detected by the magnet sensor (so the last magnet on the rack).
14) When its detected the XMC1100 shuts down the motor.
Whilst the process is going on, every 5 seconds the magnet sense values of the Open/Close mechanism are displayed on the smartphone.
The flow assumes that the window was already properly set up as explained in the following. At startup a closed position is assumed. As this is hard to achieve after the assembly, the following procedure was implemented. At startup if the window and locker are not set to the closed position, please click Emergency stop and then Close. This makes the window go into the closed state.
IN DETAIL: The Emergency stop stops the motors immediately and sets the state to unknown. If the state is unknown, any desired position makes the window first go into the closed state and then to the desired.
7) For our fellow educated peopleIf you are curious or bored you can check out these pages to cure your bored or satisfy your curiosity.
Regarding the different protocols you can find further information for MQTT, I2C and UART.
About the used boards see this site for a brief overview about Infineon's maker boards
8) It's time to say goodbye...CONGRATULATIONS!!! YOU'VE MADE IT!!! Now you can get even more lazy in the future and open the window from where you're sitting.
This project was created for the Embedded World Exhibition. We hope you enjoyed it and got inspiration from this project. If there are any questions feel free to leave a comment.
Comments