Iot Lab File - Merged
Iot Lab File - Merged
4 Leds with musical blinking and buzzer connected and also connect push
button.
Aim : The aim of this project can be to create a fun and interactive device with lights and
sounds. Here are some possible functionalities:
Musical light show: The LEDs blink in sequence or patterns along with a musical
melody played by the buzzer. Pressing the button could trigger different light shows
or melodies.
Interactive sound effects: The push button activates a musical sound or a
combination of sounds from the buzzer, along with corresponding blinking patterns
from the LEDs.
Customizable light and sound: The user can program different light sequences and
Msounds using the push button. This could require a microcontroller like Arduino.
List of components :
Jumper wires
Breadboard
Microcontroller
4 LEDs
Resistors
Push button
Buzzer
Program:
int melody[] = {262, 330, 392, 523}; // Simple melody notes (C4, E4, G4, C5)
int noteDurations[] = {400, 400, 400, 400}; // Durations for each note (in milliseconds)
void setup() {
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
pinMode(LED_PIN4, OUTPUT);
pinMode(BUTTON_PIN, INPUT); // Set button pin as input (with internal pull-up resistor)
void loop() {
for (int i = 0; i < 4; i++) { // Loop through melody notes and durations
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
{ switch (ledIndex) {
case 0:
break;
case 1:
digitalWrite(LED_PIN2, HIGH); // Turn on LED 2
break;
case 2:
break;
case 3:
break;
digitalWrite(ledIndex + 8, LOW); // Turn off the currently lit LED based on index
Output:
EXPERIMENT:-2
Connect Arduino with Motion Sensor with Distance sensor with Alert system.
Aim:- The aim of connecting an Arduino with a motion sensor, distance sensor, and an alert
system is to create a smart security system that can detect movement and proximity within a
specific area and trigger an alert. Here's a breakdown of the functionalities:
Motion Detection: The motion sensor (e.g., PIR sensor) detects movement within its
field of view.
Distance Measurement: The distance sensor (e.g., ultrasonic sensor) measures the
distance of an object from the sensor.
Alert System: When both sensors detect something suspicious (e.g., motion within a
certain distance), an alert is triggered
List of components:
Arduino Uno
Breadboard
Jumper wires
Motion Sensor
Distance Sensor
LED
Program:
Experiment : - 3
Connect Arduino for Home automation with Temperature Sensor with Motor &
LDR with light working and additionally LCD display.
Aim:- The aim of this Arduino project for home automation combines several functionalities
to create a dynamic and interactive environment
The Arduino reads temperature and light level from the respective sensors.
Based on pre-programmed settings, the Arduino controls the motor to adjust
temperature (e.g., turn on a fan if it gets too hot).
Optionally, the Arduino can control motors for light-based actions (e.g., close
curtains when it gets dark).
The LCD display shows the current temperature and light level (optional for light control).
List of components:-
Arduino Uno
Temperature Sensor
Jumper Wires
Motor
LDR
LCD Display
Circuit Diagram:-
Experiment :-4
Connect Arduino with RGB Led with Soil moisture sensor and display with
LCD start motor on dry values.
Aim:- The aim of this project is to create an automated plant watering system.
List of components:-
Arduino Uno
Soil Moisture Sensor
RGB LED
Jumper Wires
Water Pump
Experiment:-5
Develop a progress bar with the connection of any sensor to display the live
status with LCD using Arduino in Wowki.
Aim:- The aim of this project is to create a visual representation of live sensor data using a
progress bar displayed on an LCD screen connected to an Arduino board.
List of component:-
Arduino Uno
Sensor
Jumper Wires
LCD Display
Breadboard
Circuit diagram:-
Program:-
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
//LiquidCrystal_I2C lcd(0x3f,16,2);
byte gauge_empty[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000,
B11111};
byte gauge_fill_1[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000,
B11111};
byte gauge_fill_2[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000,
B11111};
byte gauge_fill_3[8] = {B11111, B11100, B11100, B11100, B11100, B11100, B11100,
B11111};
byte gauge_fill_4[8] = {B11111, B11110, B11110, B11110, B11110, B11110, B11110,
B11111};
byte gauge_fill_5[8] = {B11111, B11111, B11111, B11111, B11111, B11111, B11111,
B11111};
byte gauge_left[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000,
B11111};
byte gauge_right[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001,
B11111};
byte gauge_mask_left[8] = {B01111, B11111, B11111, B11111, B11111, B11111, B11111,
B01111};
byte gauge_mask_right[8] = {B11110, B11111, B11111, B11111, B11111, B11111, B11111,
B11110};
byte warning_icon[8] = {B00100, B00100, B01110, B01010, B11011, B11111, B11011,
B11111};
byte gauge_left_dynamic[8];
byte gauge_right_dynamic[8];
int cpu_gauge = 0;
char buffer[10];
int move_offset = 0;
const int gauge_size_chars = 16;
char gauge_string[gauge_size_chars+1];
void setup()
{
lcd.init();
lcd.createChar(7, gauge_empty); // middle empty gauge
lcd.createChar(1, gauge_fill_1); // filled gauge - 1 column
lcd.createChar(2, gauge_fill_2); // filled gauge - 2 columns
lcd.createChar(3, gauge_fill_3); // filled gauge - 3 columns
lcd.createChar(4, gauge_fill_4); // filled gauge - 4 columns
lcd.createChar(0, warning_icon); // warning icon - just because we have one more
custom character that we could use
lcd.backlight(); // enable backlight for the LCD module
}
void loop()
{
float units_per_pixel = (gauge_size_chars*5.0)/100.0; // every character is 5px wide,
we want to count from 0-100
int value_in_pixels = round(cpu_gauge * units_per_pixel); // cpu_gauge
value converted to pixel width
int tip_position = 0; // 0= not set, 1=tip in first char, 2=tip in middle, 3=tip in last char
if (value_in_pixels < 5) {tip_position = 1;} // tip is inside the first
character
else if (value_in_pixels > gauge_size_chars*5.0-5) {tip_position = 3;} // tip is inside the
last character
else {tip_position = 2;} // tip is somewhere in the middle
move_offset = 4 - ((value_in_pixels-1) % 5); // value for offseting the pixels for
the smooth filling
for (int i=0; i<8; i++) { // dynamically create left part of the gauge
if (tip_position == 1) {gauge_left_dynamic[i] = (gauge_fill_5[i] << move_offset) |
gauge_left[i];} // tip on the first character
else {gauge_left_dynamic[i] = gauge_fill_5[i];} // tip not on
the first character
gauge_left_dynamic[i] = gauge_left_dynamic[i] & gauge_mask_left[i];
// apply mask for rounded corners
}
for (int i=0; i<8; i++) { // dynamically create right part of the gauge
if (tip_position == 3) {gauge_right_dynamic[i] = (gauge_fill_5[i] << move_offset) |
gauge_right[i];} // tip on the last character
else {gauge_right_dynamic[i] = gauge_right[i];} // tip not
on the last character
gauge_right_dynamic[i] = gauge_right_dynamic[i] & gauge_mask_right[i];
// apply mask for rounded corners
}
lcd.createChar(5, gauge_left_dynamic); // create custom character for the left part
of the gauge
lcd.createChar(6, gauge_right_dynamic); // create custom character for the right part
of the gauge
for (int i=0; i<gauge_size_chars; i++) { // set all the characters for the gauge
if (i==0) {gauge_string[i] = byte(5);} // first character = custom left piece
else if (i==gauge_size_chars-1) {gauge_string[i] = byte(6);} // last character =
custom
right piece
else { // character in the middle, could be empty, tip or
fill
// gauge drawing
lcd.setCursor(0,0); // move cursor to top left
sprintf(buffer, "CPU:%3d%% ", cpu_gauge); // set a string as CPU: XX%, with
the number always taking at least 3 character
lcd.print(buffer); // print the string on the display
lcd.write(byte(0)); // print warning character
lcd.setCursor(0,1); // move the cursor to the next
line lcd.print(gauge_string); // display the gauge
// increase the CPU value, set between 0-100
cpu_gauge = cpu_gauge +1;
if (cpu_gauge > 100) {cpu_gauge = 0;}
delay(100); // wait for a while - 100ms = update the screen 10x in a second
}
Output:-
Experiment :- 6
Create a Waste management system with the LCD diaplay in WoWki.
Aim:- The aim of this waste management system is to provide information and potentially
automate actions related to waste disposal using an LCD display and possibly other
functionalities within the Wowki environment (depending on its capabilities).
List of components:-
Arduino Uno
Sensor
Jumper Wires
LCD Display
Breadboard
Circuit Diagram:-
Program:-
#define BLYNK_TEMPLATE_ID "TMPL3g-C2Rb1s"
#define BLYNK_TEMPLATE_NAME "SMART CAMPUS waste management
system" #define BLYNK_AUTH_TOKEN "3yKGFQ8KT-iOA8vI81tKuUwCuykEZlCv"
#define TRIGGER_PIN_1 12 // GPIO pin connected to the trigger pin of the first ultrasonic
sensor
#define ECHO_PIN_1 14 // GPIO pin connected to the echo pin of the first ultrasonic sensor
#define TRIGGER_PIN_2 16 // GPIO pin connected to the trigger pin of the second ultrasonic
sensor
#define ECHO_PIN_2 17 // GPIO pin connected to the echo pin of the second ultrasonic
sensor
#define LED_PIN_1_ON 2 // GPIO pin connected to the first LED ON pin
#define LED_PIN_1_OFF 0 // GPIO pin connected to the first LED OFF pin
#define LED_PIN_2_ON 4 // GPIO pin connected to the second LED ON pin
#define LED_PIN_2_OFF 5 // GPIO pin connected to the second LED OFF pin
#define BUZZER_PIN_1 32 // GPIO pin connected to the first buzzer
#define BUZZER_PIN_2 33 // GPIO pin connected to the second buzzer
#include<Ultrasonic.h>
#include<BlynkSimpleEsp32.h>
Ultrasonic ultrasonic1(TRIGGER_PIN_1,
ECHO_PIN_1); Ultrasonic
ultrasonic2(TRIGGER_PIN_2, ECHO_PIN_2); char
ssid[] = "Wokwi-GUEST";
char pass[] = "";
char auth[] = "3yKGFQ8KT-iOA8vI81tKuUwCuykEZlCv";
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(LED_PIN_1_ON, OUTPUT); // Set LED 1 ON pin as an output
pinMode(LED_PIN_1_OFF, OUTPUT); // Set LED 1 OFF pin as an output
pinMode(LED_PIN_2_ON, OUTPUT); // Set LED 2 ON pin as an output
pinMode(LED_PIN_2_OFF, OUTPUT); // Set LED 2 OFF pin as an output
pinMode(BUZZER_PIN_1, OUTPUT); // Set buzzer 1 pin as an
output pinMode(BUZZER_PIN_2, OUTPUT); // Set buzzer 2 pin as
an output Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
long distance1 = measureDistance(TRIGGER_PIN_1,
ECHO_PIN_1); long distance2 =
measureDistance(TRIGGER_PIN_2, ECHO_PIN_2); long a = 399 -
distance1;
long b = 399 - distance2; // Read distance from the second ultrasonic sensor
Serial.print("Bin1 fill level: ");
Serial.print(a);
Serial.print(" cm | Bin2 fill level: ");
Serial.print(b);
Serial.println(" cm");
Blynk.virtualWrite(V1, a ); // Send distance 1 to Blynk app
Blynk.virtualWrite(V2, b);
// Control LED 1 and buzzer 1 based on distance from sensor 1
if (distance1 < 50) {
Serial.println("Bin1 is full!!. Don't put waste on it!!");
digitalWrite(LED_PIN_1_ON, HIGH); // Turn on LED 1
digitalWrite(LED_PIN_1_OFF, LOW); // Turn off LED 1
digitalWrite(BUZZER_PIN_1, HIGH);
tone(BUZZER_PIN_1, 100);
} else {
digitalWrite(LED_PIN_1_ON, LOW); // Turn off LED
1 digitalWrite(LED_PIN_1_OFF, HIGH); // Turn on
LED
digitalWrite(BUZZER_PIN_1, LOW); // Turn off buzzer 1
}
// Control LED 2 and buzzer 2 based on distance from sensor 2
if (distance2 < 50) {
Serial.println("Bin2 is full!!. Don't put waste on it!!");
digitalWrite(LED_PIN_2_ON, HIGH); // Turn on LED 2
digitalWrite(LED_PIN_2_OFF, LOW); // Turn off LED 2
digitalWrite(BUZZER_PIN_2, HIGH); // Turn on buzzer 2
tone(BUZZER_PIN_2, 100);
} else {
digitalWrite(LED_PIN_2_ON, LOW); // Turn off LED 2
digitalWrite(LED_PIN_2_OFF, HIGH); // Turn on LED 2
digitalWrite(BUZZER_PIN_2, LOW); // Turn off buzzer 2
}
delay(1000); // Delay for stability
}
long measureDistance(int tp, int ep
{
digitalWrite(tp, LOW);
delay(2);
digitalWrite(tp, HIGH);
delay(10);
digitalWrite(tp, LOW)
long duration = pulseIn(ep, HIGH);
long distance = duration * 0.034 / 2 ;
return distance;
}
Output:-
Experiment :- 7
Develop a live Weather display to fetch from free API avaliable online in WoWki
Aim :- The aim of this project is to display live weather information on an LCD screen (or a
similar UI element) within the Wowki environment by fetching data from a free online
weather API.
List of libraries:-
Adafruit SSD1306
HttpClient
ArduinoJson
WiFi
Arduino_JSON
Circuit Diagram:-
Program:-
#include <Wire.h>
#include
<Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* weatherAPIKey = "ee6ba6810020699060c2af52ff377857";
const char* weatherAPIURL =
"http://api.openweathermap.org/data/2.5/weather?q=Mumbai,IN,&appid=";
void setup() {
Serial.begin(115200);
delay(2000); // Delay for serial connection to be established
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting...");
}
Serial.println("Connected to WiFi");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
}
void loop() {
display.clearDisplay();
if (WiFi.status() == WL_CONNECTED)
{ HTTPClient http;
String url = String(weatherAPIURL) + String(weatherAPIKey);
http.begin(url);
int httpResponseCode =
http.GET(); if (httpResponseCode >
0) {
String payload = http.getString();
JSONVar data =
JSON.parse(payload);
double temperature = data["main"]["temp"];
temperature -= 273.15; // Convert from Kelvin to Celsius
display.setCursor(0, 0);
display.print("Temperature: ");
display.print(temperature);
display.print(" C");
} else {
display.setCursor(0, 0);
display.println("Error getting weather");
}
http.end();
} else {
display.setCursor(0, 0);
display.println("WiFi Disconnected");
}
display.display();
delay(30000); // Delay for 30 seconds before fetching weather again
}
OUTPUT:-
Experiment:-8
Create a Weather logger using DHT 22 with MQTT protocol in WoWki.
Aim:- The aim of this project is to create a system that logs temperature and humidity data
from a DHT22 sensor using the MQTT protocol within the Wowki environment (if it
supports communication with sensors and MQTT).
List of componets:-
Adafruit SSD1306
HttpClient
ArduinoJson
WiFi
Arduino_JSON
Circuit Diagram:-
Program:-
import network
import time
from machine import Pin
import dht
import ujson
from umqtt.simple import MQTTClient #
MQTT Server Parameters
MQTT_CLIENT_ID = "micropython-weather-demo"
MQTT_BROKER = "broker.mqttdashboard.com"
MQTT_USER = ""
MQTT_PASSWORD = ""
MQTT_TOPIC = "wokwi-weather"
sensor = dht.DHT22(Pin(15))
print("Connecting to WiFi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '') while
not sta_if.isconnected():
print(".", end="")
time.sleep(0.1) print("
Connected!")
print("Connecting to MQTT server... ", end="")
client = MQTTClient(MQTT_CLIENT_ID, MQTT_BROKER,
user=MQTT_USER, password=MQTT_PASSWORD)
client.connect()
print("Connected!")
prev_weather = ""
while True:
print("Measuring weather conditions... ", end="") sensor.measure()
message = ujson.dumps({ "temp":
sensor.temperature(),
"humidity": sensor.humidity(),
})
if message != prev_weather:
print("Updated!")
print("Reporting to MQTT topic {}: {}".format(MQTT_TOPIC, message))
client.publish(MQTT_TOPIC, message)
prev_weather = message else:
print("No change") time.sleep(1)
OUTPUT:-
EXPERIMENT:-9
Create a Smart Agriculture monitoring system using either Pi or Arduino in
Wowki/Thinkercad.
Aim:- The system uses sensors to monitor soil, temperature, humidity (and light) to
optimize watering, control environment, and boost crop health and yield, all while
promoting resource efficiency and sustainable agriculture
List of components:-
Arduino Uno
Soil Moisture Sensor
Temperature Sensor
Jumper Wires
Breadboard
Humidity Sensor
Circuit Diagram:-
Program:-
from machine import Pin
from time import sleep
from dht import
DHT22 dht =
DHT22(Pin(15))
while True:
dht.measure()
temp = dht.temperature()
hum = dht.humidity()
print(f"Temperature: {temp}°C Humidity: {hum}% ")
sleep(2)
Output:-
EXPERIMENT:-16
Create a Smart Industry/Healthcare monitoring system using either Pi or
Arduino in Wowki/Thinkercad
Aim:- This Smart Industry/Healthcare system, built with Raspberry Pi or Arduino,
continuously gathers sensor data (temperature, heart rate, etc.), analyzes it for trends and
issues, displays it clearly, and sends alerts for critical situations. It empowers remote
monitoring and potential control, ultimately aiming to improve efficiency, predict problems,
and enhance well-being
List of components:-
Arduino Uno
Temperature Sensor
Pressure Sensor
Humidity Sensor
Ciruit Diagram:-
Program:-
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
Servo servoMotor;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int heartRateSensorPin = A4;
int tempSensorPin = A5;
int waterButtonPin = 2;
int ledPin = 3;
int simulatedHeartRate = 75;
int waitTime = 1000;
void setup() {
servoMotor.attach(9);
pinMode(heartRateSensorPin, INPUT);
pinMode(tempSensorPin, INPUT);
pinMode(waterButtonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
lcd.init();
lcd.backlight();
void loop() {
simulateHeartRate();
simulateTemperature();
checkWaterIntake();
delay(waitTime);
}
void simulateHeartRate()
{ simulatedHeartRate = random(70, 91);
lcd.setCursor(0, 0);
lcd.print("HR: ");
lcd.print(simulatedHeartRate);
lcd.print(" bpm ");
}
void simulateTemperature() {
// temperature variability
int temperature = random(0, 15);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C ");
}
void checkWaterIntake() {
static unsigned long lastDebounceTime = 0;
static bool isServoOpen = false;
int reading = digitalRead(waterButtonPin);
if (reading == LOW && (millis() - lastDebounceTime > 200))
{ lastDebounceTime = millis(); // Update the last debounce
time if (!isServoOpen) {
simulatedHeartRate += 5; // Increase heart rate due to activity
servoMotor.write(0);
digitalWrite(ledPin, HIGH); // Turn on the LED
isServoOpen = true;
delay(waitTime);
}
}
if (isServoOpen && (millis() - lastDebounceTime > waitTime))
{ servoMotor.write(90); // Close the servo
digitalWrite(ledPin, LOW); // Turn off the LED
isServoOpen = false;
simulatedHeartRate = 75; // Reset to default heart rate
}
}
OUTPUT:-