Archive for the ‘IoT’ Category

Wi-Fi Camera Trap

Project source code at GitHub: wifi-camera-trap

We have lots of small wildlife around our house (mostly rabbits this year) and since I have a small camera module and a cheap PIR (passive infrared) motion sensor, I thought it would be fun to make a motion triggered wi-fi camera to deploy somewhere near the house.

Wi-Fi Camera Trap



The project is quite simple. If the PIR sensor is triggered, software on an ESP8266 wi-fi microcontroller captures an image using the ArduCAM camera module and uploads it to an image server. I wrote a very simple Node.js server that saves the uploaded images and makes them available on a gallery page for easy viewing. Nothing fancy.

Here are some of the great images we captured. The bunny’s movement triggered the PIR sensor with no problem!

Bunnies over Wi-Fi



Inside the enclosure is an IoT Experimenter board that I designed to help me with my IoT projects. You can read more about it here. It has an ESP8266 wi-fi chip and connector for an ArduCAM module. I’m powering the whole device from a 5V battery pack. The IoT Experimenter is designed for input of 9V, but the onboard 5V regulator drops the 5V input down to about 4V, which is still fine for the camera module and PIR sensor in this project.

You can use any ESP8266 board you have. The camera connects to both the I2C and SPI pins, and the PIR sensor is connected to “Arduino pin 3” which is the RX pin on the ESP8266 but you can move it to any pin.

Wi-Fi Camera Trap – inside





Here’s what it looks like outside of the enclosure:

Wi-Fi Camera Trap Hardware





Here’s a closeup of the sensor. These are super cheap on AliExpress or Ebay. The output pin goes HIGH when there is new movement detected.

Cheap PIR Sensor



Software

I prefer to program ESP8266 chips using Arduino so I can take advantage of the hundreds of useful Arduino libraries. There’s plenty of information about using Arduino code on the ESP8266 here. This project uses the ArduCAM library control the camera module.

I’m also using the excellent WiFiManager library to make it easier to connect the ESP8266 to a network. Instead of hardcoding the SSID and password in code, if the chip can’t connect to any networks it already knows about, the WiFiManager will set up an access point (AP) named “CameraTrap”. Use your computer or phone to connect to the CameraTrap access point and a captive portal page will prompt you for your network name and password. If you aren’t automatically shown the captive portal page, just navigate to 10.0.0.200 and it will load.

After the CameraTrap code captures an image, it needs to upload it somewhere. I’ve provided a simple Node.js server for this purpose. The code POSTs the image to /upload on the image server which writes it to disk. You will have to specify the server hostname in the CameraTrap code. Note that the camera is actually installed upside down in the enclosure (so the wires fit) so my server rotates the image 180 degrees when it saves it to disk. On any machine where you can run a node server, type

npm install
node app.js

The server will run on port 8000. In any browser, just navigate to

http://yourserver:8000/images

to see the images. (Make sure you don’t accidentally include a trailing slash in the URL.)

All the software is available in the wifi-camera-trap GitHub repository. The Arduino code is in the CameraTrap directory, and the Node.js image server is in the imageserver directory.


Published by Michael, on September 9th, 2017 at 8:09 am. Filed under: Arduino,ESP8266,IoT. | No Comments |

Solar-Powered LoRa Weather Station

Project source code at GitHub: lora-weather-station

In this project I show how I built a remote, solar-powered weather station that transmits temperature and humidity readings over LoRa, and a base station that publishes the data to the Internet with MQTT (er, I guess we are supposed to say “cloud” now).



LoRa (Long Range) is a relatively new radio technology intended for reliable communication of small amounts of data over distances that are longer than achievable with bluetooth or Wi-Fi. It’s also geared toward low power applications. LoRa modules are relatively cheap (about $8 for a bare module), but the easiest way to use LoRa is to buy development boards that also have a microcontroller on them. Moteino and Anarduino MiniWireless both have LoRa enabled transceivers that work well and are essentially the same. Each is basically a small Arduino with ATmega328 and LoRa module. They cost around $20-25, and remember that you’ll need 2 of them, one for each end of the communication.

Weather Station

The remote weather monitoring station has a cheap solar panel, a LiPo battery, an Adafruit LiPo charging board, and an an Anarduino board with a TH02 I2C temperature and humidity sensor. I enclosed all of this in an small plastic box (not waterproof!).



