Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

SENDING TEXT MESSAGE USING ESP8266

By Prabakaran P.M

This tutorial is to make the reader understanding the concepts behind sending SMS through the internet. For this we are going to use ESP8266 WiFi module which will detect the button press and send a message to the predefined number, this technique can be used in alarm systems, security alerts, SMS based embedded applications, etc. Programming part is done through LUA scripting language.

You can go through “Getting started with ESP8266” if you are new to this. Before continuing with this project you have to flash ESPs with NodeMCU firmware and go through Getting Started with the ESPlorer IDE.

Circuit Connection:

Here we are using USB to TTL converter for connecting the Module with the PC. The 3.3V output of the converter is used to power the module.

The connection details are as below:

ESP8266

USB-TTL

Vcc

3.3v

Gnd

Gnd

TX

RX

RX

TX

CH_PD

Connected to 3.3v to enable chip firmware boot

Don’t forget to pull up CH_PD HIGH, you won’t get a response from the module if it is not done.

You can also use Arduino for the connection. For more details refer here.

The connection details are as below:

  ESP8266

Arduino UNO

Vcc

3.3v

Gnd

Gnd

TX

TX

RX

RX

CH_PD

Connected to 3.3v to enable chip firmware boot

Connect a Push button to GPIO 2 which is pulled down to the ground.

Disconnect the GPIO 2 from the button while powering up the module to avoid unnecessary Reset. s

Downloading ESPlorer:

It’s recommended to use the ESPlorer program to open and save Lua files into your ESP8266.

Follow these instructions:

1.     Download ESPlorer.

2.     Unzip that folder.

3.     Run ESPlorer.jar. It’s a JAVA program, make sure that JAVA is installed on your computer.

4.     Open the ESPlorer.

Steps involved in implementation:

Three steps are mandatory for the implementation of this technique.

1.     A Nexmo account. https://dashboard.nexmo.com/sign-up.

2.     A Thingspeak account. https://thingspeak.com/users/sign_up

3.     NodeMCU SMS Messaging Code.

STEP 1:

After signing up with an account in Nexmo which provides you an SMS API. Make sure to note down the key and the secret from the API settings tab.

Image showing TDA7056 based Audio Amplifier Circuit designed on a breadboard

Fig. 1: Screenshot of Nexmo Sign Up Page

Next step is to add numbers and verifying it you can add 10 numbers in the free version of Nexmo. Now you can check the API by copying the below link and pasting it into the address box of your favourite web browser.

http://rest.nexmo.com/sms/xml?api_key=xxxxx&api_secret=xxxxxx&from=senderID&to=destination_number&text=messagebody

Replace necessary values in the URL (you can get all these from the Nexmo site).  Upon hitting “Enter” you should receive a text almost immediately.

Image showing TDA7056 based Audio Amplifier Circuit designed on a breadboard

Fig. 2: Screenshot from Nexmo website showing API Key and Secret Password used for sending text messages using ESP8266 Wi-Fi Module

API Key and Secret can be found in as shown in the above picture.

Sender ID can be any, Destination number should be entered with the country code without “0” or “+” for example, India country code is “+91” you should enter the number like” 919876543210” without any space. Be sure to verify the destination number.

STEP 2:

Since ESP8266 doesn’t support HTTPS secured connection and Nexmo will not get a request in HTTP connection, we need to bridge these two by using HTTPS relay, which will receive HTTP requests ESP8266 and convert to the HTTPS request. For this, we are going to use Thingspeak.com, after signing in go to apps, then to ThingHTTP and create a new Thing HTTP.

Make the following changes in the setup page, “XXXX” are to be changed to your credentials.

1.     Name:SMS

2.     URL:https://rest.nexmo.com/sms/json?api_key=XXXX&api_secret=XXXX&from=XXXX&

3.     Method: POST

4.     Content-type : application/x-www-form-urlencoded

5.     Click remove headers, and leave host blank

