0% found this document useful (0 votes)
40 views29 pages

IoT (EC702) UI19EC039

This document contains the code and procedures for four experiments using sensors and actuators with an Arduino board: 1. Interfacing an LDR light sensor to read light intensity values. 2. Using an ultrasonic distance sensor to measure distance and output it to serial monitor. 3. Connecting a smoke sensor to detect smoke and trigger an LED, also outputting sensor values. 4. Attaching a servo motor and writing code to control its position.

Uploaded by

Ritesh Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views29 pages

IoT (EC702) UI19EC039

This document contains the code and procedures for four experiments using sensors and actuators with an Arduino board: 1. Interfacing an LDR light sensor to read light intensity values. 2. Using an ultrasonic distance sensor to measure distance and output it to serial monitor. 3. Connecting a smoke sensor to detect smoke and trigger an LED, also outputting sensor values. 4. Attaching a servo motor and writing code to control its position.

Uploaded by

Ritesh Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Internet of Things (EC 702)

Indian Institute of Information Technology Surat


for

Bachelor of Technology
In

Electronics and Communication Engineering Department

Submitted by

Ritesh Shukla (UI19EC39)


Course Faculty

Dr. Hemant S. Goklani


Dr. Pramila Jakhar

Department of Electronics and Communication Engineering


Indian Institute of Information Technology Surat
Gujarat-395007, India

December – 2022

1
UI19EC39

Certificate
This is to certify that
Mr. Ritesh Shukla of 4th year class Electronics &
Communication Engineering Roll No.
UI19EC39 has satisfactorily completed the course
in Internet of Things (EC 702) laboratory
practice during the academic year 2021-2022.

Date: 10 Dec 2022 Professor

2
UI19EC39

Index

Sr.no AIM

1  Introduction to Arduino Programming


2  Implement the following with Arduino in Tinkercad
i. Control an LED with a pushbutton
ii. Traffic light using LEDs
iii. RGB LEDs
3 Interface following with the Arduino
i. LDR sensor
ii. Ultrasonic distance sensor
iii. Smoke sensor
iv. Servo motor
4 Implement the following using on Arduino
i. Room temperature controller design
ii. Parking alert system design
iii. Controlling LED brightness using LDR sensor
5-6 Design a Home Automation System using Arduino which can control
various electrical equipment using IR remote control and also having
any 4 below listed features:
i. Security against unauthorized access
ii. Electrical devices can be operated using remote control (not
just LEDs)
iii. Scheduling of lights
iv. Motion detection
v. Door controlled lights
vi. Room temperature controlling
vii. Gas leakage detection
viii. Fire detection
ix. Display various device’s status on LCD

3
UI19EC39

EXPERIMENT 1

AIM: Introduction to Arduino Programming

APPARATUS: Tinkercad software, Arduino Uno R3, Led, Resistor 220Ω

CODE:

// C++ code
//
void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}

Fig 1.1: Code block in tinkercad

CIRCUIT:

4
UI19EC39

Fig 1.2: Led Blinking circuit

OUTPUT:

Fig 3: Led blinking

CONCLUSION: In this experiment we learned the basics of arduino programming in


tinkercad software.

5
UI19EC39

EXPERIMENT 2

AIM: Implement the following with Arduino in Tinkercad


i. Control an LED with a pushbutton
ii. Traffic light using LEDs
iii. RGB LEDs

APPARATUS: Tinkercad software, Arduino Uno R3, Led, Resistor 220Ω

CODE:

1) Control an LED with push buton

void setup()
{
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}

void loop()
{
if(digitalRead(2) == 1)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}

2) Traffic lights using LED

void setup()
{
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}

6
UI19EC39

void loop()
{
digitalWrite(4, HIGH); // For green LED
delay(3000); // Wait for 3 second
digitalWrite(4, LOW);

digitalWrite(3, HIGH); // For orange LED


delay(1000); // Wait for 1 second
digitalWrite(3, LOW);

digitalWrite(2, HIGH); // For the red LED


delay(3000); // Wait for 3 second
digitalWrite(2, LOW);
}

3) RGB LEDs

void setup()
{
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}

void loop()
{
analogWrite(11, 255);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(10, 0);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(9, 0);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(11, 255);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(10, 255);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(9, 102);
delay(1000); // Wait for 1000 millisecond(s)
}

7
UI19EC39

CIRCUIT:
1)

Fig 2.1: Control LED using push button

2)

Fig 2.2: Traffic lights using LED

8
UI19EC39

3)

Fig 2.3: RGB led

OUTPUT:

1)

Fig 2.4: push button LED

2)

9
UI19EC39

Fig 2.5: Traffic signal

3)

Fig 2.6: RGB LED

CONCLUSION: In this experiment we learned to control LED using push button. We