Reading the I2C sensor is easily accomplished using this TH02 library. As for the control of the LoRa radio, there is a wonderful library called RadioHead that makes it easy to use all kinds of radio technology in embedded systems. For message format, I like to use JSON because it is easy to read and very flexible. The ArduinoJson is an excellent Arduino library for generating and parsing JSON strings. Using these 3 libraries, the Arduino sketch reads the sensor and transmits a small JSON message with the temperature and humidity readings to the base station every 10 seconds. The format of the JSON message is simple:

{
  temp: 72.1,
  hum: 54.2
}

Base Station

The base station has 2 hardware modules. First, there is another LoRa module to receive the sensor reading messages. When the LoRa module receives the JSON message from the weather station, it simply writes the message over the serial UART which is connected to the second board, an IoT Experimenter development board. The IoT Experimenter has an ESP8266 WiFi microcontroller which provides a gateway to the Internet. I designed the IoT Experimenter as a simple tool for my IoT projects, and you can read more about the IoT Experimenter here. You can connect an OLED display which allows us to see the data right at the base station.



The code on the IoT Experimenter receives the message over serial and publishes the data using MQTT. In the source code for the ESP8266 you will need to add your WiFi user/password, as well as the info about an MQTT broker to publish the data to. You can set up a free account on CloudMQTT. Their free plan allows you to have up to 10 connections. The source code for this project makes it clear where to set the information for your account: username, password, server, and port. This project uses an SSL connection, so use the SSL port on your CloudMQTT server.

Instead of watching the weather data on the base station’s OLED display, it is more convenient to see it on the Internet or on your phone. I have an Android phone and use a simple app called MQTT Dash. It lets you create dashboards with controls on them. My weather dashboard has gauges for the temperature and humidity.

MQTT Dashboard on Android



Another way to see data from an MQTT broker is to use the Chrome app called MQTTLens. It allows you to connect to an MQTT broker, publish to topics and subscribe to topics. It works well.

Project source code at GitHub: lora-weather-station


Published by Michael, on September 3rd, 2017 at 8:44 am. Filed under: ESP8266,IoT,LoRa. | No Comments |

Introducing the IoT Experimenter ESP8266 Development Board

Like many other hardware hackers, I fell in love with the ESP8266 Wi-Fi microcontroller as soon as I started using it. It is fast, has plenty of memory, has Wi-Fi networking, and can be programmed in a number of ways. Lots of people like the Lua firmware, but I prefer to use the ESP8266 core for Arduino because I can use all the great libraries already built for Arduino.

I’m also working with LoRa radio technology. Several small Arduino-based boards are available for experimenting with LoRa: Moteino and Anarduino MiniWireless have LoRa capable boards that are easy to use. They both have the standard 6-pin serial connection for easy programming. What I really wanted to do is combine long range radio technology with Wi-Fi connectivity, so I designed an ESP8266 Development board that allows for easy connection of a LoRa radio module. While I was at it, I also included connectivity for an OLED display, ArduCAM camera module, and included a nice big PL9823 RGB LED that can be controlled just like WS2812 LEDs.

IoT Experimenter ESP8266 development board



There’s also connection for analog input with a voltage divider to scale voltage down to the 1V ranged required by the ESP8266. The board has 2 voltage regulators: a 3.3V one for the ESP8266, and a 5V regulator for powering the RGB LED and to provide power to the radio module header. If you are wondering how I drive a 5V LED with 3.3V logic from the ESP, a diode in line with the LED’s power supply drops the VCC low enough for 3.3V logic to work reliably. I learned that clever trick from this Hackaday article. If you want to connect a strip of WS2812 LEDs, there are pads for that, too.

The TX/RX serial lines for the radio module and ESP8266 are connected together for simple serial communication. This makes it easy to build a simple radio to Internet gateway. See my project Solar-Powered LoRa Weather Station for a good example of this approach. Also, this header can be used for any kind of radio (not just LoRa) that has a 6-pin header with the standard FTDI pinout. In fact, it doesn’t have to be a radio at all! Communication with any serial device might be just what you need.

Radio module attached to IoT Experimenter





The ArduCAM camera module for Arduino works great with the ESP8266 (here is the library) so I can make surveillance cameras with this board. The 8-pin female header for the camera is on the underside of the board and the camera fits great right on top of the board.

ArduCAM module attached to IoT Experimenter





I also love those cheap I2C OLED displays. They come in several colors and are only a few dollars. So I added a header for that also. It’s great for debugging, and when you are done, just pull the display off.

OLED display attached to IoT Experimenter





The PL9823 RGB LED can be controlled using any WS2812 library, like the Adafruit NeoPixel library. This big 8mm LED looks great. Make it any color you want!

