Category Archives: IoT

Weather station update

Realised this project has been running almost 10 years now, and gone through several iterations. The main improvement is that it is integrated with my Home Assistant system.

Latest version of the weather station receiver.

Note that in the process it has gone back to a breadboard, so far from a finished project yet! The circuit operates as such:

  • RF receiver module running at 433 MHz receives the data pulse from the rooftop sensors
  • Arduino Nano decodes the sensor data into meaningful values
  • Data is converted to JSON and transmitted via serial to ESP8266, using level shifter to allow 5V Arduino output to input to ESP which expects 3.3V levels
  • ESP8266 receives JSON packet and then passes this via MQTT to the Home Assistant over WiFi
  • Individual sensor data displayed on HA page
Home Assistant data display

As before, because this is intercepting data from outside sensor, it only gives me outside temperature and humidity, wind speed and direction. (Note direction is still an arbitrary number, must figure out how to convert this to meaningful compass direction one day). This is supplemented by separate ESP boards inside the home sending their temperature and humidity data via the ESPHome integration over WiFi.

During the last week it stopped receiving data from the rooftop unit, and I suspected perhaps this time it had finally packed it in after almost a decade of use. The fact that neither the console or my circuit were reporting data would suggest an issue with the transmitter. Previously I have had to replace the Alkaline rechargeable AA cells it uses, which are not the easiest things to find these days. The cockatoos have also had some fun with it also, with only two of three anemometer cups surviving and some of the wires have been chewed but still seem to be working.

So I climbed up on the ladder to get on the roof, pulled down the transmitter to find it is still working fine. Recalled this has happened before, so I pulled batteries from the wall mounted console to restart it and it picked up the transmitter straight away. Which means of course I have to set the date and time again, no memory backup 🙁

This leaves the question of why my receiver was still not working. Plugging into the Arduino IDE let me check data being received. The ESP was connecting to WiFi, but not receiving from the Arduino, although it was showing data transmission on status lights. On debugging it, found that the transmitter ID code had shifted, which seems to happen from time to time, but I don’t know why. So, what seems to happen is, transmitter ID changes, base station console doesn’t notice and keeps trying to listen to previous ID. Meanwhile, my circuit is hardcoded for the ID. Otherwise it tends to pick up spurious transmissions from other devices, I would expect these could be air conditioner remotes, garage door remotes, etc all of which are using 433MHz RF band.

So restarting the base station made it listen for a new transmitter ID, and I had to update my code for the new ID before it would start reporting the data! I can’t think of an easy way to make this happen automatically, but at least next time I’m going to know what to try before getting up on the roof again.

RGB Light CONTROLLER

I scored some of these analog RGB strips and needed a way to power them, and to be able to control the colours.

Initial prototyping showed that I needed about 20V to be useful, and I could easily switch each colour via a MOSFET driven from a microcontroller. First attempt was with an Arduino, then another with an ESP8266. At this point, I realised that you have to choose the MOSFET gate voltage to suit the logic, so common IRF540 devices won’t work with the 3.3 V available to ESP devices. I selected IRLB8271 instead, and this works.

I have tried a few different circuits, involving different coding.

  • Cycling through colours
  • Random colour cycle
  • Running a web server, using a web page to choose colours

Now to get from the breadboard to a finished circuit …

Useful links

NodeMCU electronic switch

Here’s a really easy demonstration of how you can control outputs on the NodeMCU with a simple web interface. The NodeMCU runs as a simple web server, writing a control panel interface directly as HTML.

Hardware

The circuit is very simple, just four LEDs with resistors wired to outputs of the NodeMCU.

wiring diagram
wiring diagram

Here’s the wiring I used, which matches the code.

  • yellow – D1 = GPIO5
  • green – D2 = GPIO4
  • blue – D3 = GPIO0
  • red – D7 = GPIO13

In Arduino code, GPIO numbers map to Arduino digital outputs, so to turn on yellow LED use digitalWrite(5, HIGH)

NodeMCU circuit
NodeMCU circuit

