Through the use of an electrical schematic I made available in PDF format, in today's project, an Arduino Mega is connected to the ESP8266 to make WiFi function. Principally for residential automation, the circuit also works with Bluetooth, and is connected to two relays and two lamps. For all this to occur, we’ll need to enable the control of up to 68 energy points. This will happen through an APP, Labkit, accessed through an Android phone or tablet. In this assembly, you won’t need to program the Arduino or the ESP8266. We’ll also begin to use the AT commands. Check out the video:
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Electric Scheme
Mega WiFi Circuit with Relays Here in the electrical scheme, you can see I used an Arduino Mega connected to an ESP8266 to do the WiFi function. It is useful to remember that this circuit could also work with Bluetooth. In this example, I also connected two relays and two lamps. I emphasize that on the board with the two relays, you can connect another 34 boards with two or eight relays, according to your preference. Later on, I'll explain precisely how to do it.
Step 2: Residential Automation With Up to 68 Power Points
We use Labkit during our project. This App is designed to control devices connected to an Arduino Uno or Mega. Through a Bluetooth module or an ESP8266 connected to the Arduino, we can communicate with the devices through an Android phone or tablet.
Step 3: Tools Used
In this project, we use the ESP8266 and the Arduino Mega, in addition to three programs and two files. As noted on the left side of the image, the Flash Download Tools program will run the Firmware AT file, which will be passed into the ESP8266. In the sequence, you will have Termite, that is, a terminal for you to communicate with AT mode, which will receive your commands and send configurations to ESP8266.
In the part involving Arduino Mega, which appears on the right side of the image, we also load the firmware Labkit HEX file, through the XLoader program.
Step 4: Assembly ESP01 and FTDI
To put the ESP01 into recording mode to install the AT firmware, simply follow this assembly.
ATTENTION: To use the AT commands via Termite, remove the connection between the GPIO0 and the GND.
Step 5: Load Hex Into Arduino
To use this app, it is necessary to load the Arduino with a hex file, which is an already-compiled code that we make available. To install hex in Arduino, we first need a program called XLoader that can be downloaded through this link.
The interface of the XLoader program is this in the imagem.
Step 6: Install Hex on Arduino
- In the Hex file, there should be the path to the hex, which can be downloaded through this link to the Arduino Mega and this link for the Arduino Uno.
- The device is the Arduino model. Select which Arduino to use.
- COM port is the port where the Arduino is plugged into the computer, and a list will be displayed with the ports in use. Select the one that matches your Arduino.
- The baud rate is automatically set for each type of device.
- After all the fields are configured, just click Upload and wait for the process to be completed.
Step 7: ESP8266 in AT Mode
The .hex that we put in the Arduino will communicate with the ESP through the AT protocol. For this, it is necessary that the ESP has the AT firmware installed. The version of the SDK we used was esp_iot_sdk_v1.5.0_15_11_27.
To check out the firmware version that your ESP is using acess the Termite program:
With the Termite open, type AT+GMR in the text input field below.
Step 8: Installing AT Firmware in ESP
If it is not in the version that we use, you can download the AT firmware of the ESP that we use here.
To install the firmware, you will need to download Flash Download Tools from this link.
To install the firmware on an ESP01, you can use an FTDI with the assembly in the image.
Unzip the file esp_iot_sdk_v1.5.0_15_11_27, and open the Flash Download Tools program.
Check the SpiAutoSet option.
In each field, select the files of the uncompressed folder in this order:
For each file, change the ADDR field in this order:
See the diagram
It should look like the picture
Choose the COM PORT that is your ESP and the baud rate of 115200, and click the START button.
Step 9: Configuring ESP
Now let's configure ESP01 to connect to our network. Open the Termite and type:
AT+CWMODE_DEF=1 (puts ESP in station mode)
AT+CWJAP_DEF="TestSP","87654321" (replace with SSID and password for your network)
AT+CIPSTA_DEF="192.168.2.11" (replace with the IP you want to use)
AT+CIPSTA? (To verify that you have the correct IP)
Step 10: Example
Here we have the result of Termite. This displays the version and whether or not all the commands you execute are okay, among other details.
Step 11: Other Circuit Examples
Here I put the schematics with the Uno and Mega Arduinos, with the level converter, the HC-05, both with possibility of use with WiFi or Bluetooth. In our example today, we use the Mega with WiFi, plus two resistors instead of the level converter. But here we show the other cases, because the software allows these other combinations.
Uno Bluetooth Circuit
Uno Wifi Circuit
Mega Bluetooth Circuit
Mega WiFi Circuit
Step 12: Download the App
The app is in the Google Play store at:
Step 13: Pair Bluetooth
If you are going to use the Bluetooth module, make sure you have Bluetooth turned on and paired with the smartphone in the system settings.
Step 14: Labkit Automation Control
- When you open the application for the first time, you will see the blue screen LABkit.
- Click the button in the upper left corner, and the app will ask what type of Arduino you are using.
- After choosing the type of Arduino, the app will ask which module you are using to connect.
- If you have chosen WiFi, enter the IP in the field that appears.
- If you choose Bluetooth, you will have to enter the module name.
- When connecting, the app will show a button to add new actions in the lower right corner.
- By clicking this button, a screen will appear for you to choose the Arduino pin, and the name of the action.
- When adding a new action, it should appear in the list as in the following image.
- Clicking the button will light it green, and the pin of the Arduino you chose should go High.
- To remove an action, simply touch and hold onto the button