Analogue to Digital with the ESP8266

This project is to read up to eight analogue values using an ESP8266. The ESP8266, unlike an Arduino for example, has only one 10-bit analogue input measuring 0-1V
and so
an analogue-to-digital converter chip is required if you need more inputs. The
Microchip MCP3008 provides eight analogue inputs and there's a four input version too,
the MCP3004. The digital result
from each channel is read individually by the ESP8266 as an integer value between 0 and 1023, representing a 10-bit resolution.
The voltage reference pin, Vref, must be connected
to the ESP8266's 3.3V supply.
This also caps Vref at 3.3V because it cannot exceed Vdd but the
range 0-1023 is still covered by the range 0V to 3.3V. If you need more than 10-bit resolution then you can use the 12-bit
Microchip MCP3208 instead. If you are just writing out the
digital value then the program still works but you'll need to change your program if it maps the old 0-1023 range, otherwise your results will be a quarter of what
they should be.

The connections for an MCP3008 are shown here. Vref is the voltage to be used at full scale, that is, a reading of 1023. You can scale this value down using
any of the map() functions available on the Internet.

You should tie any unused inputs to ground (GND, 0V) using a 10kΩ resistor, one for each input. If you leave the inputs floating,
you will read spurious values, which you could of course just ignore.

The program to read the values is really straight-forward.
You need to add #include <mcp3008.h> and add mcp3008.cpp to your source code.
The program listed here reads all eight inputs but you could of course modify it to read only
the input(s) you're interested in. The program also uses the delay() function to wait for 1s
between each set of readings. The MCP3008 can make up to 200,000 conversions per second at 5V, so somewhat less at 3.3V and then it's dependent upon the speed of the ESP8266.
You can download the MCP3008 header and source file from Github.