You are on page 1of 41

About NodeMCU

https://www.losant.com/blog/top-6-esp8266-modules

Top 6 ESP8266 Modules for IoT Projects


April 19, 2016

 IoT
 Projects
 Hardware
 ESP8266

We're big fans of the ESP8266 chip. What's not to love about a low-cost Wi-Fi chip with full
TCP/IP stack and microcontroller capability? Let's take a look at some of the top options
currently available and explore the major differences.

After first coming to the attention of western makers just a couple years ago with the ESP-01
module, the ESP8266 has exploded thanks to improved capability and documentation. Here's
a list of our favorite ESP8266 development boards currently available. ESP8266-based
modules work great with Losant. You can check out other boards as well on our list
of supported hardware.

1. Adafruit Feather HUZZAH


2. NodeMCU Dev Kit
3. KNEWRON smartWIFI
4. SparkFun Thing
5. WeMos D1 mini
6. Wio Link

INTUITIVE ALL-INCLUSIVE WORKHORSE


Out of all the modules on this list, we've spent the most time with Adafruit's "thin and
light" Feather HUZZAH. There's a good reason we chose it for our Losant Builder Kit to
introduce our platform back in February. It's also the "Wi-Fi Workhorse" in our list of best
maker hardware.

For a price on the high end of this list ($16 directly from Adafruit), you get an 80 MHz
microcontroller with 3.3V logic, a full Wi-Fi stack and a battery connector for added
portability. Most importantly, it's simple to set up and we've seen nothing but reliable and
predictable performance. We recommend programming it via the Arduino IDE.

Of all the ESP8266-based boards available, this is one of the best in terms of intuitive setup
and thorough instructions and documentation. Highly recommend starting with the Feather
HUZZAH to get your bearings, then trying some of the cheaper options that offer a less
intuitive setup.

The only concerns with the Feather HUZZAH is availability and soldering. It tends to go on
backorder more often than others (currently out of stock at the time of this post), assuming
due to its popularity. You also have to solder the headers, so be prepared to get the iron out.

Benefits

 Intuitive setup with great instructions and support


 Ships quickly (when in stock)
 LiPo battery connector
Affordable Open Source Reliability

As open source advocates, we like the NodeMCU platform a lot. We're using a NodeMCU
ESP8266 in some of our projects and it's been reasonably solid and predictable, especially
given the low cost. You can check it the NodeMCU in action in our Getting Started with
PlatformIO and NodeMCU guide.

NodeMCU is an open source IoT platform that uses the Lua scripting language. It's based on
the eLua project, and built on the ESP8266 SDK. It uses many open source projects, such as
lua-cjson, and spiffs. It includes firmware which runs on the ESP8266 Wi-Fi SoC, and
hardware which is based on the ESP-12 module.

There are numerous choices for NodeMCU dev boards and they're readily available from
online retailers like e-Bay and Amazon ranging from around $4-9. Thanks to a robust
community, the documentation is also very good.

The form factor on this module is also good. Though slightly wider than the Feather
HUZZAH, it still manages to expose a similar number of rows on your breadboard.

Benefits

 Most affordable standard size ESP8266


 Multiple options available
 Open source, good documentation

More Affordable
The KNEWRON SmartWIFI out of India is another inexpensive ESP8266 dev board with
solid features and capabilities. For just $9, you get integrated Wi-Fi, a LiPo battery charger,
user button, RGB LED and most notably - fairly straightforward setup. SmartWIFI provides a
fairly simple experience with a good getting started guide and detailed documentation.

BENEFITS

 Inexpensive
 Simple setup with good instructions and documentation

RELIABLE AND FAMILIAR


The SparkFun ESP8266 Thing is similar to the Feather HUZZAH in price, features, form
factor and setup. For $16, the Thing comes with integrated Wi-Fi, LiPo battery charging,
LED, user button and very good setup and documentation.

Reliability and predictability are great as you would expect coming from SparkFun. The key
differences between the Feather HUZZAH are that the Feather HUZZAH setup is a bit more
intuitive and the flash is a bit beefier. However, for most applications the difference in flash
shouldn't matter.

Like the Feather HUZZAH, the Thing ships unsoldered. The Thing should also have better
availability and fewer backorder / shipping issues vs. Feather HUZZAH.

BENEFITS

 Great instructions and support


 LiPo battery connector
 SparkFun reliability / availability

BEST BANG FOR THE BUCK


The WeMos D1 mini out of China is a great ESP8266 dev board for simple projects, offering
a fantastic bang for the buck at just $4. Though it's a "minimal" dev board, you have
everything you need to build a basic Wi-Fi enabled project, including integrated Wi-Fi,
sufficient flash and decent number of GPIO pins for the size.

