IoT devices are transforming the world, but getting started often feels expensive. I used to believe you needed a Raspberry Pi, ESP32, an Arduino, or a dedicated server to control smart devices. Then reality hit me. A student from Palawan, a major island in the Philippines, messaged me: “I love IoT, but I can’t afford extra hardware. All I have is my phone.” That one message changed my perspective.
Not everyone can buy specialized hardware, but nearly everyone has a smartphone. And that’s enough.
With Termux, you can connect and control IoT devices directly from your Android device—no extra hardware required.
Whether you’re automating smart home gadgets, collecting sensor data, or experimenting with IoT protocols, Termux makes it possible without breaking the bank.
In this guide, I’ll show you exactly how to connect and control IoT devices using just Termux, proving that innovation isn’t about what you own—it’s about what you do with what you have.
Download my FREE Termux Cheat Sheet Now!
Termux Backgrounder
Termux is an Android terminal emulator and Linux environment that enables you to run a full-fledged Linux distribution on your Android device. It provides a command-line interface and supports a wide range of Linux packages and tools, making it a versatile platform for various tasks.
With Termux, you can install and use command-line utilities, programming languages, and development tools right on your mobile device.
For more information and a comprehensive overview of Termux, check out our Ultimate Guide to Termux, which covers everything you need to know to get started and make the most of this powerful tool.
· · ─ ·𖥸· ─ · ·
What Are IoT Devices?
IoT devices are smart, internet-connected gadgets that collect, process, and exchange data to automate tasks and enhance efficiency. These devices range from smart home systems (like lights, thermostats, and security cameras) to industrial sensors, wearables, and environmental monitors.
With IoT devices, you can automate daily tasks, monitor real-time data, and control smart systems remotely. Traditionally, IoT development required specialized hardware like a Raspberry Pi, but with Termux, you can now connect and control IoT devices directly from your Android phone—making IoT more accessible and affordable than ever.
· · ─ ·𖥸· ─ · ·
How It Works
We’ll be setting up an ESP32 web server that listens for HTTP requests from Termux. When Termux sends a request, the ESP32 will control a relay module connected to a 220V light bulb.
- Relay Module: Acts as a switch for the 220V light bulb.
- ESP32: Hosts a simple web server and controls the relay.
- Termux: Sends HTTP requests to toggle the light on and off.
[ Light Bulb ] [ Light Bulb ]
| |
[ Relay ] [ Relay ]
| |
[ ESP32 ] [ ESP32 ]
\ /
\__ WiFi Router __/
|
[ Termux ]
|
[ User Input ]
· · ─ ·𖥸· ─ · ·
What You’ll Need
Hardware
- ESP32 development board
- 1-channel relay module
- 220V light bulb + socket
- Jumper wires
- Power supply for ESP32
Software
- Termux (Installed on your Android phone)
- Python in Termux (for sending HTTP requests)
- ESP32 firmware flashed with MicroPython
· · ─ ·𖥸· ─ · ·
Setting Up Termux for IoT Device Management
Step 1: Set Up Your ESP32 Web Server
We need to program the ESP32 to host a web server that listens for commands. Flash MicroPython onto your ESP32 if you haven’t already.
Install esptool and flash MicroPython onto your ESP32:
pip install esptool esptool.py --chip esp32 erase_flash
esptool.py --chip esp32 write_flash -z 0x1000 esp32-20220117-v1.18.bin
For a step-by-step guide on setting up MicroPython using Thonny, check out our detailed tutorial here.
Connect to the ESP32 via Thonny or ampy to upload your Python script.
Create a new file main.py
and add the following code:
import network
import socket
from machine import Pin
relay = Pin(2, Pin.OUT)
ssid = "Your_WiFi_SSID"
password = "Your_WiFi_Password"
# Connect to WiFi
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
pass
print("Connected to WiFi")
# Create Web Server
def start_server():
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)
print("Web Server Running...")
while True:
cl, addr = s.accept()
request = cl.recv(1024)
request = str(request)
print("Request:", request)
if '/light/on' in request:
relay.value(1)
elif '/light/off' in request:
relay.value(0)
response = "HTTP/1.1 200 OK\n\nLight Toggled"
cl.send(response)
cl.close()
connect_wifi()
start_server()
- Restart your ESP32. It should now be hosting a web server.
· · ─ ·𖥸· ─ · ·
Step 2: Send HTTP Requests from Termux
Now that the ESP32 is running a web server, we can use Termux to send requests and toggle the light.
Install Python in Termux
pkg update && pkg upgrade
pkg install python
Use curl
to Toggle the Light
Turn On the Light
curl http://ESP32_IP/light/on
Turn Off the Light
curl http://ESP32_IP/light/off
Replace ESP32_IP
with the actual IP address of your ESP32.
Automate with a Shell Script
To make it easier, create a shell script in Termux:
echo '#!/bin/bash\ncurl http://ESP32_IP/light/$1' > light_control.sh
chmod +x light_control.sh
Now, you can toggle the light using:
./light_control.sh on
./light_control.sh off
· · ─ ·𖥸· ─ · ·
Step 3: Make Termux a Smart Home Hub
For full automation, you can integrate Termux with cron jobs or tasker to schedule light control commands.
Example: Turn Light On at 7 PM and Off at 11 PM
crontab -e
Add the following lines:
0 19 * * * /data/data/com.termux/files/home/light_control.sh on
0 23 * * * /data/data/com.termux/files/home/light_control.sh off
This will automatically turn on the light at 7 PM and turn it off at 11 PM.
For full automation, you can integrate Termux with cron jobs or tasker to schedule light control commands. Need a deeper dive? Check out our guide on Termux Crontab for more details on setting up scheduled tasks.
· · ─ ·𖥸· ─ · ·
Examples of IoT Devices Used in the Home
- Smart Lights – Automate lighting schedules, control brightness, and change colors remotely.
- Smart Plugs – Turn appliances on/off from anywhere and track energy usage.
- Smart Thermostats – Optimize heating and cooling for energy efficiency and comfort.
- Smart Locks – Enable keyless entry, remote access, and security alerts.
- Smart Security Cameras – Monitor your home in real-time with motion detection and cloud storage.
- Smart Doorbells – See and communicate with visitors remotely via a mobile app.
- Smart Speakers – Control home devices using voice commands (e.g., Alexa, Google Assistant).
- Smart Sensors – Detect motion, temperature changes, water leaks, and smoke.
· · ─ ·𖥸· ─ · ·
Conclusion
By using IoT devices using Termux, you unlock the ability to control and monitor your smart devices directly from your Android phone. Whether you’re automating your home or managing sensors, Termux offers a flexible and powerful solution for IoT management. Explore more use cases and customize scripts to suit your specific IoT environment. For an in-depth look at Termux and its capabilities, check out our Ultimate Guide to Termux.
Leave a Reply