Some time ago I got myself a couple of Wemos D1 mini ESP8266 uCs. I really wanted to use them in my Smart Home project but I didn’t have a good idea until recently. I made a list of things I’d like to automate in my apartment and picked those I could actually work on. I have two primary first world problems. Every day I have to open and close window blinds in my living room. Wouldn’t it be cool to make Alexa do it for me? The second problem is the AC unit. I have to manually turn it on or off with a remote. I’d like to be able to control the unit through the OpenHab2 interface so I can turn the AC on when I’m on my way home and the apartment will be nice and cool when I arrive. It sounds like a great project. Let’s get started.

Wemos D1 mini uses the ESP8266 uC. It has 8 digital GPIO ports and one Analog input. It sounds like a lot of IO so it would be a waste of ports if I only use two of them. I had to come up with a longer list of things to connect and here it is.

  • a servo to open/close window blinds
  • IR LED to turn on/off AC
  • IR LED to control a TV with an IR LED
  • IR LED to control a pair of Bluetooth speakers
  • a room temperature sensor
  • an outside temperature sensor
  • an air pressure sensor
  • a light level sensor

The final design is on the picture below. In addition to all the sensors, I had to add a tilt switch to check a position of the blinds and a red status LED to see what’s going on with the module. It turns out that the IR LEDs require a lot of current and can’t be directly powered from the Wemos GPIO. I used the 2N3904 NPN transistor in the open collector configuration as a switch controlling the IR LEDs. BMP085 is a temperature and an air pressure sensor. It uses the SPI interface which can be emulated on any two of the digital GPIO pins. BMP085 module I have has 3.3 and 5V logic so I could hook it up directly to the Wemos board. For the internal and external temperature sensors, I used a DS18B20 1-wire digital thermometer. As you can see it is connected to Wemos in a way that requires only two wires – ground and positive which is also used for data transmission. That’s cool! The light sensor is just a regular photo resistor which goes from 0 to 4kΩ in series with 1kΩ resistor. The last component is a cheepo SG90 servo which we are going to use to turn the blinds rod.

The proto PCB is placed in the enclosure.

The IR LED is attached to the AC unit. The black tape on the left covers a photo resistor which goes on the top of the unit power LED. My idea was that I could use the power LED to read a current state of the AC unit. Unfortunately, there’s only one analog input on Wemos. I would need a separate ADC to make use of the second photo resistor. Alternatively, I could use an analog signal to drive a transistor connected to a digital GPIO, if the resistance change between when the power LED is on and off was significant enough. I didn’t have a transistor that could be easily switched with a 3.3V and 10k to 180k photo resistor resistance change and I didn’t know how to build a circuit that would make it work.

The SG90 servo rotates by only 160 degrees. It takes 5 rotations to open the blinds. But it is not a problem because most servos can be hacked and turned into continuous servos. I removed the servo potentiometer which originally gives a feedback to the servo controller about its position. I replaced the 4.4kΩ potentiometer with two 2.2kΩ resistors in series and connected them to the middle pin of the potentiometer as on the picture below. In this way, the servo uC always gets a feedback which says that it is in the center position. Now, if a signal is sent to the servo telling it to change its position to the left or right from the center, the electric motor will start spinning and will never stop since the position feedback will always be indicating the center (are we there yet? are we there yet?). There was a physical plastic pin on the servo shaft which was stopping it from rotating 360 degrees but I removed it too.

I attached the module enclosure to the window frame in a way the servo could be installed inside and would still reach the rod. The IR LED is visible for the TV and the speakers. The AC IR LED on a long wire is taped to the AC unit. The external termometer is also on a long wire outside of the window.

 

The OpenHab UI looks like this. Most of the actions are also hooked up to Alexa.

The source code for Wemos is on my Github

https://github.com/maestr0/smart-home-esp8266/blob/master/blinds-controler/blinds-controler.ino

I’m going to write a part 2 of this post. It will be about the ESP software and how it works with MQTT and OpenHab2.

Part 3 will be about Alexa integration. Stay tuned!

 

Leave a Reply