Section outline

  • What is IoT and Why It Matters in Robotics

    Internet of Things (IoT) refers to a network of physical devices—like sensors, machines, or robots—that are connected to the internet and can send or receive data. These smart devices can collect, share, and act on data in real time.

    • 🔹 Key Concepts

      • Things: Devices like robots, sensors, lights, and appliances.
      • Internet: The connection that allows these devices to communicate globally.
      • Data: The real-time information that these devices collect, send, and act upon.

      💡 Why Does IoT Matter in Robotics?

      • Robots become smarter when they can access cloud data.
      • IoT helps robots interact with users and other machines over long distances.
      • Real-time updates make robots adaptable and responsive to changes.
    • 📦 Everyday Examples of IoT

      • Smart thermostats adjusting room temperature based on user behavior
      • Wearable fitness trackers sending health data to mobile apps
      • Smart fridges that send alerts when food items are low

      🤖 IoT in Robotics

      • Remote monitoring of robot activities (e.g., surveillance bots)
      • Sending sensor data (e.g., temperature, motion) to the cloud
      • Receiving commands from smartphones or cloud services

      Summary: IoT makes robots smarter, connected, and more useful. In the next sections, we will explore the hardware that enables IoT in robotics.

    • Section 2: Introducing ESP32 and NodeMCU

      In the world of IoT-enabled robotics, not all microcontrollers are equal. While Arduino Uno is excellent for learning and prototyping, devices like ESP32 and NodeMCU are better suited for projects that require Wi-Fi connectivity and cloud communication. These boards bring more processing power, more memory, and built-in wireless features.

      🔍 What is ESP32?

      The ESP32 is a robust microcontroller with integrated Wi-Fi and Bluetooth capabilities. It is developed by Espressif Systems and is widely used in both DIY and professional-grade IoT solutions.

      • Dual-core processor running up to 240 MHz
      • Over 30 GPIO pins for flexible sensor and motor connections
      • Built-in support for Wi-Fi and Bluetooth (Classic and BLE)
      • Touch sensors, hardware PWM, and ADC/DAC functionalities
      • More SRAM and flash memory compared to Arduino Uno

      🔍 What is NodeMCU (ESP8266)?

      NodeMCU is based on the ESP8266 chip. It is a low-cost microcontroller board with built-in Wi-Fi that is ideal for smaller IoT projects or beginners entering the wireless world.

      • Single-core processor running up to 160 MHz
      • Fewer GPIO pins than ESP32, generally 10–12 usable
      • Supports only Wi-Fi, no Bluetooth
      • Compact and cost-effective
      • Programmed using the Arduino IDE or Lua scripting

      📊 ESP32 vs. NodeMCU Comparison

       

       

      Feature ESP32 NodeMCU (ESP8266)
      Wi-Fi Yes Yes
      Bluetooth Yes (Classic + BLE) No
      Processor Dual-core, 240 MHz Single-core, 80–160 MHz
      GPIO Pins 30+ 10–12 usable
      ADC Support Multiple ADC channels 1 ADC channel
      Memory (RAM) 520 KB SRAM 160 KB
      Flash Up to 16 MB Typically 4 MB
      Price (approx) INR 300–400 INR 200–300
    • ⚙️ Programming ESP Boards with Arduino IDE

      Both ESP32 and NodeMCU can be programmed using the Arduino IDE. However, some setup steps are needed:

      • Install the required board definitions via Board Manager
      • Select the correct board and port under Tools
      • Use USB to micro-USB cable for uploading code

      Once set up, you can write sketches using C/C++, just like you do for an Arduino Uno. You can also use libraries like WiFi.h and HTTPClient.h for internet communication.

      💬 Real-World Use Cases

      • ESP32: Cloud-connected robots, remote monitoring systems, wearable devices
      • NodeMCU: Basic IoT sensors, smart lights, simple remote control bots

      🧠 Choosing the Right Board

       

      • Use ESP32 if your project requires Bluetooth, more GPIOs, or high-speed processing
      • Use NodeMCU for simple IoT tasks where cost and compact size are a priority
  • Sending Sensor Data to the Cloud (e.g., ThingSpeak)

    One of the most exciting capabilities of IoT in robotics is sending live sensor data to the cloud, where it can be viewed, stored, and analyzed remotely. In this section, we will explore how to transmit data from ESP32 or NodeMCU to a cloud service like ThingSpeak.

    • 🌐 What is ThingSpeak?

      ThingSpeak is a cloud-based platform provided by MathWorks that allows devices to send data using HTTP protocols. It offers easy graphing, public/private channels, and MATLAB-based data analysis tools.

      • Free for personal use with limited updates per day
      • Supports HTTP and MQTT protocols
      • Real-time chart plotting and analytics
      • Used widely for temperature monitoring, environment sensing, etc.

      🛠️ What You Need

      • ESP32 or NodeMCU microcontroller
      • Wi-Fi connection
      • Sensor (e.g., DHT11 for temperature/humidity)
      • ThingSpeak account (https://thingspeak.com)

      📶 Setting Up a ThingSpeak Channel

      1. Create a free ThingSpeak account and log in.
      2. Click on "Channels" > "New Channel".
      3. Give a name (e.g., WeatherData), and enable the fields you want (e.g., Field1: Temperature, Field2: Humidity).
      4. Save the channel and note down your Write API Key from the API Keys tab.

      🔌 Circuit Setup

      Example: DHT11 sensor with ESP32

      • VCC → 3.3V
      • GND → GND
      • Data → GPIO 4
    • 🧑‍💻 Sample Code to Send Data to ThingSpeak

      
      // Required Libraries
      #include <WiFi.h>
      #include <HTTPClient.h>
      #include "DHT.h"
      
      // Wi-Fi Credentials
      const char* ssid = "YourWiFiSSID";
      const char* password = "YourWiFiPassword";
      
      // ThingSpeak Settings
      const char* server = "http://api.thingspeak.com/update";
      String apiKey = "YOUR_WRITE_API_KEY";
      
      // DHT Sensor Settings
      #define DHTPIN 4
      #define DHTTYPE DHT11
      DHT dht(DHTPIN, DHTTYPE);
      
      void setup() {
        Serial.begin(115200);
        WiFi.begin(ssid, password);
        dht.begin();
      
        while (WiFi.status() != WL_CONNECTED) {
          delay(1000);
          Serial.println("Connecting to WiFi...");
        }
        Serial.println("Connected to WiFi");
      }
      
      void loop() {
        float temp = dht.readTemperature();
        float hum = dht.readHumidity();
      
        if (isnan(temp) || isnan(hum)) {
          Serial.println("Failed to read from DHT sensor!");
          return;
        }
      
        if (WiFi.status() == WL_CONNECTED) {
          HTTPClient http;
          String url = server + String("?api_key=") + apiKey +
                       "&field1=" + String(temp) +
                       "&field2=" + String(hum);
      
          http.begin(url);
          int httpCode = http.GET();
          if (httpCode > 0) {
            Serial.println("Data sent successfully");
          } else {
            Serial.println("Error sending data");
          }
          http.end();
        }
      
        delay(15000); // Wait 15 seconds before next update
      }
      

      📊 Viewing Your Data

      After running the sketch, open your ThingSpeak channel. You will see real-time graphs under each field that you've updated from your ESP board. These are auto-generated and updated every 15 seconds (or based on your delay).

    • 💡 Use Cases

      • Environment monitoring robots that upload data every few minutes
      • Health robots that log temperature/humidity in a remote room
      • Weather bots that stream live updates to a dashboard

      ⚠️ Tips & Troubleshooting

       

      • Ensure correct Wi-Fi SSID and password
      • Double-check your ThingSpeak Write API Key
      • Use serial monitor for debugging network or sensor errors
      • Observe ThingSpeak update limits: 1 update every 15 seconds for free accounts
  • MQTT Basics – Lightweight Messaging for IoT

    MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol widely used in IoT systems. It allows devices like sensors, robots, and microcontrollers to communicate over the internet with low bandwidth and power usage.

    • 🌐 What is MQTT?

      MQTT is a publish-subscribe protocol. Instead of sending data directly between devices, all communication happens through a central broker (like a post office).

      🧩 How MQTT Works

      • Broker: The central server that handles messages
      • Publisher: A device (e.g. ESP32) that sends data
      • Subscriber: A device or app that receives data
      • Topic: A channel or label used to organize messages (like /weather/temp)

      Example: Your ESP32 publishes temperature data to the topic /robot/weather/temp. A mobile app subscribes to that topic and displays the latest temperature reading.

      📦 Why Use MQTT?

      • Low bandwidth – ideal for IoT devices
      • Reliable – even over spotty Wi-Fi
      • Flexible – one message can be received by many devices
    • 🔧 MQTT Terminology at a Glance

       

      Term Meaning
      Broker Server that manages all messages
      Client Any device connected to broker (ESP32, mobile app, etc.)
      Publish Send message to broker under a topic
      Subscribe Listen for messages on a specific topic
      Topic Label for organizing messages (e.g. /robot/temp)

       

    • 💻 Sample Code (ESP32 Publishing Data)

      #include <WiFi.h>
      #include <PubSubClient.h>
      
      const char* ssid = "your_SSID";
      const char* password = "your_PASSWORD";
      const char* mqtt_server = "broker.hivemq.com";
      
      WiFiClient espClient;
      PubSubClient client(espClient);
      
      void setup() {
        Serial.begin(115200);
        WiFi.begin(ssid, password);
        while (WiFi.status() != WL_CONNECTED) {
          delay(500);
          Serial.print(".");
        }
        client.setServer(mqtt_server, 1883);
      }
      
      void loop() {
        if (!client.connected()) {
          reconnect();
        }
        client.loop();
      
        // Publish data
        client.publish("/robot/weather/temp", "28.5");
        delay(5000); // send every 5 seconds
      }
      
      void reconnect() {
        while (!client.connected()) {
          if (client.connect("ESP32Client")) {
            client.subscribe("/robot/commands");
          } else {
            delay(2000);
          }
        }
      }
      

      ⚠️ Note

      • Use public MQTT brokers like broker.hivemq.com for testing
      • Always keep topic names clear and structured (e.g., /robot/status)
      • For production use, secure brokers and authentication are recommended
  • IoT-Based Weather Bot

    In this hands-on project, you will build an Internet-connected weather bot using an ESP32 or NodeMCU. The bot will measure environmental data (like temperature and humidity) and send it to the cloud in real time for monitoring and visualization.

    • 🎯 Project Goals

      • Use a DHT11 or DHT22 sensor to measure temperature and humidity
      • Connect your ESP32/NodeMCU to Wi-Fi
      • Publish sensor data to the cloud using MQTT or ThingSpeak
      • Visualize the live data on a dashboard

      🔌 Components Needed

      • ESP32 or NodeMCU board
      • DHT11 or DHT22 sensor
      • Jumper wires and breadboard
      • USB cable
      • Wi-Fi access

      🧠 Circuit Diagram

      Connect the DHT sensor to your ESP32 as follows:

      DHT Sensor ESP32
      VCC 3.3V
      GND GND
      DATA D4 (GPIO4)

       

    • 💻 Sample Code (Sending Data to MQTT Broker)

      #include <WiFi.h>
      #include <PubSubClient.h>
      #include <DHT.h>
      
      #define DHTPIN 4
      #define DHTTYPE DHT11
      DHT dht(DHTPIN, DHTTYPE);
      
      const char* ssid = "your_SSID";
      const char* password = "your_PASSWORD";
      const char* mqtt_server = "broker.hivemq.com";
      
      WiFiClient espClient;
      PubSubClient client(espClient);
      
      void setup() {
        Serial.begin(115200);
        WiFi.begin(ssid, password);
        dht.begin();
      
        while (WiFi.status() != WL_CONNECTED) {
          delay(500);
          Serial.print(".");
        }
      
        client.setServer(mqtt_server, 1883);
      }
      
      void loop() {
        if (!client.connected()) {
          reconnect();
        }
        client.loop();
      
        float temp = dht.readTemperature();
        float hum = dht.readHumidity();
      
        if (!isnan(temp) && !isnan(hum)) {
          char tempStr[8];
          char humStr[8];
          dtostrf(temp, 1, 2, tempStr);
          dtostrf(hum, 1, 2, humStr);
      
          client.publish("/weatherbot/temp", tempStr);
          client.publish("/weatherbot/humidity", humStr);
        }
      
        delay(5000);
      }
      
      void reconnect() {
        while (!client.connected()) {
          if (client.connect("WeatherBotClient")) {
            client.subscribe("/weatherbot/commands");
          } else {
            delay(2000);
          }
        }
      }
      
    • 📊 Visualizing Data

      • Using ThingSpeak: Create a free account and channel, then use HTTP POST to send data from ESP32
      • Using MQTT Dashboard App: Subscribe to topics like /weatherbot/temp to view real-time data on your phone

      🛠️ Optional Enhancements

      • Add an OLED display to show live data on the robot
      • Use IFTTT to trigger alerts if temperature goes above a limit
      • Send data to Google Sheets via webhook

      ✅ Key Takeaways

      • You can build real-time, connected devices with very basic components
      • MQTT and cloud services like ThingSpeak make data sharing simple
      • This weather bot is a great foundation for more advanced IoT automation
  • You have now explored the powerful world of IoT and how it transforms everyday robots into smart, connected systems. From understanding what IoT means to building a live data-streaming weather bot, you have worked with ESP32, MQTT, and cloud platforms like ThingSpeak. You learned how to gather sensor data, push it online, and visualize it in real time. This foundation is essential for advanced applications like remote monitoring, automation, and smart robotics. Let’s now test your understanding through a quick recap quiz!