When you don't need LiPo battery power or an LED and want to build a project as
economically as possible, this is no question the ideal option. In addition, the form factor is as
small as you can get for a Wi-Fi enabled ESP8266.

Fortunately, instructions and documentation aren't "minimal." Simple setup, good


documentation and solid reliability have helped the WeMos D1 mini become a popular go-to
board. Special thanks to Martin Ayotte and the ESP8266 Community Forum for telling us
about this gem. Just got a handful in and we're already cooking up some projects for them.

BENEFITS

 Cheapest integrated Wi-Fi available


 Simple setup with good instructions and support
 Smallest form factor available

NO BREADBOARD, NO PROBLEM
The $14 Wio Link, currently being crowdfunded by Seeed Studio, is a new and interesting
dev board innovation that's worth a look. It's a Grove-compatible, ESP8266-based board that
doesn't need a breadboard. Everything is integrated into the board itself.

The $14 price is very reasonable considering you don't have the additional cost of a
breadboard. One of the biggest benefits of the wio link is the “grove kit” connectors that
make it really easy to connect to all of the existing sensors that Seeed ships.

Setup and documentation appear solid, though we haven't had a chance to get our hands on
one since the Kickstarter campaign just recently started shipping to backers.

BENEFITS

 Innovative "no breadboard" concept


 LiPo battery connector
 Simple setup with good instructions and support

It's an exciting time for hardware with platforms like the ESP8266 creating numerous options
for reasonably priced, highly capable dev boards. We're looking forward to seeing even more
capabilities coming from the ESP32.

I'd love to hear any thoughts or feedback on your experience with these or any other
ESP8266-based dev boards.
Ricardo Quesada
4/20/2016, 12:23:13 PM

I would avoid the LoLin NodeMCU (the one from the picture) since it doesn't fit in the
breadboard. Instead, I would use the Amica NodeMCU which has exactly the same
functionality as the LoLin, but it fits Ok on the breadboard

Todd Henderson
5/12/2016, 1:46:06 AM

Thanks Ricardo. Good to know. Will swap out the pic for an Amica.

http://www.esp8266.com/viewtopic.php?f=26&t=8655

http://www.esp8266.com/viewforum.php?f=26&sid=98f9590de7c9335ab4880cb9f890e9c6
http://www.esp8266.com/wiki/doku.php?id=nodemcu

NodeMCU
The name NodeMCU refers to two separate components:

 The NodeMCU firmware which provides a Lua development and execution environment
which can run on any ESP8266 module with a minimum of 512Kb Flash Memory.
 The NodeMCU Inc manufactured development kits. These are low-cost breadboard-friendly
modules which are aimed at providing a simple to configure and set up, hardware platform
for developing ESP8266-based Lua IoT applications.

Firmware
This is hosted on Github in the Nodemcu Firmware Repository with the NodeMCU
Documentation online, and an nodeMCU Unofficial FAQ maintained on this wiki for
answers to your “Frequently Asked Questions”.

Hardware
NodeMCU devkit is a development kit for NodeMCU firmware. It's aim is to make
NodeMCU firmware development more easy. With a micro USB cable, you can connect
NodeMCU devkit to your laptop and flash it without any trouble, just like Arduino. It is an
open hardware, with ESP-12 core with 32Mbits(4MBytes) flash.

Devkit 0.8

This was the original design of NodeMCU devkit which never released on general sale.

Devkit 0.9

It is the second design of NodeMCU devkit. It uses CH340G as UART bridge, and can flash
firmware automatically by using nodemcu-flasher.
Devkit 1.0

It is the 5th design of NodeMCU devkit. This uses CP2102 as UART bridge, and can flash
firmware automatically by using nodemcu-flasher. It also supports Apple's MAC OS.

Introduction
 Website: http://www.nodemcu.com/index_en.html
 Forum: http://www.esp8266.com/viewforum.php?f=17
 Firmware: https://github.com/nodemcu/nodemcu-firmware
 Hardware: https://github.com/nodemcu/nodemcu-devkit
 Flasher: https://github.com/nodemcu/nodemcu-flasher

Summary
 Easy to access wireless router
 Based on Lua 5.1.4 (without debug, os module.)
 Event-Drive programming preferred.
 Build-in json, file, timer, pwm, i2c, spi, 1-wire, net, mqtt, coap, gpio, wifi, adc, uart and
system api.
 GPIO pin re-mapped, use the index to access gpio, i2c, pwm.
 Both Floating Point and Integer versions of the firmware can be built.
Dependencies
 Build on ESP8266 the current Espressif non-OS SDK.
o Lua core based on eLua project
o cjson based on lua-cjson
o File system based on spiffs

Flash the firmware


nodemcu_latest.bin: 0x00000
for most esp8266 modules, just pull GPIO0 down and restart.
You can use the nodemcu-flasher to burn the firmware.

Or, if you build your own bin from source code.


0x00000.bin: 0x00000
0x10000.bin: 0x10000

Better run file.format() after flash

Connect to the hardware via serial interface


Need to explain how to connect up serial portion.

baudrate:9600

Start play
Connect to your ap
ip = wifi.sta.getip()
print(ip)
-- nil
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
ip = wifi.sta.getip()
print(ip)
-- 192.168.18.110
Manipulate hardware like a arduino
pin = 1
gpio.mode(pin,gpio.OUTPUT)
gpio.write(pin,gpio.HIGH)
print(gpio.read(pin))
Write network application in nodejs style
-- A simple http client
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(80,"115.239.210.27")
conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
Or a simple http server
-- A simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
conn:send("<h1> Hello, NodeMcu.</h1>")
end)
conn:on("sent",function(conn) conn:close() end)
end)
Connect to MQTT Broker
-- init mqtt client with keepalive timer 120sec
m = mqtt.Client("clientid", 120, "user", "password")
-- setup Last Will and Testament (optional)
-- Broker will publish a message with qos = 0, retain = 0, data = "offline"
-- to topic "/lwt" if client don't send keepalive packet
m:lwt("/lwt", "offline", 0, 0)
m:on("connect", function(con) print ("connected") end)
m:on("offline", function(con) print ("offline") end)
-- on publish message receive event
m:on("message", function(conn, topic, data)
print(topic .. ":" )
if data ~= nil then
print(data)
end
end)
-- for secure: m:connect("192.168.11.118", 1880, 1)
m:connect("192.168.11.118", 1880, 0, function(conn) print("connected") end)
-- subscribe topic with qos = 0
m:subscribe("/topic",0, function(conn) print("subscribe success") end)
-- or subscribe multiple topic (topic/0, qos = 0; topic/1, qos = 1; topic2
, qos = 2)
-- m:subscribe({["topic/0"]=0,["topic/1"]=1,topic2=2}, function(conn)
print("subscribe success") end)
-- publish a message with data = hello, QoS = 0, retain = 0
m:publish("/topic","hello",0,0, function(conn) print("sent") end)
m:close();
-- you can call m:connect again
UDP client and server
-- a udp server
s=net.createServer(net.UDP)
s:on("receive",function(s,c) print(c) end)
s:listen(5683)
-- a udp client
cu=net.createConnection(net.UDP)
cu:on("receive",function(cu,c) print(c) end)
cu:connect(5683,"192.168.18.101")
cu:send("hello")

nodemcu.txt · Last modified: 2016/02/13 12:50 by terrye


https://bigdanzblog.wordpress.com/2015/04/14/nodemcu-devkit-development-board/

ESP8266 NodeMCU DevKit Development Board


Posted on April 14, 2015 by Dan TheMan

(click here to see index of all ESP8266 posts)

https://bigdanzblog.wordpress.com/test/#esp8266

Before I get started trying to write anything for the ESP8266, I decided to get a NodeMCU
dev board:

This exposes all the pins, let’s you connect directly to a USB cable, and mounts in a
breadboard. And it has the NodeMCU LUA firmware already installed.

This device uses a different chip to connect USB to serial instead of the ubiquitous FTDI
chip. More about this here:

http://hackaday.com/tag/ch340/

Mainly, it requires a different driver. I found reference to the driver here:

http://doityourselfchristmas.com/forums/showthread.php?14690-CH340-USB-RS232-Driver
and if that link goes bad, the driver itself is here:

http://www.winchiphead.com/download/CH341/CH341SER.ZIP

I unzipped the file into the directory CH341. I then updated the driver manually using that
location and it worked perfectly. Even on my old Win XP system.

Connecting to the serial port, I was greeted with the LUA ‘>’ prompt.

I’m ready to write a simple script.

https://bigdanzblog.wordpress.com/2016/02/07/esp8266-and-using-the-arduino-ide/

ESP8266 and Using the Arduino IDE


Posted on February 7, 2016 by Dan TheMan

I noted a while back that the ESP8266 can be directly programmed now using the Arduino
IDE. I’ve played with direct access (AT commands) and Lua in the past. While interesting, I
found both methods a bit clumsy to use. Being able to write my own code on the ESP8266
sounds intriguing.