6.     Body: to=%%number%%&text=%%message%%

7.     Leave other blank

8.     Click Save ThingHTTP

 

Image showing TDA7056 based Audio Amplifier Circuit designed on a breadboard

Fig. 3: Screenshot from Nexmo website showing convertion of https protocol supported by ESP8266 Modem on Thingspeak Server

You can now send your request to ThingHTTP and view the response using the following URL:

https://api.thingspeak.com/apps/thinghttp/send_request?api_key=XXXX &number=91XXXX&message=Hi from Esp8266

STEP 3:

NodeMCU SMS Messaging Code is written in LUA and uploaded using Esplorer. Here we are using a button to trigger the SMS sending code. For this button interface, we are using Interrupt with debounce in ESP8266.

Using interrupt mode:

If we want to know when a pin’s value change (ie. At once a button is pressed) a better solution is to use interrupt mode. That way we can create a function and set it to be called every time the pin’s value changes.

We define which callbacks are called when by using gpio.trig().

Let’s write to the console when GPIO2 changes value:

local pin = 4    –> GPIO2

function onChange ()

    print(‘The pin value has changed to ‘..gpio.read(pin))

end

gpio.mode(pin, gpio.INT)

gpio.trig(pin, ‘both’, onChange)

Event name Description
up Occurs when the pin moves high.
down Occurs when the pin moves low.
both Occurs when the pin moves high or low.
low Occurs repeatedly while the pin is low.
high Occurs repeatedly while the pin is high.

Debouncing:

When you press a button down the pin changes value, changes back again and finally settles on the new value once more. This is called contact bounce and it is common.

For avoiding this Software debouncing is implemented by the following code:

local pin = 4    –> GPIO2

function debounce (func)

    local last = 0

    local delay = 200000

    return function (…)

        local now = tmr.now()

        if now – last < delay then return end

        last = now

        return func(…)

    end

end

function onChange ()

    print(‘The pin value has changed to ‘..gpio.read(pin))

end

gpio.mode(pin, gpio.INT)

gpio.trig(pin, ‘both’, debounce(onChange))

The debounce() function takes a function as its argument and wraps it in another. When the outer function is called, that then calls the inner function, but only if it hasn’t been called in the last 5000us (5ms).

The POST request to send a text message is the following:

1.     POST : /apps/thinghttp/send_request?api_key=XXXX

2.     Host: api.thingspeak.com

3.     Connection: close

4.     Content-Type: application/x-www-form-URL encoded

5.     Content-Length: xxx

6.     number=91XXXX&message=my message

This project consists of two codes one should be named as init.lua and this is responsible for the initialization of the connection with WiFi router it will retry until connection to the router and getting the IP address and then it will call SMS.lua which will send the SMS once the button is pressed.

Uploading Your Lua Script:

Follow these steps to send the code to your ESP8266:

1)    Connect your FTDI programmer and select your FTDI COM Port.

2)    Set baud rate at 9600

3)    Select NodeMCU+MicroPtyhon tab

4)    Copy your Lua script into ESPlorer and save your file with the name “init.lua” and SMS.luas respectively.

5)    Upload to the ESP and Run on ESP.

Download code

Don’t forget to change the SSID, Password to your Home WiFi Network and Api_key in the code.

Working:

Here the ESP8266 is connected to the WiFi home network and initialized with the coding when the button is pressed the ESP8266 will POST the request to the SMS API and the message will be sent to the predefined number. This technique is very much useful in the Security systems.

Project Video


Filed Under: Featured Contributions

 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Avalanche Pulser
  • Measure AC current accurateley (100mA to 10A)
  • SDR with external LO input
  • Timer MC14541B wrong delay
  • simple LSB explanation please

RSS Electro-Tech-Online.com Discussions

  • bluetooth jammer
  • Disabled son needs advice please
  • DIY bluetooth speaker
  • Someone please explain how this BMS board is supposed to work?
  • HV Diodes
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering