element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Sending WhatsApp message from Esp8266
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi Projects requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bidrohini
  • Date Created: 19 May 2023 3:46 PM Date Created
  • Views 182 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Sending WhatsApp message from Esp8266

bidrohini
bidrohini
19 May 2023

Whatsapp has made communication very easy. We can send calls, messages, and video calls from anywhere in the world. All we need is Wi-Fi or mobile data. There is no charge. We can receive notifications from a gas sensor on our mobile phones through WhatsApp. This tutorial will show how. 

Working principle:

We will use an ESP8266 as the main processor for the project. , we know that ESP8266  has its own Wi-Fi module. Through this Wi-Fi module, ESP8266 can connect itself to a Wi-Fi network.

The ESP8266 will be connected to a Wi-Fi network. We will connect the MQ-2 to the ESP8266. The MQ-2 sensor can detect various types of gases.  Gas from stoves, alcohol fumes, and smoke are among them.

There will be a  pre-defined WhatsApp number. When the sensor detects any gas or smoke, our project will send an alert message to that number.

To send messages on WhatsApp, we will use an API called CallMeBot.

What will we learn from this project?

  • How to send Whatspp message from ESP8266.

 

  • How to read MQ-2 sensor data with  ESP8266.

Components needed

Quantity

ESP8266 NodeMCU V2 Development Board with CP2102

1

Gas Sensor Module (MQ-2)



1

Breadboard(830 point)

1

Male to male jumpers

3

Micro USB cable 

1

App and API needed:

  1. Whatsapp 
  2. CallMeBot

Circuit connection:

Arduino UNO

MQ-2

3V

VCC

GND

GND

A0

A0

image

My setup looked like this in real life: 

image

App installation:I assume, whatsapp is installed in your mobile.  If not, download and install it from here. 

 

API Key generation: To use  CallMeBot, follow the steps described below: 

 

Save  +34 644 44 21 48 in your phone’s contact list। You can save by any name.

Now send this message from whatsapp to the number above  “I allow callmebot to send me messages” ।

 

You will receive a reply. It will include your API key. You’ll have to write the API key in your programme. 

image

Is it your first project with ESP8266?  If yes, you have to finish some tasks before. You have to perform board installation. You can see the procedure here.

Library installation: Open  Arduino IDE. Then search and install  UrlEncode library. 

image

Code:

Write the following programe in Arduino IDE:

#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>

#include <WiFiClient.h>

#include <UrlEncode.h>

 

const char* ssid = "Your SSID";

const char* password = "Your password";

 

// +international_country_code + phone number

// Bangladesh +88, example: +8801....

String phoneNumber = "Your phone number";

String apiKey = "API KEY";

 

void sendMessage(String message){

 

  // Data to send with HTTP POST

  String url = "http://api.callmebot.com/whatsapp.php?phone=" + phoneNumber + "&apikey=" + apiKey + "&text=" + urlEncode(message);

  WiFiClient client;    

  HTTPClient http;

  http.begin(client, url);

 

  // Specify content-type header

  http.addHeader("Content-Type", "application/x-www-form-urlencoded");

 

  // Send HTTP POST request

  int httpResponseCode = http.POST(url);

  if (httpResponseCode == 200){

    Serial.print("Message sent successfully");

  }

  else{

    Serial.println("Error sending the message");

    Serial.print("HTTP response code: ");

    Serial.println(httpResponseCode);

  }

 

  // Free resources

  http.end();

}

 

void setup() {

  Serial.begin(115200);

 

  WiFi.begin(ssid, password);

  Serial.println("Connecting");

  while(WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

  }

  Serial.println("");

  Serial.print("Connected to WiFi network with IP Address: ");

  Serial.println(WiFi.localIP());

 

  // Send Message to WhatsAPP

 // sendMessage("Hello from ESP8266!");

}

 

void loop() {

 

   // read the input on analog pin 0:

  int sensorValue = analogRead(A0);

  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

  float voltage = sensorValue * (5.0 / 1023.0);

  // print out the value you read:

 // Serial.println(voltage);

 Serial.println(sensorValue);

 

if(sensorValue>=700)

{

  sendMessage("GAS!");

}

 

 

}

You have to select NodeMCU 1.0 (ESP12E-Module) from the  Board option at the time of uploading the code.

 

Open the serial monitor in 115200 baud rate. You will see the analog value of  A0 pin. In my setup, this value was below   300 under normal condition.  

 

In presence of gas, this value increases. It can be up to  1024.

image

According to my code, you’ll receive an whatsapp message when the value is 700 or more. 

image

 You can test the circuit keeping gas lighter, candle, hand sanitizer etc. in front of the sensor. 

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube