Reading analog signals
The ESP8266 has one analog pin that we can use to read analog signals. In this recipe, we will be looking at how to write a sketch that reads analog signals. This will enable us to read input from analog sensors.
Getting ready
Connect your ESP8266 board to your computer via a USB cable and set up your Arduino IDE (refer back to Chapter 1, Configuring the ESP8266). Once that is done, you can proceed to make the other connections.
In this recipe, we will need a breadboard and jumper wires in addition to the ESP8266 board. Mount the ESP8266 board onto the breadboard and then connect a jumper wire from the analog ADC pin to the GND pin. The connection should be as shown in the following diagram:
How to do it…
We will use the analogRead()
function to read the analog signal on the ADC pin and display the analog signal value on the serial monitor. This will be repeated every 1 second:
// LED pin int val = 0; void setup() { Serial.begin(9600); } void loop() { /...