Building Homie Devices for IoT or Home Automation

This instructable is part of my DIY Home Automation series, check out main article ā€œPlanning a DIY Home Automation Systemā€œ. If you donā€™t know yet what Homie is, have a look atĀ homie-esp8266Ā +Ā homieĀ fromĀ Marvin Roger.

There are many many sensors. Iā€™m covering the very basic ones in order to give reader the requirements to get started building ā€œsomethingā€. That might not be rocket science but that should actually work.

Building Homie Devices for IoT or Home Automation

If you donā€™t have the parts, watch out for my upcoming instructable ā€œSourcing Electronic Parts From Asiaā€œ.

Let me add a few buzz words : IoT, ESP8266, Homie, DHT22, DS18B20, home automation.

Topic should be pretty clear now šŸ™‚

Also, this instructable is now also available from my personal page :Ā http://stuffblog.dullier.eu/

Step 1: Getting Started

Conventions

This instructable usesĀ D1 MiniĀ clones. These are WiFi enabled Arduino compatible controllers usingĀ ESP8266 chip. They ship in very small form factor (~34*25mm) and are dirt cheap (~3-4$ for clones).

Iā€™ll illustrate each build using a D1 Mini, a breadboard and some sensor(s). I include a Bill Of Materials (BOM) for each but will skip obvious things likeĀ jumper wiresĀ and breadboard (miniĀ orĀ full). Iā€™ll focus on ā€œactive partsā€.

For wires/cables in diagrams (FritzingĀ +Ā AdaFruitFritzing library), I used:

  • Red/Orange for power, usually 3.3V. Sometimes it will be 5V, be careful.
  • Black for ground.
  • Yellow for digital data signals : Bits are traveling and can be read as-is by chips.
  • Blue/Purple for analog data signals : No bits here, just plain voltage that must be measured and computed to understand whatā€™s going on.

Homie for ESP8266Ā ships aĀ dozen examples, thatā€™s where I started to build this instructable.

Breadboard

The D1 is quite breadboard friendly but will save only one row of pins up and down.
Each example will have the D1 on the right side and the components on the left side. The upper and lower power rails will be used to carry either 3.3V or 5V.

Note

Homie examples are built as ā€œ.inoā€ sketches forĀ Arduino IDE. My own code is however built as ā€œ.ccpā€ forĀ PlatformIO.

This will make very little difference as sketches are simple enough to be copy/pasted whatever your tool of choice is.

Step 2: Temperature & Humidity : DHT22 / DHT11

Building the device

The DHT22 uses :

  • One digital pin to communicate with the controller, connect it to D3
  • Two wires for power (3.3V or 5V + GND)
  • The digital pin must be kept high (connected to power), for this we use a resistor between power rail and data pin

Code

The PlatformIO project can be downloaded from :Ā https://github.com/amayii0/Homie-DHT22

The original Homie example is here (but does not use a sensor) :Ā https://github.com/marvinroger/homie-esp8266/blob/ā€¦

For DHT22, use DHT sensor library (ID=19)

BOM

  • Controller : Wemos D1 Mini
  • Resistor : 10KĪ©
  • Sensor : (one of these)
    • DHT22 : Iā€™ve used theĀ 4 pins kindĀ which requires an extra resistor. There areĀ 3 pins modulesĀ shipping as SMD which includes the resistor.
    • DHT11Ā : This is cheaper but less accurate, check your requirements

Step 3: Waterproof Temperature : DS18B20

Building the device
The DS18B20 uses :

  • One digital pin to communicate with the controller, connect it to D3
  • Two wires for power (3.3V or 5V + GND)
  • The digital pin must be kept high (connected to power), for this we use a resistor between power rail and data pin

The DS18B20 is aĀ 1-wireĀ sensor. It uses a bus and as such multiple sensors can use a single data pin.

It is also possible to NOT use 3.3V/5V to power the sensor, this is called parasitic power mode. SeeĀ datasheetĀ for details.

Code

The PlatformIO project can be downloaded from :Ā https://github.com/amayii0/Homie-DS18B20

Like for DHT22, the original Homie example is here (but does not use a sensor) :Ā https://github.com/marvinroger/homie-esp8266/blobā€¦

For 1-Wire bus, use package OneWire (ID=1)

For DS18B20, use DallasTemperature (ID=54)

BOM

Step 4: Light : Photoresistor / Photocell (digital : On/off)

Building the device

(Sorry, donā€™t have a Fritzing component for the digital photocell)

The photocell digital module uses :

  • One digital pin to communicate with the controller, connect it to D3
  • Two wires for power (3.3V + GND)

Its possible to use an analog photocell but this is not documented here, seeĀ AdafruitĀ excellent article ā€œUsing a Photocellā€œ.

Note: In this example thereā€™s a potentiometer on the sensor board. It is used to set the limit between ā€œlightā€ and ā€œdarkā€ ambient light. When reading 1 light is off, therefor reading 0 means light if on.

Code

The PlatformIO project can be downloaded from :Ā https://github.com/amayii0/Homie-Photocell

BOM

Controller : Wemos D1 Mini

Sensor :Ā Photosensitive / Light Detection Module

Step 5: Light : Photoresistor / Photocell (analog)

Building the device


The photocell analog sensor acts as a resistor. It will connect between an analog input and 3.3V.

A resistor is put between GND and data pin to create aĀ voltage divider. The purpose is to create a known range of values:

  • If there is no light, photocell will basically block VCC, thus connecting GND to your data pin : Pin will read nearly 0.
  • It there is a lot of bright light, photocell will let VCC flow to the data pin : Pin will read nearly full voltage and as such near to max (1023).

Note : Analog pins values are read in a 0-1023 range usingĀ analogRead. This is not practical to deal with 1 byte values, for this theĀ Arduino map functionĀ will help reduce from 0-1023 to (for instance) 0-255.

For calibration of min/max values for your sensor, use a sketch likeĀ this one from Arduino.

Code

The PlatformIO project can be downloaded from :Ā https://github.com/amayii0/Homie-PhotocellAnalog

BOM

References

Step 6: Optical Detector : QRD1114

Building the device

Code

BOM

References

Step 7: Final Words

This instructable is a very short one to explain basic monitoring.

To go further weā€™ll need to connect relays, IR emitterā€¦ This will hopefully be covered later on as free time allows me to. The major difference is that we wonā€™t just ā€œreadā€ (is there light?) but also ā€œwriteā€ (turn light on!).

Source: Building Homie Devices for IoT or Home Automation


About The Author

Muhammad Bilal

I am a highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top