implemented traffic lights using LEDs and also implemented RGB LEDs.

10
UI19EC39

EXPERIMENT 3

AIM: Interface following with the Arduino


i. LDR sensor
ii. Ultrasonic distance sensor
iii. Smoke sensor
iv. Servo motor

APPARATUS: Tinkercad, Arduino UNO R3, LDR sensor, Ultrasonic distance sensor, Smoke
sensor, Servo motor

CODE:

1) LDR sensor

// C++ code
//
int sensor = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);

void loop()
{
sensor = analogRead(A0);
Serial.println(sensor);
delay(100); // Wait for 100 millisecond(s)
}

2) Ultrasonic distance sensor

// C++ code
//
int US = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)


{

11
UI19EC39

pinMode(triggerPin, OUTPUT); // Clear the trigger


digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);

void loop()
{
US = 0.01723 * readUltrasonicDistance(11, 10);
Serial.println(US);
delay(100); // Wait for 100 millisecond(s)
}

3) Smoke sensor

// C++ code
//
int gas = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);

pinMode(13, OUTPUT);
}

void loop()
{
gas = analogRead(A0);
Serial.println(gas);
delay(100); // Wait for 100 millisecond(s)
if (gas > 400) {
digitalWrite(13, HIGH);

12
UI19EC39

}
digitalWrite(13, LOW);
}

4) Servo motor

// C++ code
//
#include <Servo.h>

int position = 0;

int i = 0;

int j = 0;

Servo servo_9;

void setup()
{
servo_9.attach(9, 500, 2500);

void loop()
{
position = 0;
for (position = 1; position <= 180; position += 1) {
servo_9.write(position);
delay(20); // Wait for 20 millisecond(s)
}
for (position = 179; position >= 0; position -= 1) {
servo_9.write(position);
delay(20); // Wait for 20 millisecond(s)
}
}

13
UI19EC39

CIRCUITS:
1)

Fig 3.1: LDR sensor circuit

2)

Fig 3.2: Ultrasonic distance sensor circuit

3)

14
UI19EC39

Fig 3.3: Gas sensor circuit

4)

Fig 3.4: Servo motor circuit

15
UI19EC39

OUTPUTS:

1) LDR Sensor

Fig 3.5 Serial monitor output for LDR sensor

2) Ultrasonic distance sensor

Fig 3.6: Serial monitor output for Ultrasonic distance sensor

3) Smoke detector

Fig 3.7: Serial monitor output for smoke detector

16
UI19EC39

4) Servo motor

Fig 3.8: Servo motor output

CONCLUSION: In this experiment we interfaced different sensors with Arduino UNO R3.
We noted the values for the LDR sensor, Ultrasonic distance sensor and Gas sensor on the serial
monitor. We also implemented code to rotate the servo motor.

17
UI19EC39

EXPERIMENT 4

AIM: Implement the following using on Arduino


i. Room temperature controller design
ii. Parking alert system design
iii. Controlling LED brightness using LDR sensor

APPARATUS: Tinkercad, Arduino UNO R3, LDR sensor, Ultrasonic distance sensor,
temperature sensor, buzzer, etc.

CODE:

1) Room temperature controller

// C++ code
//
float temp, tempMV, tempC;
void setup()
{
pinMode(A0, INPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop()
{
temp = analogRead(A0);
tempMV = temp*5000/1024;
tempC = (tempMV/10)+ (-50);
Serial.println(tempC);
if (tempC > 25)
{
tone(11, 5000, 100);
digitalWrite(13, HIGH);
delay(100);
}
else
{
digitalWrite(13, LOW);
delay(100);

18
UI19EC39

}
}

2) Car parking system

// C++ code
//
int dist = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)


{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}

void loop()
{
dist = 0.01723 * readUltrasonicDistance(2, 2);
if (dist > 200) {
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
} else {
if (dist > 150 && dist <= 200) {
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);

19
UI19EC39

digitalWrite(12, HIGH);
} else {
if (dist > 100 && dist <= 150) {
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
} else {
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
}
}
delay(10); // Delay a little bit to improve simulation performance
}

3) Controlling LED Brightness

// C++ code
//
int lrd = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop()
{
lrd = analogRead(A0);
Serial.println(lrd);
analogWrite(13, map(lrd, 0, 1023, 0, 255));
delay(1000); // Wait for 1000 millisecond(s)
}

20
UI19EC39

CIRCUITS:
1)

Fig 4.1: Temperature controller circuit


2)

Fig 4.2: Car Parking System

3)

21
UI19EC39

Fig 4.3: Brightness controller

OUTPUTS:
1)

Fig 4.4: Temperature Controller

2)

22
UI19EC39

Fig 4.5: Car parking system

3)

Fig 4.6: LED Brightness controller

CONCLUSION: In this experiment we learned to make control systems for room


