Sending Email using Arduino and ESP8266 WiFi Module
Sending Email using Arduino Uno
and ESP8266 Wi-Fi Module
We are
moving towards the World of Internet
of Things (IoT). This technology plays a very important role in the
Electronics and Embedded system. Sending
an Email from any Microcontroller or Embedded system is very basic thing, which
is required in IoT. So in this article, we
will learn “How to send an Email using Wi-Fi and Arduino”.
For
sending Email via Wi-Fi module and Arduino, first
of all we need to have an Email account. So user can create email account at smtp2go.com. After
signup, remember your new email address and password.
We can
understand the whole process in below Steps:
Step 1: First
arrange all the required Components.
·
Arduino UNO
·
ESP8266 Wi-Fi module
·
USB Cable
·
Laptop
·
16x2 LCD (optional)
·
10K POT (optional)
·
Power supply
·
Connecting wires
Wi-Fi Module ESP8266:
Step 2: In
this step we will connect ESP8266 Wi-Fi
module with Arduino and give it power supply from 3.3v pin of Arduino.
Step 3: In
this step, we need to sign-up for
Email address and Password (smtp2go.com). smtp2go.com
provides the email services, to send the emails using outgoing email server.
Step 4: We
will need Username and Password in base64 encoded format with utf-8 character set. For converting the Email and Password in base64
encoded format use below given link. Keep
the encoded username and password handy, we need it in our program to login at
smtp2go.com.
Step 5: Now
start writing code for sending Email. ‘Programming
Explanation’
and Code is given at the end.
Circuit Explanation:
Circuit
is very simple, for this project we only need Arduino and ESP8266 Wi-Fi module. A 16x2 LCD is also connected for displaying the
status messages.
This LCD is optional. ESP8266’s Vcc
and GND pins are directly connected to 3.3V and GND of Arduino and CH_PD is also connected with 3.3V.
Tx and
Rx pins of ESP8266 are directly connected to pin 2 and 3 of Arduino. And Pin 2 of Arduino is also shorted with Tx pin (Pin 1) of
Arduino.
This pin is shorted for
displaying response of ESP8266 directly on Serial monitor of Arduino. Software Serial Library is used to allow serial
communication on pin 2 and 3 of Arduino.
Note: For watching the response of ESP8266 on Serial
Monitor, don’t initialise the Serial.begin(9600) function.
Programming Explanation:
1. In programming part first we include
libraries and define pins for LCD & software serial communication. By default Pin 0 and 1 of Arduino are used for
serial communication but by using SoftwareSerial library, we can
allow serial communication on other digital pins of the Arduino.
2. void connect_wifi(String cmd, int t) Function is defined to Connect the Wi-Fi module to the Internet.
void
connect_wifi(String cmd, int t)
{
int temp=0,i=0;
while(1)
{
Serial1.println(cmd);
while(Serial1.available())
{
if(Serial1.find("OK"))
... .... ....
... .....
3. After it connect module to SMTP server by using
given commands:
lcd.print("Configuring Email..");
Serial1.println("AT+CIPSTART=4,\"TCP\",\"mail.smtp2go.com\",2525");
delay(2000);
Serial1.println("AT+CIPSEND=4,20");
delay(2000);
Serial1.println("EHLO 192.168.1.123");
delay(2000);
Serial1.println("AT+CIPSEND=4,12");
Note: Many email servers will not accept email from a
non-commercial, dhcp-issued ip address.
4. Now we will try to Login at smtp2go.co, using the base64 encoded User name and
password, which we have derived in Step 4 above.
lcd.print("Try To Login.....");
Serial1.println("AUTH LOGIN");
delay(2000);
Serial1.println("AT+CIPSEND=4,30");
delay(2000);
Serial1.println("c2FkZGFtNDIwMUBnbWFpbC5jb20="); //base64 encoded username
delay(2000);
Serial1.println("AT+CIPSEND=4,18");
delay(2000);
Serial1.println("Y2lyY3VpdDQyMDE="); //base64 encoded password
5. After this, enter your main message that user want
to send.
And send this email by ending
line (sending)
‘.’
Serial1.println("Testing Success");
delay(2000);
Serial1.println("AT+CIPSEND=4,3");
delay(2000);
Serial1.println('.');
delay(10000);
Serial1.println("AT+CIPSEND=4,6");
delay(2000);
Serial1.println("QUIT");
... .....
.......
Demo & Code
Sending Email using Arduino and ESP8266 WiFi Module
Reviewed by XXX
on
สิงหาคม 27, 2560
Rating:
ไม่มีความคิดเห็น