My first step, and the topic of this post, is to simply get the IDE running to the point where I
can blink an LED with the ESP8266. I’ve got a handful of ESP-01’s laying around so that’s
what I’ll work with.

Before starting, my main reference was the Adafruit post

Using Arduino IDE

and to a lesser extent, the Sparkfun post

ESP8266 Thing Hookup Guide

Setting Up the Hardware

I used my own post, Basic ESP8266 Setup and Operation, to get the basic ESP-01 connected
to the breadboard as I’m still using the same breadboard adapter.

Installing the Arduino IDE

You need at least version 1.6.4 of the IDE to make use of the ESP8266 Board Add-on. You
can download it from here.
Note to self: I do NOT download the Windows installer, but download the Windows ZIP file
instead. I keep multiple versions of the IDE installed and the Windows Installer wants to
overwrite files. The ZIP file contains a directory that I just copy straight to C: to make use of.

Once the IDE is installed, start it, and from the menu select Files | Preferences and enter
“http://arduino.esp8266.com/stable/package_esp8266com_index.json” into Additional
Boards Manager URLs:” field:

Now, from the menu, select Tools | Board | Boards Manager and scroll down to the Esp8266
board:

Click anywhere on this entry and it will give you the option to install and the version to
install:

Select the version (probably the most recent), and click on install.

Now you can select an ESP8266 board in the Arduino IDE:


At this point, I had to restart the IDE to get it to allow me to change the port:

Note that I am using upload speed of 115200 Baud. Though others have set it much faster, I
cannot get anything faster than 115200 to work.

Wiring Up Blinky Circuit

There are two GPIO pins on the ESP-01, GPIO0 and GPIO2. Both are also used during
bootup to determine the run mode. The operation of the GPIO pins are explained here:

ESP8266 Using GPIO0/GPIO2/GPIO15 pins

Using that post as a basis for my own blinky circuit, I ended up with this schematic:
The Program, er, Sketch

GPIO0 and GPIO2 are pins 0 and 2 on the Arduino. I have successfully run this sketch on
both pins. Here, it is set to use pin/GPIO 2:

const int ledPin = 2;

// ------------------------------------------------------------------------
---
void setup() {

pinMode(ledPin, OUTPUT);

} // setup

// ------------------------------------------------------------------------
---
void loop() {

digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}

Compiling and Uploading

You can do just a Control-R to verify syntax. When you are ready to compile and upload,
first you must put the ESP8266 into upload mode. Press and hold Program button (S1,
connected to GPIO 0). Press and release RESET button. Then release the program button. On
my ESP-01, there is no indication it is in program mode.

Now compile and upload using control-U. When the program starts uploading, the blue LED
(tied to the UART TX pin) will begin flashing.

Once the upload is complete, your LED should begin flashing.


https://www.losant.com/blog/getting-started-with-platformio-esp8266-nodemcu

Getting Started with PlatformIO and


ESP8266 NodeMCU
March 30, 2016

 Tutorials
 ESP8266
 PlatformIO
 NodeMCU

The Arduino editor, while functional, has never been a pinnacle of productivity and usability.
PlatformIO has recently been released to bring some much needed improvements to the
ecosystem. The IDE is built on top of GitHub's Atom text editor, which provides an excellent
extensibility model that the Arduino IDE was sorely missing.

The NodeMcu ESP8266 dev board has become an extremely popular choice for an
inexpensive wifi enabled microcontroller for IoT projects. Since the hardware is an open
standard, they can be bought from a variety of vendors. Here's one on Amazon for less than
$10.

In my own experimentation, I've found the ESP8266 Arduino libraries and toolchain to work
much better than the Lua toolchain. C++ can be more difficult than Lua, but being able to
easily and reliably flash the device more than makes up for the difference. This tutorial will
demonstrate how to use PlatformIO to program a NodeMcu microcontroller using the
Arduino libraries.

Install PlatformIO
The first step is to download and install the PlatformIO IDE. If you already have Atom
installed, follow these instructions to install the PlatformIO package. Once installed you
should see the PlatformIO toolbar in Atom. If you don't see the toolbar, all of the options are
also available in a new "PlatformIO" main menu.

Depending on how you install, you may experience the error "command not found: pio"
when performing later steps in this tutorial. If you do, follow the instructions to do a manual
install. For me, it was solved by running "pip install platformio" on my Mac to get the
command line tools properly installed.

Install NodeMcu USB Driver


All NodeMcu boards have a USB to Serial chip that requires a driver for Windows and Mac.
Download and install the driver from Silicon Labs website.

Create Project
Select the "Initialize new PlatformIO project" button and create a new project. This option is
also available in the PlatformIO main menu.
On the popup, select the board and the directory to place your project. Since we're using a
NodeMcu dev kit, select NodeMCU 1.0 (ESP-12E Module) from the dropdown. As you can
see, PlatformIO supports a wide variety of boards. Once you've got the options selected, click
"Initialize". This will take a while the first time as PlatformIO downloads and installs the
correct tools for your board. Once it's done, you'll see some automatically generated files.
We're now ready to write some code.

Hello World
Let's start with a basic hello world example that prints "Hello World!" to the serial output
every second. Right mouse click on the "src" folder and add a new file named "main.cpp".

Copy paste the below code into "main.cpp".


#include <Arduino.h>

void setup() {

Serial.begin(9600);

void loop() {

delay(1000);

Serial.println("Hello World!");

view raw hello-world.cpp hosted with ❤ by GitHub

Next, hit the big checkmark icon or use the PlatformIO->Build menu to make sure everything
compiled correctly. You should get nice "SUCCESS" message at the bottom.
Next, hit the "Upload" button or use the PlatformIO->Upload to flash the ESP8266
microcontroller with this firmware.
When the flashing starts you'll see some progress output on the bottom. NodeMcu's also
typically rapidly flash a small blue LED when flashing.

Next, click the "Serial Monitor" button or use the PlatformIO->Serial Monitor menu to
display the serial monitor.
First, select the serial port to connect to. On a Mac, this will always be named something like
"USB to UART Bridge". On Windows, it will be named something like "Com3". Next, select
the baud rate. This should be the same value you used for the "Serial.begin()" call in the
source code. For our example, we used 9600.

After you click "Start", you should start to see serial output from the microcontroller in a
window at the bottom of the screen.

The serial monitor should print "Hello World!" once a second since.

Using Libraries and Connecting to The Losant Platform


There are a ton of already existing Arduino libraries that we can make use of when
developing connecting solutions. Let's look at how to install and use existing libraries in our
project. For this example, we're going to connect the device to the Losant platform. Doing
this requires three libraries: losant-sdk-arduino, pubsubclient, and ArduinoJson.

First, open the Library Manager by clicking the "Library Manager" button or use the
PlatformIO->Library Manager menu.

The library manager is simply a command line tool. To use it, first search for the required
library, and then install it using the returned id. Let's first install the pubsubclient library.

> pio lib search pubsubclient


Once you see the result, you can install the library using the ID, which is "89" for the
PubSubClient library.

> pio lib install 89

Repeat the same process for the ArduinoJson library. It's called just "Json" in PlatformIO's
library manager.

> pio lib search json


> pio lib install 64

The Losant SDK is not yet in PlatformIO's library manager. You'll need to first clone it into
your project's "lib" folder. Click the "Terminal" button or use the PlatformIO->Terminal
menu to bring up a new terminal. Once open, run these commands.

> cd lib
> git clone https://github.com/Losant/losant-sdk-arduino

You now have all required libraries installed. You can now connect the device to Losant
using the example ESP8266 code from the SDK repo.
When I copy-pasted the example code into the editor, PlatformIO showed some incorrect
compile errors. Hit the "Build" button to see if it succeeds. It appears as though the inline
error checking still needs some tweaks.

The ESP8266 example code from the SDK repo demonstrates everything required for basic
input reading and communication with the Losant Platform. It's now up to you to build
something amazing - maybe a Twitter activity globe?

All-in-all, PlatformIO is a major step forward for the development ecosystem. It has
completely replaced my day-to-day environment. The library management system is a much
needed addition and will bring major productivity boosts to embedded development.

If you have any questions or comments, please feel free to leave them below.
From mybotic

http://www.mybotic.com.my/webshaper/store/viewProd.asp?pkProductItem=1784

Description

NodeMCU is an open source IoT platform. It includes firmware which runs on the ESP8266 WiFi SoC from
Espressif, and hardware which is based on the ESP-12 module. The term "NodeMcu" by default refers to the
filmware rather than the dev kits. The firware ESP8266 uses the Lua scripting language. It is based on the eLua
project, and built on the Espressif Non-OS SDK for ESP8266. It uses many open source projects, such as lua-
cjson and spiffs.

Specification

 Wi-Fi Module – ESP-12E module similar to ESP-12 module but with 6 extra GPIOs.
 USB – micro USB port for power, programming and debugging
 Headers – 2x 2.54mm 15-pin header with access to GPIOs, SPI, UART, ADC, and power pinsMisc –
Reset and Flash buttons
 Power – 5V via micro USB port
 Dimensions – 49 x 24.5 x 13mm

http://www.mybotic.com.my/webshaper/store/viewProd.asp?pkProductItem=2137
Description

This ESP8266 ESPDuino NodeMcu SPI Module TFT LCD display has 128 x 128 resolution and 262 color, it uses
SPI interface to communicate with controller such as Arduino Uno and ESP8266.

Features:

 Size: 1.44 inch


 Interface:SPI
 Resolution: 128*128
 Visual area: 1:1 square
 TFT color screen, the effect is far better than other small CSTN screen
 Drive IC: ILI9163
 Fully compatible and alternative 5110 interface
 Onboard LDO, support 5V/3.3V input voltage, the LED backlight, 3.3V input

http://www.instructables.com/id/HOW-TO-BLINK-LED-USING-ESP8266/

Blink LED Using ESP8266 NodeMCU Lua


WiFi Tutorial

http://www.instructables.com/id/How-to-Install-ESP8266-Into-Arduino-IDE/
Installing ESP8266 Into Arduino IDE
Tutorial

http://arduino.esp8266.com/versions/2.3.0/package_esp8266com_index.json

http://www.instructables.com/id/How-to-Control-Fan-Using-ESP8266-From-WebServer/

Tutorial for Fan Control by Using ESP8266


Module From WebServer

http://www.instructables.com/id/How-to-Control-LED-Using-ESP8266-NodemCU-Lua-WiFi-/

How to Control LED Using ESP8266


NodemCU Lua WiFi From Website

http://www.instructables.com/id/Tutorial-for-ESP8266-ESPDuino-NodeMcu-SPI-Module/

Tutorial for ESP8266 ESPDuino NodeMcu


SPI Module Using Arduino Uno
Other sources

https://makezine.com/2010/12/22/diy-power-meter/

DIY power meter

Bill Porter built this excellent DIY Power Meter to monitor the electricity usage of his home. It’s
capable of measuring not only the amount of power that his house consumes, but also other fun
facts such as power factor, voltage and frequency, and transmits the information wirelessly to a
separate display system. He has a thorough explanation of the design process on his website, along
with source code and schematics for the project. [via Hacked Gadgets]

http://www.billporter.info/2010/12/19/not-so-tiny-power-meter/

Not So Tiny Power Meter


Posted in Projects, Software Libraries, Tutorials by Bill

19 Dec 2010
The Kill A Watt is an awesome product; it measures volts, amps and
power factor of an individual appliance which can be used to calculate power, cost to run, etc.
It’s also quite hackable. But I wanted something that would give me the same data for my
whole apartment. After some Googling, the best I could find was this project from picobay,
but I didn’t want to invest in an expensive network IO platform. There were also some off-
the-shelf solutions, but they too were expensive and limited. Well, time to design my own
solution then.

Enter what I call the ‘Not So Tiny Power Meter’. The catchy name comes from the
microcontroller I used, ATtiny85, and some sizing issues I had with the enclosure.
I started out with a plan to use volt-meter current clamps just like the project I linked above
(photo of clamp from picobay.com) and use a dedicated chip, the AD736, to convert the AC
signal off the clamps to a DC voltage representing the RMS current value. The chips are
expensive, tough to use as I found out, and still require external amplifiers to scale up the
value to 5V ADC range. So I nixed that idea. Instead, I decided to use a single op-amp to
scale up the AC voltage off the clamp and sample it directly with the ATtiny’s ADC. The
circuit would be cheap and easy to design and I can convert the signal to RMS in code.

Then I had a thought. If I’m sampling directly, why not measure more than just amps? As an
EE, I’d love to know more about my power usage, like power factor, frequency, and a more
accurate measure of power by not assuming a voltage like most other projects; but I still
wanted to keep the device simple. Then I had another thought: Why not measure voltage
through the same transformer that’s giving my circuit power? After a few tests, I found that a
properly designed rectifier and regulation circuit wouldn’t distort the source AC waveform
too much. They key was to keep the values of the capacitors before the voltage regulator
(circled in red) to a minimum, just enough to support a stable DC voltage. Anymore and the
inrush when the rectifier diode starts conducting severely distorts the AC wave form.

My design is simple. An AC transformer powers the circuit and a voltage divider drops the
source voltage down to ADC range for measuring. A dual sided half-wave rectifier and
regulation circuit provides +5V and -5V rails. The AC signals off two AC clamps are scaled
up using two op-amps. I planned on using trim potentiometers to calibrate the gains of all the
measurement circuitry, but found it was easier to just use transfer functions (found with
experimentation) in code. Everything is measured with an ATtiny85, and transmitted out of
the breaker panel by a cheap RF transmitter. Since all sources are AC, the ATtiny could only
read the positive half of the waveforms. When the signal would go below the ATtiny’s GND,
the protection diodes and input resistors would protect the ADC pins from damage. With this
design, I can measure voltage & frequency off one phase and current & power factor off both
phases.

(Circuit Diagram, Click for Full Size)

The theory of operation is simple. First, the ATtiny85 will repeatedly sample the volts ADC
pin for over a full period of the 60Hz sine wave. The peak value of the samples is
remembered. Repeat for both current clamp ADC pins. After the max values are captured, the
ADC clock is increased for faster sampling, with higher errors. To measure frequency and
power factor, I used a 8 bit timer that I extended to 16 bit in software. Using the timer, I
measure the difference in time between two peak values of the voltage waveform. Then, I
measure the difference in time between a peak value of the volts waveform, and a peak value
of the current clamp waveform. Repeat for the second clamp. After all these measurements,
some conversions are done to convert the peak values to RMS, times to frequency and power
factor, run through a transfer function to account for various gains in the circuit and
transmitted out via software serial as ASCII sentences with checksum.

Comparing to real measurement hardware, my project had respectable measurement


accuracies of:

 +/- 1 Volt,
 +/- 1 Amp,
 +/- 2% for frequency,
 +/- .03 power factor when current is above 10 amps.

The circuit is designed for 120 Volt, 100 Amp mains, but can be adapted for other systems.

I ran into a few issues through the course of my project. The first issue was with the
enclosure. All good projects should be protected by an enclosure, especially when installed
into a breaker panel. First my poor planning resulting in a enclosure that was too small to
house all the banana jacks for the current clamps. Then the second enclosure didn’t match the
mechanical drawings provided by the manufacture. What stinks is I already had PCBs made
to the spec of the drawings before I received the case. O well, time for double stick foam to
mount the PCB instead inside an overly large box (part of the irony of the name).
The second issue was the quality of the signal off the current clamps. When using function
generators for testing and programming, I could measure frequency, power factor and max
value with great accuracy. The noisy signal off the current clamps is another story. Really,
power factor measurements with currents less then 8~10 amps are very noisy.

Third, I originally used 434Mhz radios, until I realized it is the same frequency as my
external temperature/humidity probe for my clocks. I quickly changed the radios to the lower
frequency versions.

Anyway, I got the project built, tested, and installed into my breaker panel. Everything is
internal so nothing extrudes. Right now, the data is received by another one of my projects,
an Arduquee display. The display just shows live power usage. I plan to experiment with data
loggers to log the data and/or play with the Google PowerMeter API to send the data into the
cloud. This project was just to build a sensor to get the data out of my breaker panel.

Here’s some photos from the build, and the installation into my breaker panel. Click for
larger pics.

Quite a workbench
Checking the signals

Installation into panel

The temporary LED display showing power (Watts), now hanging on my wall. Notice the RF
receiver on the left.
My design is open-source. All the theory of operation is well documented in my code, and all
code and Eagle PCB files are available to download:

Not So Tiny Power Meter files(zip)

I even have extra PCBs for any that what them, $5 plus shipping. Drop me a line in the
comments if interested.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported


License.

https://makezine.com/2013/11/12/smart-metering-for-makers/

Smart Metering for Makers?


There is a whole bunch of smart meters on the market, meters that measure how much
electricity your home is using and that track how your energy consumption is changing with
time. I have one in my own home, and I’ll admit it’s changed my behavior—it’s making me
want to optimize the bottom line—and see if I can get the ‘tick over’ for my house—the
figure that it reports when nothing much is happening in my home—even lower. But it
doesn’t tell me a whole lot about how the individual appliances in my home are working.

In the closing hours of their Kickstarter campaign, Neurio is a smart meter with a difference.
It doesn’t just monitor how much energy your homes is using. It tries to figure out the cost of
running individual appliances using smart algorithms that look for patterns—and potential
problems.

The system will have a public API so you can extend it—connect it to web services, or write
your own applications. It also comes with something they’re calling Trigger,

Trigger is an open-source application for Raspberry Pi and Android. It enables you to receive
a continuous stream of power data directly from the Neurio Sensor. Trigger also comes
equipped with pattern matching capability, so you can detect your appliances in real-time.
With Trigger, you can detect when your garage door opens and turn up your Nest
Thermostat!

Yesterday I talked to Ali Kashani—the software lead—and Jon Hallam—the hardware


lead—of the Neurio project and asked them about their technology, and how it could be used
by makers.

What is Neurio exactly? What’s home intelligence?

I like to use an analogy to explain this. The wiring in our homes is analogous to a nervous
system that connects everything to a central place — the breaker panel. But there’s no brain
there, no intelligence. That’s how Neurio fits in a home. It sits at the center of all devices, and
by monitoring their signals and looking for patterns, it figures out what’s happening with
each device. It can then relay that information to users by notifying them when the laundry is
done, or control wifi-enabled appliances like adjusting the thermostat when you leave home.

What’s the difference between Neurio and other smart energy meters?

In essence Neurio and smart meters both monitor the same electrical signals but they’re built
for very different purposes. Smart Meters are designed to facilitate billing customers, so the
focus is on kWh measurements and low frequency reporting. But Neurio was designed to
perform granular measurements of many attributes beside just kWh, and communicate that in
real-time to the cloud. That detailed data is what drives the algorithms that allows us to do
things like break your bill down by appliance or use. Neurio was also designed for
consumers, so it uses WiFi rather than the less common radio formats typically found in
smart meters.

Neurio learns about the appliances in your home, how does it do that?

Appliances exhibit unique patterns in the way they consume electricity. Neurio monitors the
main electrical lines of a home, and looks for those patterns. It can figure out when a
dishwasher is running, or when a dryer has just finished.

Is there a stage where the user is involved in training the system?

While we have designed the algorithms to work without training, there may be cases every
now and then where a new device is introduced that we don’t recognize. So the users are also
able to provide feedback and “train” the algorithms.

The system talks to the cloud, is that necessary, can it stand by itself?

The cloud is important because our learning algorithms perform best when they look at large
data sets to find patterns and create their models. It’s similar to a search engine; Google
provides every individual with better results by looking at everyone else’s search behavior.
All your data remains private though. We only look at broad trends in anonymized data in
order to build our models.

Neurio Trigger is what makers will be interested in, tell us more about it?

We think there is tons of potential in energy data but without the right tools, that potential
will remain untapped. So we decided to start building those tools, and release them for the
community to use. Trigger will be an open-source application that retrieves real-time data
streams from our sensor, processes that data to infer the states of appliances in your home,
and then performs some kind of action based on that state. For instance, Trigger could notice
that your garage door just opened in the early evening, and welcome you home by turning up
the heat. The idea is to leverage energy data in order to allow you to take ordinary appliances
and get them talking with connected devices. We’re trying to hide all the complexity
involved in such a process and build something that will be easy for anyone to integrate into
their existing projects, and share the result with the community. We’re really excited to see
what they will do with Neurio.

What can you do with it?


You could connect your dryer to your Hue lights so they flash red when your laundry is done.
Or do what our hardware engineer Jon did, and make it so that your noisy robotic vacuum
only runs when you’re not in the house. It can essentially take the state of an ordinary
appliance, and make it trigger some kind of action.

Why just Raspberry Pi and Android? Can you talk to Neurio from something more
lightweight like an Arduino?

Trigger requires more processing power than is available in a typical Arduino, but you can
definitely integrate Arduino-based projects into Neurio other ways. In fact, we’re integrating
Neurio with the Spark Core, which is kind of like an Arduino with superpowers. It’s
Arduino-compatible and integrates a powerful microcontroller and WiFi into a small module.
Our support for the Spark Core means that your Arduino projects could get notifications from
Neurio when someone wakes up in the morning or arrives home at night.

You talk about an open API, and then you talk about Trigger—which is an
application—are they the same thing?

Trigger uses our API to get data from the Neurio Sensor. Both Trigger and the API are open.
In a sense, Trigger actually serves two purposes: it’s a really useful application that also
demonstrates how to develop an application that uses our API. We’re also hoping that the fact
that it’s open-source will allow the community integrate it with all their favourite projects.

In a way, it’s a starting kit with some basic capabilities already implemented in it to make it
really easy to start. It will even be able to send commands to other home automation products
that we’re partnering with, so it’s like a do-it-yourself kit ready to be applied to your
favourite projects.

Is this what you set out to build? How has it changed over the course of moving from
prototype to Kickstarter?

A lot has changed actually. For instance, we had to announce a redesign to our sensor board
to accommodate the demand from all the 3-phase homes, mostly in Europe, that we weren’t
expecting. We also added an expansion port as a stretch goal, in order to allow the
community to build their boards to extend the Sensor’s capabilities, and do things like control
appliances from within the breaker panel.

The project is now in its closing hours and over 200% funded and closing in on the last of its
stretch goals.

You might also like