temperature, LED brightness and Car parking. Here we took inputs from various sensors and the
resulting output was indicated using buzzers and LEDs

23
UI19EC39

EXPERIMENT 5-6

AIM:  Design a Home Automation System using Arduino which can control various electrical
equipment using IR remote control and also having any 4 below listed features:
● Security against unauthorized access
● Electrical devices can be operated using remote control
(not just LEDs)
● Scheduling of lights
● Motion detection
● Door controlled lights
● Room temperature controlling
● Gas leakage detection
● Fire detection
● Display various device’s status on LCD

APPARATUS: Tinkercad, Arduino UNO R3, IR remote, Power Supply, Relay SPDT, IR
sensor, DC motor, Hobby gearmotor, Vibration motor, push buttons, light bulb

CODE:

#include <SPI.h>
#include <Wire.h>

#include <IRremote.h>
int gas = 0;
float temp, tempMV, tempC;
int door = 0;
const int relay_1 = 12;
const int relay_2 = 11;
const int relay_3 = 10;
const int relay_4 = 9;

const int mswitch_1 = 8;


const int mswitch_2 = 7;
const int mswitch_3 = 6;
const int mswitch_4 = 5;

int RECV_PIN = 3;

IRrecv irrecv(RECV_PIN);

24
UI19EC39

decode_results results;

int toggleState_1 = 0;
int toggleState_2 = 0;
int toggleState_3 = 0;
int toggleState_4 = 0;

void setup() {

Serial.begin(9600);
irrecv.enableIRIn();

pinMode(relay_1, OUTPUT);
pinMode(relay_2, OUTPUT);
pinMode(relay_3, OUTPUT);
pinMode(relay_4, OUTPUT);

pinMode(A0, INPUT);
pinMode(A0, INPUT);
pinMode(2, INPUT);

pinMode(mswitch_1, INPUT_PULLUP);
pinMode(mswitch_2, INPUT_PULLUP);
pinMode(mswitch_3, INPUT_PULLUP);
pinMode(mswitch_4, INPUT_PULLUP);
}

void relayOnOff(int relay){

switch(relay){
case 1:
if(toggleState_1 == 0){
digitalWrite(relay_1, HIGH); // turn on relay 1
toggleState_1 = 1;
}
else{
digitalWrite(relay_1, LOW); // turn off relay 1
toggleState_1 = 0;
}
delay(100);
break;
case 2:
if(toggleState_2 == 0){
gas = analogRead(A0);
delay(100); // Wait for 100 millisecond(s)

25
UI19EC39

if (gas > 400) //{


digitalWrite(relay_2, HIGH);
toggleState_2 = 1;
}
else{
digitalWrite(relay_2, LOW); // turn off relay 2
toggleState_2 = 0;
}
delay(100);
break;
case 3:
if(toggleState_3 == 0){
temp = analogRead(A1);
tempMV = temp*5000/1024;
tempC = (tempMV/10)+ (-50);
if (tempC > 25){
digitalWrite(relay_3, HIGH);
Serial.println("On AC");}
else{
digitalWrite(relay_4, LOW);} // turn on relay 3
toggleState_3 = 1;
}else{
digitalWrite(relay_3, LOW); // turn off relay 3
toggleState_3 = 0;
}
delay(100);
break;
case 4:
if(toggleState_4 == 0){

digitalWrite(relay_4, HIGH);

// turn on relay 4
toggleState_4 = 1;
}
else{
digitalWrite(relay_4, LOW); // turn off relay 4
toggleState_4 = 0;
}
delay(100);
break;

default : break;
}

26
UI19EC39

void loop() {

if (digitalRead(mswitch_1) == LOW){
delay(200);
relayOnOff(1);
}
else if (digitalRead(mswitch_2) == LOW){
delay(200);
relayOnOff(2);
}
else if (digitalRead(mswitch_3) == LOW){
delay(200);
relayOnOff(3);
}
else if (digitalRead(mswitch_4) == LOW){
delay(200);
relayOnOff(4);
}

if (irrecv.decode(&results)) {
switch(results.value){
case 0xFD08F7:
relayOnOff(1);
break;
case 0xFD8877:
relayOnOff(2);
break;
case 0xFD48B7:
relayOnOff(3);
break;
case 0xFD28D7:
relayOnOff(4);
break;
default : break;
}
irrecv.resume();
}
}

27
UI19EC39

CIRCUIT:

Fig 5.1: Home Automation System with light bulb Gas detection system, temperature controller system
and motor.

OUTPUT:

Fig 5.2: Output of home automation system

28
UI19EC39

CONCLUSION: In this experiment we implemented home automation system using


Arduino. We connected light bulb, DC motor for fan, Smoke detector system and temperature
controller system and used a IR remote to control it.

29

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy