Active Pet-Projects =============== Air quality sensor ------------------ Motivation ~~~~~~~~~~ At some point in autumn/winter 2018, I have realized that I have some allergic symptoms in our bedroom. One way to figure it out was to try air filtering. To this end, I have borrowed `a unit built by a renowned manufacturer `_ and found that it, in fact, has improved our sleep quality. This made me curious about the air quality measurement - so I got one of the `Plantower `_ sensors to compare its numbers with the sensor built into the commercial purifier. Solution ~~~~~~~~ Not much time, I have built and implemented an air quality sensor. I have used a cheap, low power USB charger (5V) with a `voltage regulator `_ to power `ESP01 `_ . The `Arduino implementation `_ is straightforward: * it waits to get a poll message through an MQTT channel * switches on the sensor and lets it warm up for 30 seconds * takes a measure and pushes it back over another MQTT channel The results can be read out through the `NodeRed Dashboard `_ .. raw:: html :file: air-gallery.html Results ~~~~~~~ It seems that the numbers I got form my sensor perfectly matched numbers from the purifier, so I decided to proceed with the next step. Air purifier ------------ Motivation ~~~~~~~~~~ A `commercial purifier cost goes in hundreds CHF `_, and it seemed to me that it comprises no more than a filter, a fan, and an air sensor. As most of the vendors sell `affordable replacement filters `_ and I already had a sensor, I decided that to take the challenge and build the remaining part. Hardware ~~~~~~~~ I have based my design on principles similar to the commercial purifier: it should suck air from the side and blow it up. The airflow was to be provided by a three-channel array of fans to pull the air through the filter and one additional set of fans to pull the air out of the box. For air quality monitoring, I've built in an array of five colorful LEDs, and for the manual operation, I have added `a digital encoder dial (KY-040) `_. A dual power supply is used to feed the logic with 5v and 12v for powering fans. `PWM modulation `_ for fan power is driven through integrated `PWM i2c drivers (PCA9685) `_. Given the fact that the driver has 16 independent channels, I was hoping to be able to feed through it both fans and LEDs. Unfortunately, it seems that the PWM frequency required by the fans is way different than the one suitable for LEDs, so I ended up using two PWM drivers. As drivers themselves are not ideal for high-current drains, I have used `TIP-31c (TO-220) `_ for fans and `n2222 (TO-92) `_ for LEDs. I was caught by surprise by the hum induced in fans by the PWM frequency. To mitigate that, I needed to add massive capacitors (XXX uF) behind power transistors to smoothen the pulsed power delivery. As a side-effect of placing capacitors there, I have noticed power transistors heating up significantly more than before. I guess that this is caused by the high peak currents when charging capacitors. Given enough research and oscilloscope at hand, I'm quite sure that it would be possible to smoothen the PWM shape after the driver and before power transistors, but I still don't have one at hand. Eventually, to support silent overnight operation, I have optimized the capacitor size to limit hum at about 1/4 of fan throughput. .. raw:: html :file: purifier-gallery.html Software ~~~~~~~~ A boilerplate of `Arduino implementation `_ is similar to my `other automation projects `_. I have used an off-the-shelf SPI PWM control library and my implementation of rotary encoder read-out. To Be Done ~~~~~~~~~~ Component wiring visible in the gallery above is prototype-grade. Still, it has proven to be reliable enough to improve our sleep quality during the autumn-to-spring season when leaving the open window overnight is not an option. I also need to improve covers for the electronics compartment (now covered with tape) and come up with some good ways to protect top fans from the curious hands of my son. Dining room ambient light ------------------------- Following the success of the bedroom ambient light, I have installed a plain-white LED-strip in our living room. Thanks to the fact that the ESP32 module has an integrated PWM generator, with use only one TIP-31c, I was able to modulate the brightness quickly. As our primary source of light in the dining room is the spot-lamp over the table, we enjoy the extra ambient light, in particular during the winter mornings, when we have breakfast before the sunrise. .. raw:: html :file: dining-room-light.html 443 MHz to MQTT bridge ---------------------- Motivation ~~~~~~~~~~ There are plenty of useful sensors, buttons, and actuators that operate using digital code exchange at 443 MHz band. I found buttons and door/window opening sensors particularly helpful in triggering events for our home-automation. .. raw:: html :file: 443MHz-bridge.html Hardware ~~~~~~~~ I have used cheap, `low-grade 5v off-the-shelf charger `_ to and `3.3v voltage regulator `_ to feed the `ESP-01 `_ module. Most importantly, I have used the `SRX882 receiver `_ to feed the microcontroller with the demodulated signal. I found `this particular receiver `_ to have far superior reception over any other alternatives. On the market, one can see the whole range of wireless sensors, such as `IR `_, `door/window `_ and `flooding `_. For human-based interaction, I have found `wireless panel buttons `_ to be particularly useful. Software ~~~~~~~~ The `Arduino-based code `_ to feed received codes to MQTT is trivial and, over the years of operation has proven to be super reliable. I have found node-red to be the most convenient way to implement the logic behind the actions triggered by sensors and buttons. .. raw:: html :file: node-red.html Tomato observatory ------------------ Motivation ~~~~~~~~~~ My Ph.D. course allowed me to enjoy the Mediterranean climate of Lugano. It has also triggered my *green thumb* and resulted in a number of flora world representatives inhabiting balconies at my apartment. The main problem for me was that my academic schedule sometimes required me to travel for extended periods (2 weeks+), and I could not count on my flatmates to water my plants. Solution ~~~~~~~~ A home-grown irrigation system was to come for help. Following the advice of `my flatmate Matteo `_ I have taken into consideration using Arduino, lack of WiFi, and `good experience with RPi <#bedroom-alarm-clock-radio-decommissioned>`_ I have decided to use autonomous RPi for it. The prototype was quite simple... .. raw:: html :file: tomatoes-youtube-1st-prototype.html But they have quickly evolved into observation and watering stations. Because RPi doesn't have analog inputs, I have built an `RC-charging circuit `_ with a photo-resistor. Flipping directionality of a GPIO pin would discharge the capacitor. Afterward, it would slowly charge through the photo-resistor, reaching the TTL level at some point in time. The time it took to charge the capacitor is inversely correlated with the intensity of light. I used `a simple python script `_ to measure it. Later on, I have added additional `soil humidity sensors `_ but had no luck with getting reasonable measurements, Most likely because sensor surface corrosion having a much more significant influence than soil humidity itself. Finally, I have noticed that the water flow is actually entirely dependent on the throughput of nozzles, and not-so-much on the time that the pump is running. To take water throughput into account, I have installed a small, rotation-encoder based flow-meter. .. raw:: html :file: tomatoes-flow-meter.html .. The (almost) complete wiring diagram for the tomato observatory project looks like this: .. T raw:: html .. :file: tomatoes-circuit.html The logical view of the system follows: .. raw:: html :file: tomatoes-logical-view.html Live webcam snapshots and current weather conditions are available online under: `http://tomatoes.sonyx.net `_. Testimonies ~~~~~~~~~~~ The tomato observatory project in 2013 has resulted in pretty decent fruit yield and a time-lapse video: .. raw:: html :file: tomatoes-timelapse-2013.html Currently, the project (and tomatoes) have relocated to Zurich Enge, and it is broadcasting live from this location: ``_, and collecting material for the new time-lapse. The current set-up at our balcony looks like this: .. raw:: html :file: tomatoes-summer-2017.html To be done ~~~~~~~~~~ * Recently I have bought a `water-level sensor `_ and I'm planning to use it for issuing an early warning before the water runs out in the container. * the quality, and in particular reliability of the USB webcam connected to the Pi leaves a lot to be desired. It is going to be soon replaced with either the outdoor WiFi camera or a GoPro shooting through the window. * the system is not yet coupled to the home-automation MQTT bus running on our home RPi. It should be operated and calibrated with a web-app providing cross-platform (mobile & desktop) compatibility. Wake-up light ------------- Motivation ~~~~~~~~~~ Waking up early ain't easy. Waking up before sunrise is even harder. If there is no natural light to wake up to, maybe at least an artificial would do. Inspired by the availability of the LED stripes, I decided to give it a try and got myself a 5v rated, 5m long, 150 led strip from `here `_. Electronics ~~~~~~~~~~~ With a little experimentation, I have tapped the led stripe into the `power supply `_ together with the reliable ESP32s and `Adafruit NeoPixel library `_. It can draw quite some current (3-5A in my case), so make sure that you have enough power at hand. Software ~~~~~~~~ At first, everything seemed to run smoothly, but as soon as I wanted to connect it to home MQTT automation, I started having trouble with the reliable programming of the LED stripe. Specifically, what I was getting were utterly random colors. I have narrowed it down to the interference between WiFi and NeoPixel library. The reason for the interference was that the led programming (electric) `handshake is extremely time-sensitive `_ and interrupts generated by the WiFi and MQTT were disrupting it. I found no good way of solving this issue by `switching off interrupt handling `_ so I decided to give a try to an alternative LED library - `FastLED `_. Initially, I had no luck with it either, but eventually, I found that there is a way to `instruct it to disallow interrupts `_. It did the trick. .. raw:: html :file: wake-up-light-demo.html To be done ~~~~~~~~~~ For now, the wake-up light is adjusted manually with the use of the wireless remote numeric-pad that I use to control the curtain mover. This is undoubtedly sub-optimal, and the ultimate plan is to connect it to the `Actions on Google API `_, to be able to schedule and adjust the light with the use of an android phone. Caveats ~~~~~~~ Hardware: * most likely due to the noise generated by the power supply with little or no load, the LED strip would occasionally get the wrong color for few (one, two) LEDs. This, in turn, would make a bright flash in the middle of the night. Adding a sizeable stabilizing capacitor at the power supply should help with it. * due to the same power-line issue, I needed to use a separate power supply for the ESP32s. Luckily they are happy to share ground connectors, and it was no problem for the LED stripe control line. Software: * for some reason building code that references FastLED in `Platform.IO `_ fails due to the multiple inclusions of libstdc++. I didn't find the right solution for it. Luckily building with `the original Arduino environment `_ works just fine. Past Pet-Projects ====================== Bedroom curtains ---------------- Motivation ~~~~~~~~~~ .. It is quite simple - bedroom privacy requires curtains. Putting them on in the evening is a must, opening them later to enjoy Uetliberg, or seeing the sunrise is another. Combining these two, without getting out of the bed comfort with electricity and electromagnetic waves is the requirement. It is quite simple - sliding bedroom curtains open and closed. Closed in the evening, open before the sunrise. Electronics ~~~~~~~~~~~ An `ESP32s `_ coupled with a `4-way relay switch `_. Powered by the `two-voltage (12v and 5v) power supply `_ and a resistor gives a four-speed, two-speed `mover `_. Additionally, to estimate curtain move I have installed `a rotation encoder `_ together with an edge state detection switch. .. T raw:: html .. :file: curtains-circuit.html Software ~~~~~~~~ Controlling curtains is done via wireless `USB Numpad `_ connected to our home network computer (RPi 2) that hosts Mosquitto MQTT broker. A `simple python script `_ collects keystrokes and transmits them over MQTT to the curtain controller. .. raw:: html :file: curtains-logical-view.html The complete code repository for the project can be found `here `_. Hardware ~~~~~~~~ .. raw:: html :file: curtains-gallery.html Status / To Be Done ~~~~~~~~~~ As of now, the position of the curtains is not persisted, hence move has to be triggered and stopped manually. The mid-term plan is to implement document-based state persistence (MongoDB) and build a simple web-app (nodeJS & React) to control and calibrate curtains moves. Decommissioned as of now - because of my son, we have settled for manually operated shutters. Stepping motor controls for it is a song of the future. Bedroom alarm-clock radio (decommissioned in 2015) ------------------------------------------ Motivation ~~~~~~~~~~ The owl schedule all-so-typical for academics made it difficult for me to get myself out of bed. I found it quite enjoyable to be woken up with old-good-rock radio. Given a rather poor offer of local radio in Ticino, I grew fond of `Virgin Radio Italy `_. Solution ~~~~~~~~ I have built a small RPi with a USB audio DAC and USB WiFi adapter and installed `MPD `_ on it. It served for years for a cron-scheduled wake-up radio. Later on, I have installed on it `ShairPort `_ and used it quite a bit with `AirAudio `_. Finally, after a few relocations, the project was decommissioned and replaced with a `Spotify compatible dongle (Audiocast) `_ connected to my old, reliable stereo.