TABLE OF CONTENTS S. No CONTENTS 1. Design an IoT Circuit to ON/OFF an LED bulb for a delay of 5 sec. 2. Design an IoT Circuit to ON/OFF 4 LED bulbs for a delay of 8 sec. 3. Write an Arduino program to switch ON/OFF four LED bulbs in a parallel manner. 4. Write an Arduino program to switch ON/OFF the LED bulb in a series manner. 5. Write an Arduino program for designing a two - way junction traffic controller system. 6. Write an Arduino program for designing a four - way junction traffic controller system. 7. Write an Arduino program for displaying the temperature and humidity in the serial monitor. 8. Write an Arduino program for displaying the distance between an object and displaying the distance in the serial monitor. 9. Write an Arduino program to switch ON/OFF LED by using Bluetooth. 10. Write an Arduino program to switch ON/OFF LED by using Wi - Fi. 11. Write an Arduino program for displaying the temperature and humidity in the cloud database. 12. Write an Arduino program for displaying the temperatures and humidity values into mobile applications. 13. Write an Arduino program for displaying the distance between an object and displaying the distance values in the cloud database. 14. Write an Arduino program for displaying the distance between an object and displaying the distance values into mobile applications. 15. Design and Interface ESP32 with a DC motor using the L298 motor driver. 16. Design a simple IoT System comprising a sensor, Wireless Network connection, and Data Analytics. Experiment 1 — ON/OFF single LED with 5s delay Aim: Design an IoT circuit to turn ON/OFF a single LED with a delay of 5 seconds. Objectives: Learn basic GPIO control and timing. Outcomes: Student can control an LED via Arduino/ESP32 with timed delays. Components Required: Arduino Uno (or ESP32), LED, 220Ω resistor, breadboard, jumper wires. Block Diagram: LED → Resistor → Digital Pin (e.g., D4) → GND Circuit Notes: Use a current limiting resistor (220Ω) in series with the LED. Program Code (Arduino UNO): // Single LED blink with 5 second delay const int ledPin = 4 ; // change to LED_BUILTIN for builtin LED void setup () { pinMode ( ledPin , OUTPUT ); } void loop () { digitalWrite ( ledPin , HIGH ); // LED ON delay ( 5000 ); // wait 5 seconds digitalWrite ( ledPin , LOW ); // LED OFF delay ( 5000 ); // wait 5 seconds } Explanation / Result: LED toggles ON and OFF every 5 seconds. Experiment 2 — ON/OFF 4 LEDs with 8s delay Aim: Design IoT circuit to toggle 4 LEDs together with an 8 second delay. Components Required: Arduino/ESP32, 4 LEDs, 4 resistors (220Ω), wires, breadboard. Block Diagram: Four LEDs connected to digital pins (D2, D3, D4, D5) each via resistor. Program Code (Arduino UNO): // 4 LEDs toggle every 8 seconds const int leds [ 4 ] = { 2 , 3 , 4 , 5 }; void setup () { for ( int i = 0 ; i < 4 ; i ++) pinMode ( leds [ i ], OUTPUT ); } void loop () { // Turn all ON for ( int i = 0 ; i < 4 ; i ++) digitalWrite ( leds [ i ], HIGH ); delay ( 8000 ); // Turn all OFF for ( int i = 0 ; i < 4 ; i ++) digitalWrite ( leds [ i ], LOW ); delay ( 8000 ); } Explanation: All four LEDs switch simultaneously every 8 seconds. Experiment 3 — Four LEDs in parallel control Aim: Switch ON/OFF four LED bulbs in a parallel manner. Components: Arduino, 4 LEDs + resistors, breadboard. Circuit: Each LED has its own digital output pin — parallel in electrical sense (individual pins drive each LED). Program Code: // Control four LEDs independently (parallel wiring) const int ledPins [ 4 ] = { 2 , 3 , 4 , 5 }; void setup (){ for ( int i = 0 ; i < 4 ; i ++) pinMode ( ledPins [ i ], OUTPUT ); } void loop (){ // Example sequence: chase for ( int i = 0 ; i < 4 ; i ++){ digitalWrite ( ledPins [ i ], HIGH ); delay ( 300 ); digitalWrite ( ledPins [ i ], LOW ); } delay ( 500 ); } Explanation: This demonstrates independent control — electrically parallel per pin. Experiment 4 — Switching LED in series manner (concept) Aim: Demonstrate LED series behaviour (note: series wiring for LEDs requires voltage headroom). Warning: Typical single Arduino pin cannot properly drive multiple LEDs in series because the voltage drop may exceed supply; use external driver or use multiple pins. The exercise will simulate series switching using one pin for the whole string (through proper driver or an external supply). Components: Arduino, 2 – 3 LEDs in series (only if supply voltage allows), resistor, external supply if needed. Program Code (simulate series ON/OFF using single pin): const int seriesPin = 4 ; // drives series string via transistor/MOSFET void setup (){ pinMode ( seriesPin , OUTPUT ); } void loop (){ digitalWrite ( seriesPin , HIGH ); // series string ON delay ( 1000 ); digitalWrite ( seriesPin , LOW ); // series string OFF delay ( 1000 ); } Explanation: Prefer using a transistor driver if series string requires more voltage or current than MCU pin can provide. Experiment 5 — Two - way junction traffic controller Aim: Implement a two - way traffic controller that alternates traffic signals between two directions. Components: Arduino UNO, 6 LEDs (NS: Green, Yellow, Red; EW: Green, Yellow, Red), resistors, breadboard. Pins (suggested): - NS Green: 2 - NS Yellow: 3 - NS Red: 4 - EW Green: 5 - EW Yellow: 6 - EW Red: 7 Program Code: const int greenNS = 2 ; const int yellowNS = 3 ; const int redNS = 4 ; const int greenEW = 5 ; const int yellowEW = 6 ; const int redEW = 7 ; void setup (){ int pins [] = { greenNS , yellowNS , redNS , greenEW , yellowEW , redEW }; for ( int i = 0 ; i < 6 ; i ++) pinMode ( pins [ i ], OUTPUT ); } void nsGreenSequence (){ digitalWrite ( greenNS , HIGH ); digitalWrite ( redEW , HIGH ); delay ( 5000 ); digitalWrite ( greenNS , LOW ); digitalWrite ( yellowNS , HIGH ); delay ( 2000 ); digitalWrite ( yellowNS , LOW ); digitalWrite ( redNS , HIGH ); } void ewGreenSequence (){ digitalWrite ( greenEW , HIGH ); digitalWrite ( redNS , HIGH ); delay ( 5000 ); digitalWrite ( greenEW , LOW ); digitalWrite ( yellowEW , HIGH ); delay ( 2000 ); digitalWrite ( yellowEW , LOW ); digitalWrite ( redEW , HIGH ); } void loop (){ nsGreenSequence (); delay ( 1000 ); // both red ewGreenSequence (); delay ( 1000 ); } Explanation: Simple timed sequence for two directions. Experiment 6 — Four - way junction traffic controller Aim: Design a four - way traffic control system using timing to manage traffic from 4 directions. Components: Arduino, 12 LEDs (4 directions × 3 colors), resistors, breadboard. Program Code (simplified cyclic scheduler): // pins for direction A,B,C,D (each has red,yellow,green) const int red [ 4 ] = { 2 , 5 , 8 , 11 }; const int yellow [ 4 ] = { 3 , 6 , 9 , 12 }; const int green [ 4 ] = { 4 , 7 , 10 , 13 }; void setup (){ for ( int i = 0 ; i < 4 ; i ++){ pinMode ( red [ i ], OUTPUT ); pinMode ( yellow [ i ], OUTPUT ); pinMode ( green [ i ], OUTPUT ); } } void setAllRed (){ for ( int i = 0 ; i < 4 ; i ++){ digitalWrite ( green [ i ], LOW ); digitalWrite ( yellow [ i ], LOW ); digitalWrite ( red [ i ], HIGH ); } } void giveGreenTo ( int dir ){ // dir: 0..3 digitalWrite ( red [ dir ], LOW ); digitalWrite ( green [ dir ], HIGH ); } void cycleDirection ( int dir ){ giveGreenTo ( dir ); delay ( 5000 ); digitalWrite ( green [ dir ], LOW ); digitalWrite ( yellow [ dir ], HIGH ); delay ( 2000 ); digitalWrite ( yellow [ dir ], LOW ); digitalWrite ( red [ dir ], HIGH ); } void loop (){ for ( int d = 0 ; d < 4 ; d ++){ cycleDirection ( d ); delay ( 500 ); // all red transition } } Explanation: Cycles green through four directions with transition yellow and all - red gaps. Experiment 7 — Display temperature and humidity in Serial Monitor Aim: Read temperature & humidity (DHT11/DHT22) and display on Serial Monitor. Components: Arduino/ESP32, DHT11 or DHT22 sensor, jumper wires. Library required: DHT sensor library by Adafruit or equivalent. Program Code (Arduino UNO with DHT11): #include "DHT.h" #define DHTPIN 4 #define DHTTYPE DHT11 DHT dht ( DHTPIN , DHTTYPE ); void setup (){ Serial begin ( 115200 ); dht begin (); } void loop (){ float h = dht readHumidity (); float t = dht readTemperature (); if ( isnan ( h ) || isnan ( t )){ Serial println ( "Failed to read from DHT sensor!" ); } else { Serial print ( "Temperature: " ); Serial print ( t ); Serial println ( " °C" ); Serial print ( "Humidity: " ); Serial print ( h ); Serial println ( " %" ); } delay ( 2000 ); } Explanation: Reads sensor and prints values. Experiment 8 — Ultrasonic distance measurement (Serial Monitor) Aim: Measure distance using HC - SR04 and show distance in Serial Monitor. Components: Arduino, HC - SR04, jumper wires. Program Code: const int trigPin = 7 ; const int echoPin = 6 ; long duration ; float distanceCm ; void setup (){ pinMode ( trigPin , OUTPUT ); pinMode ( echoPin , INPUT ); Serial begin ( 9600 ); } void loop (){ digitalWrite ( trigPin , LOW ); delayMicroseconds ( 2 ); digitalWrite ( trigPin , HIGH ); delayMicroseconds ( 10 ); digitalWrite ( trigPin , LOW ); duration = pulseIn ( echoPin , HIGH ); distanceCm = ( duration * 0.0343 ) / 2.0 ; Serial print ( "Distance: " ); Serial print ( distanceCm ); Serial println ( " cm" ); delay ( 500 ); } Explanation: Calculates distance from echo time and prints to serial. Experiment 9 — Switch ON/OFF LED via Bluetooth (ESP32) Aim: Use ESP32 Bluetooth Classic (Serial BT) to receive commands and control LEDs. Components: ESP32 Dev board, LED + resistor, mobile phone app (Serial Bluetooth terminal). Program Code (ESP32): #include "BluetoothSerial.h" BluetoothSerial SerialBT ; const int ledPin = 2 ; // onboard LED on many ESP32 boards void setup (){ Serial begin ( 115200 ); SerialBT begin ( "ESP32_LED_CTRL" ); pinMode ( ledPin , OUTPUT ); Serial println ( "Bluetooth started, pair with ESP32_LED_CTRL" ); } void loop (){ if ( SerialBT available ()){ String cmd = SerialBT readStringUntil ( ' \ n' ); cmd trim (); Serial print ( "Received: " ); Serial println ( cmd ); if ( cmd == "ON" ) digitalWrite ( ledPin , HIGH ); else if ( cmd == "OFF" ) digitalWrite ( ledPin , LOW ); else if ( cmd == "TOGGLE" ) digitalWrite ( ledPin , ! digitalRead ( ledPin )); } delay ( 20 ); } Explanation: Pair phone, send plain text commands ON/OFF. Experiment 10 — Switch ON/OFF LED via Wi ‑ Fi (ESP32 + ThingSpeak simple) Aim: Control an LED over Wi ‑ Fi using ThingSpeak channel or simple HTTP GET. Components: ESP32, Wi ‑ Fi access, LED + resistor. Program Code (ESP32 using ThingSpeak readIntField example): #include <WiFi.h> #include < ThingSpeak.h> WiFiClient client ; const char * ssid = "YOUR_SSID" ; const char * password = "YOUR_PASS" ; const unsigned long channelID = 626082 ; // example const char * readAPIKey = "READ_KEY" ; const int ledPin = 4 ; void setup (){ Serial begin ( 115200 ); pinMode ( ledPin , OUTPUT ); WiFi begin ( ssid , password ); while ( WiFi status () != WL_CONNECTED ){ delay ( 500 ); Serial print ( "." ); } Serial println ( "WiFi connected" ); ThingSpeak begin ( client ); } void loop (){ int val = ThingSpeak readIntField ( channelID , 1 , readAPIKey ); Serial print ( "Field1: " ); Serial println ( val ); if ( val == 1 ) digitalWrite ( ledPin , HIGH ); else digitalWrite ( ledPin , LOW ); delay ( 5000 ); } Explanation: Use mobile app or ThingSpeak web update to change field value to 1/0. Experiment 11 — Send temperature & humidity to cloud database (ThingSpeak) Aim: Read DHT sensor and upload values to ThingSpeak channel. Components: ESP32, DHT11/22, Wi - Fi. Program Code (ESP32 + ThingSpeak): #include <WiFi.h> #include < ThingSpeak.h> #include "DHT.h" #define DHTPIN 4 #define DHTTYPE DHT11 DHT dht ( DHTPIN , DHTTYPE ); WiFiClient client ; const char * ssid = "YOUR_SSID" ; const char * password = "YOUR_PASS" ; unsigned long myChannelNumber = 123456 ; // replace const char * myWriteAPIKey = "WRITE_KEY" ; void setup (){ Serial begin ( 115200 ); dht begin (); WiFi begin ( ssid , password ); while ( WiFi status () != WL_CONNECTED ) { delay ( 500 ); Serial print ( "." ); } ThingSpeak begin ( client ); } void loop (){ float h = dht readHumidity (); float t = dht readTemperature (); if (! isnan ( h ) && ! isnan ( t )){ ThingSpeak setField ( 1 , t ); ThingSpeak setField ( 2 , h ); ThingSpeak writeFields ( myChannelNumber , myWriteAPIKey ); Serial println ( "Uploaded to ThingSpeak" ); } else Serial println ( "Sensor error" ); delay ( 20000 ); } Explanation: Values appear in ThingSpeak channel fields and can be graphed. Experiment 12 — Send temperature & humidity to mobile application Aim: Display sensor values in a mobile app (e.g., Blynk or a simple HTTP server + REST). Option A — Blynk (recommended): Use Blynk library and app to display values in widgets. Program Code (Blynk + ESP32 + DHT11): #define BLYNK_PRINT Serial #include <WiFi.h> #include <BlynkSimpleEsp32.h> #include "DHT.h" char auth [] = "BLYNK_AUTH_TOKEN" ; char ssid [] = "YOUR_SSID" ; char pass [] = "YOUR_PASS" ; #define DHTPIN 4 #define DHTTYPE DHT11 DHT dht ( DHTPIN , DHTTYPE ); void setup (){ Serial begin ( 115200 ); Blynk begin ( auth , ssid , pass ); dht begin (); } void loop (){ Blynk run (); float h = dht readHumidity (); float t = dht readTemperature (); if (! isnan ( h ) && ! isnan ( t )){ Blynk virtualWrite ( V1 , t ); // show temp on widget V1 Blynk virtualWrite ( V2 , h ); // show humidity on widget V2 } delay ( 2000 ); } Explanation: Configure Blynk app with two value display widgets bound to V1 and V2. Experiment 13 — Upload distance measurement to cloud database Aim: Measure distance (HC - SR04) and upload values to ThingSpeak. Program Code (ESP32 + HC - SR04 + ThingSpeak): #include <WiFi.h> #include <ThingSpeak.h> const int trigPin = 12 ; const int echoPin = 13 ; WiFiClient client ; unsigned long myChannelNumber = 123456 ; const char * writeAPIKey = "WRITE_KEY" ; const char * ssid = "YOUR_SSID" ; const char * password = "YOUR_PASS" ; void setup (){ Serial begin ( 115200 ); pinMode ( trigPin , OUTPUT ); pinMode ( echoPin , INPUT ); WiFi begin ( ssid , password ); while ( WiFi status () != WL_CONNECTED ){ delay ( 500 ); Serial print ( "." ); } ThingSpeak begin ( client ); } float measureDistance (){ digitalWrite ( trigPin , LOW ); delayMicroseconds ( 2 ); digitalWrite ( trigPin , HIGH ); delayMicroseconds ( 10 ); digitalWrite ( trigPin , LOW ); long duration = pulseIn ( echoPin , HIGH ); return ( duration * 0.0343 ) / 2.0 ; } void loop (){ float dist = measureDistance (); Serial print ( "Distance: " ); Serial println ( dist ); ThingSpeak setField ( 1 , dist ); ThingSpeak writeFields ( myChannelNumber , writeAPIKey ); delay ( 15000 ); } Explanation: Distance values will populate ThingSpeak field for plotting. Experiment 14 — Send distance values to mobile application Aim: Display HC - SR04 distance in a mobile app (Blynk or custom REST frontend). Program Code (Blynk + ESP32 + HC - SR04): #define BLYNK_PRINT Serial #include <BlynkSimpleEsp32.h> #include <WiFi.h> char auth [] = "BLYNK_AUTH_TOKEN" ; char ssid [] = "YOUR_SSID" ; char pass [] = "YOUR_PASS" ; const int trigPin = 12 ; const int echoPin = 13 ; float measureDistance (){ digitalWrite ( trigPin , LOW ); delayMicroseconds ( 2 ); digitalWrite ( trigPin , HIGH ); delayMicroseconds ( 10 ); digitalWrite ( trigPin , LOW ); long duration = pulseIn ( echoPin , HIGH ); return ( duration * 0.0343 ) / 2.0 ; } void setup (){ Serial begin ( 115200 ); Blynk begin ( auth , ssid , pass ); pinMode ( trigPin , OUTPUT ); pinMode ( echoPin , INPUT ); } void loop (){ Blynk run (); float dist = measureDistance (); Blynk virtualWrite ( V3 , dist ); // display on widget V3 delay ( 1000 ); } Explanation: mobile app receives live distance readings on a widget. Experiment 15 — Interface ESP32 with DC motor using L298 driver Aim: Control a DC motor (speed & direction) with ESP32 through L298N driver. Components: ESP32, L298N driver, DC motor, external power supply (motor voltage), jumper wires, potentiometer (optional for speed control via analogRead and PWM). Wiring (summary): - L298 IN1 - > ESP32 pin 14 - L298 IN2 - > ESP32 pin 27 - L298 ENA - > ESP32 pin 26 (PWM) or tied high if not using speed control - Motor +/− connected to L298 motor outputs - L298 Vcc (motor supply) - > external motor supply (e.g., 12V) - L298 5V - > ESP32 5V only if regulated and safe; typically power ESP32 separately via USB. Program Code (ESP32 PWM control): const int in1 = 14 ; const int in2 = 27 ; const int ena = 26 ; // PWM pin void setup (){ pinMode ( in1 , OUTPUT ); pinMode ( in2 , OUTPUT ); pinMode ( ena , OUTPUT ); } void motorForward ( int speed ){ digitalWrite ( in1 , HIGH ); digitalWrite ( in2 , LOW ); ledcWrite ( 0 , speed ); // uses LEDC channel 0 } void motorReverse ( int speed ){ digitalWrite ( in1 , LOW ); digitalWrite ( in2 , HIGH ); ledcWrite ( 0 , speed ); } void stopMotor (){ digitalWrite ( in1 , LOW ); digitalWrite ( in2 , LOW ); ledcWrite ( 0 , 0 ); } void setupLEDC (){ ledcAttachPin ( ena , 0 ); ledcSetup ( 0 , 20000 , 8 ); // channel 0, 20kHz, 8 - bit resolution } void setup (){ setupLEDC (); setup (); } void loop (){ motorForward ( 200 ); // speed 0..255 delay ( 3000 ); stopMotor (); delay ( 1000 ); motorReverse ( 200 ); delay ( 3000 ); stopMotor (); delay ( 1000 ); } Explanation: Uses PWM to control motor speed and IN1/IN2 to set direction. Experiment 16 — Simple IoT System: Sensor + Wireless + Analytics Aim: Design a simple end - to - end IoT system: sense environmental data, transmit to cloud, and perform basic analytics (average, min, max). Components: ESP32 (sensor node), DHT11/DHT22 or other sensor, Wi ‑ Fi, ThingSpeak or MQTT+free cloud, and simple analytics script (Python/Jupyter or cloud functions). Architecture: Sensor → ESP32 → Wi ‑ Fi → Cloud (ThingSpeak/MQTT broker) → Analytics (Python script or ThingSpeak charts) Program Code (ESP32 upload to ThingSpeak, same as Exp 11): #include <WiFi.h> #include <ThingSpeak.h> #include "DHT.h" #define DHTPIN 4 #define DHTTYPE DHT11 DHT dht ( DHTPIN , DHTTYPE ); WiFiClient client ; const char * ssid = "YOUR_SSID" ; const char * password = "YOUR_PASS" ; unsigned long myChannelNumber = 123456 ; // replace const char * myWriteAPIKey = "WRITE_KEY" ; void setup (){ Serial begin ( 115200 ); dht begin (); WiFi begin ( ssid , password ); while ( WiFi status () != WL_CONNECTED ) { delay ( 500 ); Serial print ( "." ); } ThingSpeak begin ( client ); } void loop (){ float h = dht readHumidity (); float t = dht readTemperature (); if (! isnan ( h ) && ! isnan ( t )){ ThingSpeak setField ( 1 , t ); ThingSpeak setField ( 2 , h ); ThingSpeak writeFields ( myChannelNumber , myWriteAPIKey ); Serial println ( "Uploaded to ThingSpeak" ); } else Serial println ( "Sensor error" ); delay ( 20000 ); } // After data is in ThingSpeak, run analytics in Python (example below) Simple analytics (Python pseudocode): # Suppose you download CSV of Field1 (temperature) and Field2 (humidity) import pandas as pd df = pd.read_csv( 'thingspeak_export.csv' ) # Basic stats print (df[ 'field1' ].mean(), df[ 'field1' ]. min (), df[ 'field1' ]. max ()) # Rolling average df[ 'temp_ma_10' ] = df[ 'field1' ].rolling(window = 10 ).mean() Explanation: Demonstrates end - to - end flow and basic processing for decisions or visualizations. Notes & References • Replace YOUR_SSID , YOUR_PASS , WRITE_KEY , READ_KEY , and BLYNK_AUTH_TOKEN with your real credentials before uploading. • For ESP32 - specific Bluetooth functionality, ensure the correct board definitions and include BluetoothSerial.h • When using motors or multiple LEDs, be mindful of power budgets; use external supplies and proper drivers. End of Document