BC Robotics

Getting Started With The ESP8266 1 Channel Relay Board

  PRODUCT TUTORIAL

The ESP8266 has been an integral part of the growth of simple, low-cost, IoT devices. This very small, low powered, WiFi Enabled microcontroller is ideal for applications needing just a few IO and a little processing power. We have built upon all of these features with this relay module and used it to make a simple IoT relay with all of the supporting elements required.

About The Board:

Our ESP8266 Relay Board is designed around the ESP-12E module, one of the most common ESP8266 boards out there. The relay board provides all of the ESP-12E’s external requirements, includes one 10A relay, and a Qwiic (I2C) connector. With the ability to easily add sensors and other modules via the Qwiic connector, this WiFi Connected Relay becomes quite useful for basic automation tasks. Best of all, this board has been designed to fit a Hammond 1591L enclosure, making deployment a breeze!

How It Works

Relays can be thought of as big electronically controlled switches. Being able to control them with a microcontroller or single board computer is one of the key elements in basic automation – but it isn’t as simple as just connecting a relay to your ESP8266. Powering a relay requires a lot more current than can be provided by a simple digital output from a microcontroller. Also, when the relay coil is de-energized, the reverse voltage spike is particularly harmful to sensitive electronics! So, additional circuitry is required! Our ESP8266 1 Channel Relay Board has the required driver circuit and packages it neatly on a single circuit board so all you need to do is plug everything in – no need to worry about transistors, diodes,  or any of that! 

The Parts Needed:

Since this board is fully assembled, we don’t require much in the way of additional components to get this up and running. All that is required is a TTL Serial Cable and a means of connecting to the board’s programming pins. 

Optionally, you may want to consider the following parts as well:

Step 1 - Arduino Software

If you have never programmed an ESP8266 board with your Arduino software, there are a few steps that will need to be completed first.  The ESP8266 is not included in the base configuration of the Arduino IDE, so we will have to add it using the board manager. We have put together an easy to follow tutorial here: 

Once everything is set up, we can move to the next step. 

20%

Step 2 - Powering The Board

Unlike many of our other boards, the ESP8266 1 Channel Relay Board requires external power to be programmed. There is no USB cable to provide this power, so we will need to get this board powered up first.

The five pin connector at the bottom of the board provides power and breaks out the three SPDT relay pins. We will be focusing on the two pins to the left: “VCC” and “GND” (highlighted in the photo) which provide the board power. Generally this input should be kept within 11-14VDC but it will tolerate 9-15VDC. Any lower and the relays will not have enough power to operate, too high and the relays will start to get too hot. 

With your power source disconnected, attach the correct wire to each of the two pins. Once completed, double check the connection and reconnect your power source. 

With power enabled, the Green LED at the top right of the board labeled “3.3V” should be illuminated and the ESP’s blue LED should start blinking slowly. If this is not the case, disconnect power immediately and contact support

40%

Step 3 - Programming Cable

To program the ESP8266 we will need to connect our serial cable to TXD0, RXD0, and GND. When using the recommended cable the connections should be as follows:

  • White to TXD0
  • Green to RXD0
  • Black to GND
  • Red is left disconnected 

We have opted to solder a chunk of breakaway header to this side of the board to make this as easy as possible, but if you are only uploading something quickly, test cables or another form of temporary connection will also work. 

60%

Step 4 - Programming Mode

Unlike most Arduino, where you can simply hit “Upload” and the program will automatically be uploaded to the board, there is one extra step when using the ESP8266. The board is required to be in programming mode, otherwise it will not accept the upload from the Arduino IDE. 

To get the board into programming mode:

  1. Press and hold the “PRGM” Button
  2. While holding “PRGM” press and release the “RESET” button. 
  3. Release the “PRGM” button.
  4. The blue light on the ESP should flash. 

 

80%

Step 5 - Testing Code

Now that we have finished with the hookup we need to start writing some code. Since the ESP is already set up in Arduino using the tutorial linked earlier, this will be fairly simple. The Relay is attached to GPIO 15 , so in our example we are going to write a simple program that will turn the relay on and off with a one second delay between each action. 

We are starting with the BareMinimum Sketch found in the IDE, it should look something like this: 

				
					void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
				
			

So first we will need some variables for the Pico GPIO pins we plan to use:

				
					int relayPin1 = 15; //This is the ESP Pin that will control Relay #1

void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
				
			

Basically we are going to reduce the opportunity for confusion later down the road by assigning names to each of the ESP’s pins we use. Now, instead of trying to remember that ESPGPIO Pin 15 is Relay number 1, we will simply just refer to the variable “relayPin1” instead – much easier!

Next we will set the pin we are using to be a digital output:

				
					int relayPin1 = 15; //This is the ESP Pin that will control Relay #1

void setup() {
// put your setup code here, to run once:
    pinMode(relayPin1, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

}
				
			

Ok, now all of the pins are set to outputs. Next we can write some code in the loop to switch a relay on and off:

				
					int relayPin1 = 15; //This is the ESP Pin that will control Relay #1

void setup() {
// put your setup code here, to run once:
    pinMode(relayPin1, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(relayPin1, HIGH); //Switch Relay #1 ON
delay(1000); //Wait 1 Second
digitalWrite(relayPin1, LOW); //Switch Relay #1 OFF
delay(1000); //Wait 1 Second
}
				
			

If we were to upload this code to the ESP it will turn Relay #1 on for 1 second and then switch it off for 1 second and continue through this loop forever. Let’s try it!

  1. Ensure your ESP is in programming mode by using the directions mentioned in Step 4.
  2. Once it is in programming mode, start by hitting the upload button in the Arduino IDE. This can take a little while to compile and upload. 
  3. On completion, restart the board entirely by shutting off power, and restarting it. 

After power has been restored, the relay should now click on and off every second.

This is just the most basic code triggering the relay, but it should give you a point to start off from. Going forwards you can use this board’s Qwiic / STEMMA QT interface to connect various sensors or use the ESP8266’s WiFi interface to control when these relays are triggered.

100%

Leave a Reply

Your email address will not be published.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
  • Attributes
  • Custom attributes
  • Custom fields
Click outside to hide the comparison bar
Compare