Reading digital signals
One of the uses of the ESP8266's GPIO pins is to read digital signals. This allows you to control your project using input devices and also to monitor sensor data. In this recipe, we will look at how to read digital signals using GPIO pins.
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 few extra components. They include:
- Breadboard
- Jumper wires
Mount the ESP8266 board onto the breadboard and then connect a jumper wire from pin 5 to the GND pin. The connection should be as shown in the following figure:
How to do it…
We will configure pin 5 as an input, then read it using the digitalRead()
function and display the state of the input signal on the serial monitor. This will be repeated every 1 second:
// LED pin int inputPin = 5; int val = 0; void setup() { Serial...