Software

  1. Get the code example (esp8266ledControl.ino) and edit to add your wifi name and password to the code.
  2. Board type in Arduino IDE is ‘Node MCU 1.0 (ESP-12E Module)’
  3. You will need to set up your Arduino IDE to work with the NodeMCU. A good guide can be found at https://www.circuito.io/blog/nodemcu-esp8266/ (go to the last section Programming NodeMCU with Arduino IDE. Note there is a slight typo in the instructions, the board URL should end with ‘.json’ not ‘.jso’).
  4. Upload the code to the NodeMCU.
  5. When it has finished loading, quickly open the Serial Monitor, set the baud rate to 115200.
  6. Wait until the device joins the WiFi network, and note the IP address it obtains.
  7. Enter this address in a web browser, and the interface will load.
  8. Now you can turn on and off the various coloured LEDs by clicking on the respective buttons.

web interface
web interface

Silicon Chip module articles

A series of articles on ‘Cheap Asian’ Electronic Modules

  1. Low Cost Asian Electronic Modules (Oct 2016)
  2. Computer Interface Modules (Jan 2017)
  3. Measuring Temperature and Relative Humidity (Feb 2017)
  4. LCD Module with I2C (Mar 2017)
  5. Direct Digital Synthesiser (Apr 2017)
  6. LED Matrix Displays (Jun 2017)
  7. Li-Ion and LiPo Charger Modules (Aug 2017)
  8. Pressure/Temperature Sensors (Dec 2017)
  9. 2.4 GHz Wireless modules (Jan 2018)
  10. Sensing motion and moisture (Feb 2018)
  11. ESP-01 Wifi Data Transceiver (Apr 2018)

It’s a hot, hot summer

Summer holidays in Australia and it has been a real scorcher of a week. As I need to get some preparation for the school year happening I am still playing with IoT here, even if it’s a little bit harder working away from home.

I’ve been playing with NodeMCU a bit more, because it has the obvious benefit of built-in WiFi, so once configured it just needs power and a network connection and you have data logging.

As noted in my previous post, Xively is no longer providing free hosting, so I need to find other options. A bit of hacking and some examples online and I have temperature logging being pushed to ThingSpeak. I’ve put the board outside plugged into a USB phone charger and am using a phone hotspot to provide internet connectivity. Proof-of-concept done!

Feed is here: https://thingspeak.com/channels/407022

graph of temperature
Local temperature

Currently it’s dropped a little to just 35 °C, cooling off a bit!

Edit: Now back at home, and it is inside so a bit cooler!

Home weather offline for the moment

With a bit of ingenuity and a lot of trial and error there are ways of making this IoT work without having to sign up for commercial services. Since I am doing this for hobbyist/education purposes I can’t really justify paying for business services.

So what tends to happen is, something that one uses for a while and ‘it just works’ stops working because the provider changes the terms of use. Before Christmas, Xively sent out a notice that they were dropping their free data hosting, and I would either need to upgrade to a paid service or go elsewhere. This is quite reasonable, they are a business and I have been able to use their services for several years now. They even made a few suggestions for alternative hosts.

Being the silly season, time was limited to get a new service onboard, although I did spend some time with ThingSpeak it didn’t go smoothly, so I would have to say that Xively do have a very good platform because it was so easy to get up and running in the first place. So at the moment the weather station isn’t logging to the web, and will need some more work done before it does.

The Xively feed started on Mar 14, 2014, so it has been logging data for almost four years. That was my first real IoT experiment so I’m pleased with that! It was interesting to be able to check the weather at home when we were on holidays, and you could even work out who had been working in the study by the changing light levels.

HomeAssistant + Arduino

OK, HomeAssistant runs on RaspberryPi, but the RPi only has digital in/out, but what if I want to read analog values from sensors? One solution appears to be to use an Arduino, since this is the sort of thing they do well. However, finding details of how to do this seems a bit sketchy. I could use I2C, but that seems a bit tricky. I did read that I can use USB, which is convenient because that will also give me power for the Arduino. To use an Arduino as an add-on board for the RPi, I had read about something called Firmata, which loads as a sketch running on the Arduino. This is easy at the Arduino end, as it is just one of the examples pre-installed, upload and it’s ready to go.