RGB LED



This board has proven really useful for me in several projects, and I’m probably going to offer it as a product. Hope you like it, and if you are interested, let me know.


Published by Michael, on September 3rd, 2017 at 8:42 am. Filed under: Arduino,ESP8266,IoT,LoRa. | No Comments |

Wi-Fi IoT Electrical Outlet: Turning on a Coffee Maker Remotely

Project source code at GitHub: iot-wifi-outlet

They say necessity is the mother of invention, and there’s no question that the need to turn on my coffee maker while still in bed is a necessity. I don’t want to wait for my coffee to brew after I go down to the kitchen in the morning. I want my coffee ready as soon as I get there. It’s not that I’m impatient, I just have lots of electronics work to do, right?

Obviously, I needed a solution that would allow me to start my coffee brewing from my phone which I keep at my bedside. This is a great example of a problem in need of an IoT (Internet of Things) solution. The coffee maker is a thing I want to control from the Internet.

I’m the only one in my house that drinks coffee, so I have a simple single-serving coffee maker that I like to set up the night before. To brew, there is a mechanical button on the side that turns on the heating element and then “pops out” after the brewing process. If there is no power supplied to the coffee maker, this button can still be pressed in, and when power is supplied, the brewing will start. All I needed is a way to turn on the AC mains power to the coffee maker.

Building an Wi-Fi Enabled Electrical Outlet

IoT enabled electrical outlet



Enabling an electrical outlet to connect to a Wi-Fi is not difficult. I used an ESP8266 wi-fi microcontroller to control a relay that switches the mains power on and off. I used an Adafruit Huzzah board which is just a convenient breakout board for the ESP8266. The relay control wire is connected to an ESP8266 GPIO pin and a simple Arduino program running on the ESP8266 makes it easy to control the relay. There are several ways to program an ESP8266, but I prefer to use Arduino. See this guide for instructions on how to get started programming the ESP8266 with the Arduino IDE.

Here is the schematic for the circuit. I power the circuit with a common 9V adapter. A voltage regulator provides 5V to the relay coil and to the Huzzah board (which has an onboard 3.3V regulator to power the ESP8266). Note that the GPIO pins are 3.3V, but I found no problems controlling the 5V relay with 3.3V logic.



An ordinary wall plug connects this IoT outlet box to normal outlet in the wall, and the wires are connected to the outlet enclosed in the box. The relay connects and disconnects the “line” or “hot” wire of the mains circuit. That is, the relay is between the wall power and the outlet provided by this outlet box. Here’s how it looks all closed up.



Controlling the Outlet from the Internet with MQTT

Now that we have a way for Arduino code to turn the power on and off, how do we connect it to the Internet and control it? Step one is to get connected to your Wi-Fi network. This is very easy, and to keep things simple, the source code for this project just has you hard code your SSID and password. But we still need a way to send a command to the outlet. I’m using MQTT for this purpose, which is implemented by the Arduino PubSubClient library. MQTT allows the outlet to subscribe to an MQTT topic on an MQTT broker. An MQTT broker allows different MQTT clients to publish messages to topics and/or subscribe to topics. I run my own MQTT broker for all my MQTT projects, but you can set up a free account on CloudMQTT. Their free plan allows you to have up to 10 connections. The source code for this project makes it clear where to set the information for your account: username, password, server, and port. This project uses an SSL connection, so use the SSL port on your CloudMQTT server.

The outlet subscribes to a topic called “coffee-maker” and my phone will publish messages to that topic. If the outlet receives a message “ON” on this topic, it will turn the relay on. If it receives an “OFF” message, the relay is switched off. You can also specify a delay so that the outlet is switched off after a period of time. My coffee will be done brewing within 10 minutes, so I want everything switched off. To do this, I send the message “ON”, but also with the number of seconds for the auto-off delay. For 10 minutes, I send “ON:600”.

Remote Control on the Phone

I have an Android phone and use a simple app called MQTT Dash. It lets you create dashboards with controls on them. My coffee maker dashboard has a button that can toggle between on and off for the outlet. It’s green when the outlet is turned on and publishes the message “ON:600” to the topic coffee-maker, and is red when I publish “OFF” to to the same topic. Here is the setup for the control:



MQTT Dash has many icons to choose from when creating a button — even a coffee maker icon! This gives me a great little dashboard for my coffee maker. Just tap to turn it on/off!



Project source code at GitHub: iot-wifi-outlet


Published by Michael, on August 26th, 2017 at 2:16 pm. Filed under: ESP8266,IoT. | No Comments |