Practical File Iot - For Merge
Practical File Iot - For Merge
Practical File
of
Submitted By:
Saurav Yadav
0901CD211051
Faculty Mentor:
Dr. Devesh Kumar Lal
Assistant Professor
CSE
Submitted to:
JAN-MAY 2024
INDEX
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
OUTPUT :
Experiment = 2
#include <DHT.h>;
//Constants
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//Variables
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(100);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(10000);
}
OUTPUT
Experiment = 3
#include <Servo.h>
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo
object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
}
OUTPUT :
Ultrasonic Sensor :
void setup() {
Serial.begin(9600); // Starting Serial Terminal
}
void loop() {
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
//Defining pins
int pir = 2;
void setup()
{
void loop()
{
//Read data from the sensor
int status = digitalRead(pir);
if(status == HIGH)
{
Serial.println("Motion Detected");
// tone(buzz,1000,700);
delay(2000);
}
else
{
Serial.println("No one is there");
delay(1000);
}
}
OUTPUT :
Experiment = 5
#include <DHT.h>;
//Constants
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//Variables
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(100);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables temp
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
if(temp > 40){
Serial.println("fire is detected");
}
delay(10000); //Delay 2 sec.
}
OUTPUT :
Experiment = 6
int led=13;
int MQ2pin=A0;
void setup(){
Serial.begin(9600);
}
void loop(){
float sensor=value;
sensorValue=analogRead(MQ2pin);
if(sensorValue>=250){
digitalWrite(led,HIGH);
Serial.print(sensorValue);
Serial.println(" Gas Detected ");
else{
digitalWrite(led,LOW);
Serial.println("Sensor Value : ");
Serial.println(sensorValue);
}
delay(1000);
}
OUTPUT :
Experiment = 7
char Incoming_value = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("/n");
if (Incoming_value == 'on')
digitalWrite(13,HIGH);
else if(Incoming_value == 'off')
digitalWrite(13,LOW);
}
}
Implementing an MQTT-based IoT system involves several steps. MQTT (Message Queuing
Telemetry Transport) is a lightweight messaging protocol ideal for IoT applications due to its
low bandwidth usage, low power consumption, and efficient communication between
devices. Here's a high-level overview of how you can implement such a system:
Choose an MQTT Broker: Select an MQTT broker that will serve as the central hub
for communication between devices. Popular MQTT brokers include Mosquitto,
HiveMQ, and RabbitMQ.
Set Up the MQTT Broker: Install and configure the chosen MQTT broker on a
server or cloud platform. Ensure that it's accessible to all your IoT devices and
applications.
Connect IoT Devices: Implement MQTT client libraries on your IoT devices. These
libraries enable devices to publish data (e.g., sensor readings) and subscribe to topics
to receive commands or updates.
Define Topics and Payloads: Define a topic structure that reflects the different types
of data your IoT devices will publish and subscribe to. Topics can represent sensors,
devices, or specific data types. Decide on the payload format (e.g., JSON, XML) for
exchanging data between devices and applications.
Maintenance and Updates: Regularly maintain and update your MQTT-based IoT
system to address any security vulnerabilities, optimize performance, and add new
features as needed. This may involve software updates for devices, firmware updates
for IoT gateways, or upgrades to the MQTT broker.
By following these steps, you can successfully implement an MQTT-based IoT system
tailored to your specific application requirements.
Experiment = 9
#include <WiFi.h>
#include <HTTPClient.h>
#include "DHT.h"
#define DHTPIN 5
// Domain Name with full URL Path for HTTP POST Request
void setup() {
Serial.begin(115200);
// WiFi.begin(ssid, password);
WiFi.begin("Wokwi-GUEST", "");
dht.begin();
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println("");
Serial.println(WiFi.localIP());
void loop() {
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
//float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Your Domain name with URL path or IP address with path
http.begin(client, serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Data to send with HTTP POST
Serial.println(httpResponseCode);
http.end();
else {
Serial.println("WiFi Disconnected");
}
OUTPUT :
Experiment = 10
char Incoming_value = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("/n");
if (Incoming_value == 'on')
digitalWrite(13,HIGH);
else if(Incoming_value == 'off')
digitalWrite(13,LOW);
}
}
Define the access control requirements: Determine what areas or assets need to be
secured and who should have access to them.
Consider integration: Determine if the access control system needs to integrate with
other systems such as security cameras, alarms, or databases.
System Design:
Design the RFID infrastructure: Plan the placement of RFID readers and antennas
to ensure adequate coverage and read range for the intended application.
Select access control software: Choose or develop software that can manage user
credentials, access permissions, and event logging.
Design user interface: Determine how users will interact with the system, whether
through RFID cards, key fobs, mobile devices, or a combination.
Hardware Installation:
Install RFID readers and antennas: Mount readers and antennas in strategic
locations according to the system design.
Install RFID tags: Affix RFID tags to access cards, key fobs, or other items that
users will carry for access.
Software Configuration:
Configure access control software: Set up user accounts, access levels, and
permissions in the software.
Integrate with other systems: If necessary, configure integration with other security
or management systems.
Conduct system testing: Test the RFID readers, antennas, and software to ensure
proper functionality and reliability.
Validate access control: Verify that users can access permitted areas and that
unauthorized access attempts are denied.
Deployment:
Roll out the access control system: Deploy the system to the intended users and
locations.
Train users and administrators: Provide training on how to use the access control
system, including how to present RFID credentials and manage access permissions.
Maintenance and Monitoring:
Update software: Install software updates and security patches to keep the access
control system secure and up to date.
Monitor access logs: Review access logs regularly to identify any anomalies or
security incidents.