Reading data from a GPIO pin

In the second project in this chapter, we are going to read the state of a GPIO pin. For this, we will use the same pin as in the previous project. You can therefore remove the LED and the resistor that we used in the previous project.

Now, simply connect this pin (GPIO 5) of the board to the positive power supply on your breadboard with a wire, applying a 3.3V signal on this pin.

Reading data from a pin is really simple. This is the complete code for this part:

// Import required libraries #include <ESP8266WiFi.h> void setup(void) { // Start Serial (to display results on the Serial monitor) Serial.begin(115200); // Set GPIO 5 as input pinMode(5, INPUT);} void loop() { // Read GPIO 5 and print it on Serial port Serial.print("State ...

Get Internet of Things with ESP8266 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.