How to Send E-mail using PIC Microcontroller and ESP8266

Sending email with PIC

Sending email with PIC

In this tutorial let us learn how to send E-mails from PIC Microcontroller using famous WiFi module the ESP8266. This tutorial uses PIC16F877A IC and MPLABX and XC8 compiler for programming.

At the end of this tutorial you will be able to send E-mail from any normal E-mail ID like Gmail, yahoo etc to any other E-mail ID. Hence this tutorial assumes that you have some basic knowledge on ESP8266-01 Modules and PIC Microcontrollers. If not, the following tutorials will help you

Getting your Hardware Ready:

The complete schematic of the project is shown below.Circuit for Sending Email w

The LCD display is used here for debugging purpose. It is not mandatory for you to connect this. The program will work fine even without the LCD display. If you want to know more about the schematics you visit this tutorial. (Interfacing PIC with ESP).

You can simply assemble this circuit on a breadboard and then proceed with the programming.

Programming your PIC to send E-mail:

In order to send an E-mail from the ESP8266 a sequence of AT commands has to be sent to the ESP module. The following steps have to be followed to send an E-mail from ESP8266.

  1. Set the module in AP+STA (Access Point and station) mode
  2. Connect to an Access point to get internet connection
  3. Enable multiple connections
  4. Start a server on any specific port
  5. Establish a TCP connection  with SMPT2GO website
  6. Navigate to the Login section of the website
  7. Enter the E-mail ID and Password in base64 format
  8. Enter From mail ID
  9. Enter To mail ID
  10. Enter the Subject of the mail
  11. Enter the body of the mail
  12. Indicate the end of mail
  13. Send the mail
  14. Quit the TCP connection

It is a bit lengthy and tedious process but do not worry. I have simplified the process by creating a header file and you can use it directly by just calling some functions (explained below) which makes this task very easy. The complete code along with the header file can be downloaded from here.

Note: If you are using the code in a new project make sure you download the header file and add it in your project.

I have explained some important parts of the code below, the other parts are self explanatory. But if you have any doubts feel free to use the comment section.

/*Check if the ESP_PIC communication is successful*/




    Lcd_Print_String("ESP not found");

    }while (!esp8266_isStarted()); //wait till the ESP send back "OK"


    Lcd_Print_String("ESP is connected");



    /*Yes ESP communication successful -Proceed*/

This part of the code is used to check if there is a proper communication established between the PIC and ESP8266. Only if, both of them could send and receive data through USART the program will proceed to next step.

Read more: How to Send E-mail using PIC Microcontroller and ESP8266

Leave a Comment

Your email address will not be published. Required fields are marked *