Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Practical 5: Controlling Raspberry Pi with WhatsApp

Lesson 5 of 10 in the free Internet of Things (IoT) Lab notes on Siksha Sarovar, written by Rohit Jangra.

Program Statement

Write a Program for Controlling Raspberry Pi with WhatsApp.

Objective

To control a Raspberry Pi device (e.g., turn an LED on/off) remotely by sending WhatsApp messages using the Twilio API and a Python script.

Components Required

ComponentQuantity
Raspberry Pi (any model with Wi-Fi)1
LED + 220Ω Resistor1 each
Breadboard + Jumper WiresAs needed
Twilio Account (free trial)1
Internet ConnectionRequired

Setup Steps

Step 1: Create a Twilio Account

  1. Go to https://www.twilio.com and sign up for a free account.
  2. In the Twilio console, activate the WhatsApp Sandbox.
  3. Note your Account SID, Auth Token, and the Twilio WhatsApp number.
  4. Join the sandbox by sending the given code from your WhatsApp to the Twilio number.

Step 2: Install Dependencies on Raspberry Pi Open a terminal on Raspberry Pi and run:

pip3 install twilio flask RPi.GPIO

Step 3: Set Up ngrok for Public URL Twilio needs a public URL to send incoming messages to your Pi:

# Download and run ngrok
./ngrok http 5000
# Copy the https URL (e.g., https://abcd1234.ngrok.io)

Step 4: Configure Twilio Webhook

  1. In the Twilio console, go to WhatsApp Sandbox Settings.
  2. Set the "When a message comes in" URL to: https://your-ngrok-url/whatsapp

Step 5: Circuit Connection

  • LED Anode → GPIO Pin 17 (through 220Ω resistor)
  • LED Cathode → GND

Program

Run this Flask server on your Raspberry Pi: