Professional Documents
Culture Documents
by adachsoft
How to increase the number of I/O pins on the Arduino IDE. NodeMCU, ESP8266 is a very good
ESP8266 using the PCF8574. This example will use solution for IOT (Internet of things).
four buttons (as inputs) and four relays (as outputs)
and only one PCF8574 chip. The four pins of the This article can also see here:
PCF8574 chip will be set as inputs and four pins as
outputs. In this example I will use NodeMCU but it How to use ESP8266 with PCF8574 - 4 input and 4
works well on ESP8266-01. In this tutorial I will also output
show you, how to use jQuery AJAX with ESP8266.
The software for the ESP8266 was written in the
Step 1: Components
ESP8266
Relay Module 250V 10A
Button switch
Some wires
PCF8574
Resistors 10k ohm
Step 2: Schematic
How to Use ESP8266 With PCF8574 - 4 Input and 4 Output: Page 1
Step 3: Software
Configure WIFI connection and HTTP server. Before you upload the software to ESP8266 setup
your WiFi connection. The HTTP server allows us to control relayers using a web browser.
//WIFI i server HTTP
ESP8266WebServer server(80);
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
#define HOST_NAME "onoff"
In this code fragment we setup the i2c bus and our PCF8574 I/O expander. Using this "pcf8574.begin (0xF0)"
we set 4 pins in high as inputs and 4 pins in low as outputs.
Wire.pins(PIN_SDA, PIN_SCL);//SDA - D1, SCL - D2
Wire.begin();
pinMode(PIN_INT, INPUT_PULLUP);
This part of the code is responsible for handling the PCF8574 interrupt. If PIN_INT is low,
our expander notifies us of a change in input. After reading the pin values from the expander,
PIN_INT will return to high.
if( CheckKey(keys, 0) ){
Serial.println( "KEY 0");
SW_toggle(0);
}
if( CheckKey(keys, 1) ){
Serial.println( "KEY 1");
SW_toggle(1);
}
if( CheckKey(keys, 2) ){
Serial.println( "KEY 2");
SW_toggle(2);
}
if( CheckKey(keys, 3) ){
Serial.println( "KEY 3");
SW_toggle(3);
}
}
1. Select your board Tools -> Board -> NodeMCU 1.0(ESP-12E Module)
2. Press the upload button
3. After uploading the software in Serial Monitor you can see the IP of your ESP8266.
1. Select your board Tools -> Board -> NodeMCU 1.0(ESP-12E Module) 1. Press the upload button
1. After uploading the software in Serial Monitor you can see the IP of your
ESP8266.
Take IP from Serial Monitor and type in web browser. You will see the control panel of the ESP8266, thanks to
which you can control the relays. You can also control the state of the relays using the buttons. If you turn on the
relay with the physical button, the state of the relay will change automatically. This is possible thanks to the use of
jquery ajax. The below piece of code that is responsible for it.
html += "</script>\r\n";
//END: AJAX ------------------------------------------