I set up the configuration in HomeAssistant and immediately got a whole heap of errors, mostly referring to needing PyMata 2.14. Now PyMata is a client library that allows Python to control the Arduino. Obviously not part of the standard RPi/Hassbian image. After a bit of messing around here’s what I managed to do:

  1. Plug the Arduino into your computer, load up the IDE and upload the StandardFirmata sketch (found in the Examples submenu)
  2. Plug the Arduino into a USB port on the RPi. Log into the RPi using SSH
  3. At the command line, run:
    sudo pip3 install pymata
  4. If you download the examples from the GitHub repository, you should be able to call the blink sketch to verify that all is working. It should flash the LED 10 times, and you should see the process running in your terminal session counting down. (Note that my UNO clone is connected at ‘/dev/ttyACM0’, so the script works as is.
  5. Add the following entries to your configuration.yaml script and save it:
    arduino:
      port: /dev/ttyACM0
    
    switch:
      platform: arduino
      pins:
        13:
          name: LED
  6. Restart HomeAssistant
  7. The LED should show up as another switch in your dashboard, and turning it on should light the pin 13 LED on the Arduino

HomeAssistant dashboard with Firmata switch
LED on pin 13 of Arduino controlled through HA using Firmata

Note that it appears you can only read analog input pins, and switch digital output pins through this interface. No PWM, and I suppose if you need to read digital inputs then you can do that directly on the RPi.

More info at:

 

HomeAssistant

Thought it was time to step up the home automation effort, so a mention of HomeAssistant on a blog had me interested. So now the RaspberryPi is running some new software and I’ve been tinkering with this seeing what it can do. There’s not too many things in the house that are ‘smart’, but I can turn the TV off and control a WeMo switch. Much of the built-in functionality is impressive, so triggers for sunset or time let one test how it works. Integration with my phone also lets it track location and use geofencing for triggers also.

I’d be interested to see what can be done once I can integrate with other systems in the house, such as the alarm system, thermostat or pool controllers. Being open-source and open, there’s plenty of scope to ‘roll-your-own’ to meet individual needs.

Here’s a useful article on using the Hass.io version of HomeAssistant. Worth a look.

ESP8266 & NodeMCU

I bought a NodeMCU module a while back, but couldn’t figure out how to use it at the time. I also played with one of the ESP8266 modules using a FTDI adaptor to also convert to 3V3, but it seemed rather flaky. In the end, I found I could simply hook up the NodeMCU to a USB port and use the Arduino IDE. To save a whole lot of messing around, I also set up Blynk, which works briliantly with this type of device. One slight complication is that the NodeMCU tries to map pins to equivalent Arduino pinouts, whilst Blynk is still aware of the GPIO pinouts. Finding a pinout diagram here helped make sense of it.

NodeMCU on breadboard
NodeMCU on breadboard, with one LED connected. Note el cheapo phone booster battery doing a great job.

It also seems that the USB ports on my MacBook Pro aren’t reliable with this device, whether it isn’t so happy with USB 3.0 ports or whether it’s not supplying enough current I can’t tell.  When it shows up it is easy to flash it with the Arduino sketch. Plugging the board into a phone charger it works 100%. I’m also testing out an el cheapo phone battery booster from K-Mart as a portable power source for projects, and at only $5 this is great value, so I plan to pick up a few more.

Blynk screenshot
Test Blynk project. The red LED is on the breadboard, and the other two are blue LEDs on the NodeMCU board.

Suddenly I see a whole lot of benefits of using these inexpensive NodeMCU boards in place of Arduinos for lightweight projects, considering that you get Wi-Fi built in.

Arduino + shield

Shield with RF module added
Shield with RF module added

So this project had been sitting on my desk for ages now with the sensors and RF module spread across two breadboards with a mess of wire connecting it all up. Today I finally found some time to add the RF module to a prototyping shield. The other sensors are still on a breadboard and that’s the extra wires hanging off it, but it’s one step closer to a finished project. Some of the soldering was a bit fiddly but worked straight off.