[go: up one dir, main page]

0% found this document useful (0 votes)
11 views27 pages

Iot Manual

The document is a lab manual for the OCS352 IoT Concepts and Applications course at Muthayammal Educational Institutions, detailing objectives, experiments, and outcomes for students. It covers various IoT technologies, including Arduino and Raspberry Pi, and includes specific experiments for interfacing with modules like Zigbee, GSM, and Bluetooth. The manual aims to equip students with practical skills in IoT application development and data analytics.

Uploaded by

suganyamurali02
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)
11 views27 pages

Iot Manual

The document is a lab manual for the OCS352 IoT Concepts and Applications course at Muthayammal Educational Institutions, detailing objectives, experiments, and outcomes for students. It covers various IoT technologies, including Arduino and Raspberry Pi, and includes specific experiments for interfacing with modules like Zigbee, GSM, and Bluetooth. The manual aims to equip students with practical skills in IoT application development and data analytics.

Uploaded by

suganyamurali02
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/ 27

DEPARTMENT OF ELECTRICAL AND ELECTRONICS

ENGINEERING

MUTHAYAMMAL
EDUCATIONAL
INSTITUTIONS

LAB MANUAL

OCS352- IOT CONCEPTS AND APPLICATIONSLABORATORY

VI SEMESTER
(Academic Year – 2024-2025)

Prepared by Approved by
Mrs.S.Suganya M.E., Prof.Dr.C.Nagarajan M.Tech.,Phd.,
AP/EEE HOD/EEE
OCS352 IOT CONCEPTS AND APPLICATIONS L T P C
2 0 2 3

OBJECTIVES:

The main learning objective of this course is to prepare the students able to:
 To apprise students with basic knowledge of IoT that paves a platform to understand physical
and logical design of IoT.
 To teach a student how to analyse requirements of various communication models and
protocols for cost-
Effective design of IoT applications on different IoT platforms.
 To introduce the technologies behind Internet of Thing (IoT).
 To explain the students how to code for an IoT application using Arduino/Raspberry Pi open
platform.
 To apply the concept of Internet of Things in real world scenario.

IoT CONCEPTS AND APPLICATIONS LABORATORY LIST OF


EXPERIMENTS

1. Introduction to Arduino platform and programming

2. Interfacing Arduino to Zigbee module

3. Interfacing Arduino to GSM module

4. Interfacing Arduino to Bluetooth module

5. Introduction to Raspberry PI platform and python programming

6. Interfacing sensors to Raspberry PI

7. Communicate between Arduino and Raspberry PI using any wireless medium

8. Setup a cloud platform to log the data

9. Log Data using Raspberry PI and upload to the cloud platform

10. Design an IOT based system

Course period: 30 Hours


COURSE OUTCOMES:

At the end of the course the students would be able to:

CO1 – Explain the concept of IoT

CO2 – Understand the communication models and various protocols for IoT

CO3 - Design portable IoT using Arduino/Raspberry Pi/ open platform

CO4 – Apply data analytics and use cloud offerings related to IoT.

CO5 – Analyze applications of IoT in real time scenario.

CORRELATION OF COURSE OUTCOMES (COs) WITH POs/ PSOs

CO/
PO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3

3 3 2 2 2 1 - - - - - 2 3 2 1
CO1

3 3 2 2 1 3 - - - - - 2 3 3 3
CO2

3 3 2 2 2 1 - - - - - 3 2 2 2
CO3

CO4 2 3 3 1 1 3 - - - - - 1 3 1 2

CO5 2 3 1 1 2 2 - - - - - 1 3 1 1
EX. NO: 1 INTRODUCTION TO ARDUINO PLATFORM AND PROGRAMMING

Aim:

To study about the introduction to Arduino platform and its programming.

Apparatus Required:

1. 1 X LED
2. 1 X Resistor, 330 Ohm
3. Breadboard
4. Arduino UNO R4 or earlier versions.
5. Jumper wires

THEORY:

Introduction:

Arduino is a prototype platform (open-source) based on an easy-to-use hardware and


software. It consists of a circuit board, which can be programed (referred to as a
microcontroller) and a ready-made software called Arduino IDE (Integrated Development
Environment), which is used to write and upload the computer code to the physical board.
The key features are:
 Arduino boards are able to read analog or digital input signals from different sensors
and turn it into an output such as activating a motor, turning LED on/off, connect to the
cloud and many other actions.
 You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading software).
 Unlike most previous programmable circuit boards, Arduino does not need an extra
piece of hardware (called a programmer) in order to load a new code onto the board.
You can simply use a USB cable.
 Additionally, the Arduino IDE uses a simplified version of C++, making it easier to
learn to program.
 Finally, Arduino provides a standard form factor that breaks the functions of the micro-
controller into a more accessible package.
F ARDUINO PROCEDURES

Launch the Arduino Application

Double-click the Arduino application (arduino.exe) you have previously downloaded.(Note: if


the Arduino Software loads in the wrong language, you can change it in the preferences dialog. See
the Arduino Software (IDE) page for details.)

Open the blink example:


Open the LED blink example sketch: File > Examples
>01.Basics> Blink

Select Your Board


You'll need to select the entry in the Tools > Board menu that corresponds to your
Arduino.
Select Your Serial Port

Select the serial device of the Arduino board from the Tools | Serial Port menu. This is likely
to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serialports). To find out,
you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the
Arduino board. Reconnect the board and select that serial port.

Upload the Program

Now, simply click the "Upload" button in the environment. Wait a few seconds - you should
see the RX and TX leds on the board flashing. If the upload is successful, the message "Done
uploading." will appear in the status bar. (Note: If you have an ArduinoMini, NG, or other board, you'll
need to physically press the reset button on the board immediately before clicking the upload button on
the Arduino Software).

A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board
start to blink (in orange). If it does, congratulations! You've gotten Arduino up-and- running.
If you have problems, please see the troubleshooting suggestions.

Coding:
Program 1:

int LEDpin = 13;


int delayT = 1000;
void setup() {
// put your setup code here, to run once:
pinMode(LEDpin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LEDpin, HIGH);
delay(delayT);
digitalWrite(LEDpin, LOW);
delay(delayT);
}

Program 2:

void setup()
{
pinMode(1 3,OUTPU T);
}
void loop()
{
digitalWrite(13,HIGH);
delay(100 0);
digitalWrite(13,LOW );
delay(100 0);
}

RESULT:

Thus, the introduction to Arduino platform and programming was studied


EX.NO:02 INTERFACING ARDUINO TO ZIGBEE MODULE

Aim:
To write the Arduino program for communication between two trainers and control
the ledby switch.
Apparatus Required:

1. Arduino UNO
2. AtMega328 microcontroller
3. Zigbee Transmitter (ZTx)
4. Zigbee Receiver (ZRx)
5. USB cables
6. LEDs

Theory:

Zigbee is a low-power wireless mesh network standard targeted at battery-powered


devices in wireless control and monitoring applications. Zigbee delivers low-latency
communication. Zigbee chips are typically integrated with radios and with
microcontrollers.

Program for Zigbee Transmitter:

//Pin 2 connected to ZTx


//Pin 3 Connected to ZRx
//Switch on 7 in Dip switch S3
//Press SW3 Push Button for Led On in Receiver Trainer.
#include "SoftwareSerial.h"
SoftwareSerial

XBee(2,3);

int SW1 = A4;

void setup()
{
Serial.begin(9600 );
pinMode(SW1,INPUT);
XBee.begin(9600 );
}

void loop()
{
if (digitalRead(SW1) == HIGH)
{
Serial.println("Turn on
LED");
XBee.write('1');
delay(1000);
}
else if (digitalRead(SW1) == LOW)
{
Serial.println("Turn off
LED");
XBee.write('0');
delay(1000);
}
}

Program for ZigBee Receiver:

//Pin 2 connected to ZTx


//Pin 3 Connected to
ZRx
#include
"SoftwareSerial.h"
#include<SoftwareSer
ial.h>int led = 13;
int
receive
d = 0;
int i;

//For communicating with


zigbeeSoftwareSerial
zigbee(2,3);

void setup()
{
Serial.begin(9600);
zigbee.begin(9600);
pinMode(led, OUTPUT);

}
void loop()
{
//check if the data is
received
if (zigbee.available() >
0)
{
received = zigbee.read();
//if the data is 0, turn off the
LED
if (received == '0')
{
Serial.println("Turning off LED");
digitalWrite(led, LOW);
}
//if the data is 1, turn on the
LED
else if (received == '1')
{
Serial.println("Turning on LED");
digitalWrite(led, HIGH);
} } }

RESULT:

Thus, the Arduino is interfaced to the Zigbee module and the output is verified.
EX.NO:03 INTERFACING ARDUINO TO GSM MODULE

Aim:
To write the Arduino program for detect the flame and send a sms.

Apparatus Required:

1. Arduino UNO board.


2. SIM900A GSM Module
3. Micro SIM Card.
4. USB cable
5. Jumper wires for connections.

Note: DIP Switch S3 in Buzzer Block switch6 should be ON.

Theory:

GSM is combination of TDMA (Time Division Multiple Access), FDMA (Frequency


Division Multiple Access) and Frequency hopping. Initially, GSM use two frequency bands of
25 MHz width: 890 to 915 MHz frequency band for up-link and 935 to 960 MHz frequency
for down-link. Later on, two 75 MHz band were added.

Program for GSM:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3); // RX, TX


int flame = A0;
int buz =7;
void setup()
{
pinMode(A0,INPUT);
pinMode(buz,OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(flame) == LOW)
{
init_sms();
send_data("Flame Alert");
mySerial.println(" ");
Serial.println(" ");
send_sms();
digitalWrite(buz,HIGH);
while(1);
}
else
{
digitalWrite(buz,LOW);
}
}
void init_sms()
{
mySerial.println("AT+CMGF=1");
Serial.println("AT+CMGF=1");
delay(400);

mySerial.println("AT+CMGS=\"8838961153\"");// use your 10 digit cell no. here


Serial.println("AT+CMGS=\"8838961153\"");
delay(400);
}
void send_data(String message)
{
mySerial.print(message);
Serial.print(message);
delay(200);
}
void send_sms()
{
mySerial.write(26);
Serial.write(26);
}

RESULT:

Thus, the Arduino is interfaced to the GSM module and the output is verified.
EX.NO:04 INTERFACING ARDUINO TO BLUETOOTH MODULE

Aim:
To write the Arduino program for Electronics Notice Board.

Apparatus Required:

1. Arduino UNO
2. AtMega328 Microcontroller
3. HC-05 Bluetooth Module.
4. LED.
5. Breadboard.
6. Resistors - 1K & 2K Ohm.
7. Connecting Wires.

Note: DIP Switch S1 in 16X2 LCD Display Block should be all ON position.

Theory:
The HC-05 is a class 2 Bluetooth module designed for transparent wireless serial
communication. It is pre-configured as a slave Bluetooth device. Once it is paired to a master
Bluetooth device such as PC, smart phones and tablet, its operation becomes transparent to the
user.
Program:

//HC-05 pair password 1234


//Connection A0 ~ BTx , A1 ~
BRx#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
//Create Liquid Crystal Object called LCD
LiquidCrystal lcd (7, 6, 5, 4, 3, 2);
SoftwareSerial mySerial (A0, A1); //(Connect TX, RX from bluetooth to Pin
A0,A1 in Arduino);
String val = "No Data";
String oldval;
String newval = "No Data";
int i = 0;
void setup()
{
// Initialize the LCD
lcd.begin(16,2); //Tell Arduino to start your 16 column 2 row LCDmySerial.begin(9600);
Serial.begin(9600);
lcd.setCursor(0, 0); //Set cursor to first column of first rowlcd.print("Welcome!");
delay(2000);
void loop()
{
val = mySerial.readString();
val.trim();
Serial.println(val);
if(val != oldval)
{
newval = val;
}
lcd.clear(); lcd.setCursor(i, 0);
lcd.print(newval);
i++;
if(i >= 15)
{
i = 0;
}
val = oldval;
}

RESULT:

Thus, the Arduino is interfaced to the Bluetooth module and the output is verified.
EX.NO:05 INTRODUCTION TO RASPBERRY PI PLATFORM AND
PYTHON
PROGRAMMING

Aim:
To write the python program for Turn on & off a LED.

Apparatus Required:

1. Raspberry Pi
2. PiCo W
3. LED
4. Connecting Wires

Theory:

Python is the official programming language of the Raspberry Pi. It is known for its two unique
characteristics: cross-platform compatibility and easy-to-understand syntax. Unlike lower-level
languages like C and C++, Python uses a Python interpreter that translates the Python program into
machine-specific instructions. So as long as you have a Python interpreter on your computer, you can
run any Python program written on whatever machine. Moreover, compared to other languages, the
syntax is simple. Syntax is the arrangement of symbols, words, and phrases needed to make a Python
program work. The friendly Python syntax makes programming fun, which is perfect for a credit card
computer that is made to acquaint people in the field of computer science.

Program:

Import machine

Import time

Led=machine. Pin (15, machine.Pin.OUT)

While (True):

Led. On ()

Time. Sleep (1)

led.off ()

time. Sleep(1)

RESULT:

Thus, the LED was turned on and off and the output was verified.
EX.NO:06 INTERFACING SENSORS TO RASPBERRY PI

Aim:
To write the python program for measure the obstacle distance in cm using Ultrasonic Sensor.

Apparatus Required:

1. Raspberry Pi
2. PiCo W
3. Ultrasonic Sensor (HC-SR04)
4. Connecting Wires

Theory:

HC-SR04 stands for High-Conductance Ultrasonic Sensor consists of a transmitter and


receiver. The sensor measures how far things are without touching them, and it uses sound
waves to get the measurements right. It can work well when things are between two to four
centimeters away.

Program:

from machine import Pin


import utime
trigger = Pin(16, Pin.OUT)
echo = Pin(17, Pin.IN)
def ultra():
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(5)trigger.low()
while echo.value() == 0:
signaloff = utime.ticks_us()
while echo.value() == 1:
signalon = utime.ticks_us()
timepassed = signalon - signaloff
distance = (timepassed * 0.0343) / 2
print("The distance from object is ",distance,"cm")
while True:
ultra()
utime.sleep(1)

RESULT:

Thus, the sensors were interfaced to Raspberry Pi and the output was verified.
EX.NO:07 COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI USING ANY
WIRELESS MEDIUM

Aim of the Experiment:


To write the python program for communication between Arduino and Raspberry Pi
UsingZigBee Wireless Medium.
Apparatus Required:

1. Raspberry Pi
2. PiCo W
3. Arduino UNO
4. AtMega328 Microcontroller
5. Zigbee Transmitter (ZTx)
6. Zigbee Receiver (ZRx)
7. Connecting Wires

Raspberry Pi Interface with ZiGBee Transmitter Program:

#Pin GP0 connected to ZRx


#Pin GP1 Connected to ZTx
#Switch off 7 in Dip switch S3
#Press SW3 Push Button in Transmitter for Led On in Receiver Trainer.from
machine import UART, Pin
import time
sw =machine.Pin(16,machine.Pin.IN)
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
while True:
a = sw.value()
if(a==1):
uart0.write('1')
else:
uart0.write('0')

Arduino Interface with ZigBee Reciver Program:

//Pin 2 connected to ZTx


//Pin 3 Connected to ZRx
//Led13 On in receiver kit while press sw3 switch in Tranmitter Trainer.
#include "SoftwareSerial.h"
#include<SoftwareSerial.>
int led = 13;
int received = 0;
int i;
//For communicating with zigbee
SoftwareSerial zigbee(2,3);
void setup()
{
Serial.begin(9600);
zigbee.begin(9600);
pinMode(led, OUTPUT);
}
void loop()
{
//check if the data is received
if (zigbee.available() > 0)
{
received = zigbee.read();
//if the data is 0, turn off the LED
if (received == '0')
{
Serial.println("Turning off LED");
digitalWrite(led, LOW);
}
//if the data is 1, turn on the LED
else if (received == '1')
{
Serial.println("Turning on LED");
digitalWrite(led, HIGH);
}
}

RESULT:

Thus, the communication between Arduino and Raspberry Pi using ZigBee wireless medium
is done and the output was verified.
EX.NO:08 SETUP A CLOUD PLATFORM TO LOG THE DATA

Aim:

To setup a Thingspeak cloud platform to log the data.

Apparatus Required:

1. Arduino UNO
2. Arduino IDE 1.8.2 or higher
3. Thingspeak Account
4. Thinhspeak Library
5. Arduino Wifi Shield 101
6. Photocell
7. Temperature Sensor (This example uses a TMP36)
8. 10K Ohm Resistor

Procedure:

Step-1: The first step is to create an account. The good part is that ThingSpeak does not require a
Credit card (like AWS/Azure) for signing up. You may sign up here.
Step-2: After signing up on ThingSpeak, login here.
Step-3: Create a new ThingSpeak channel by clicking on the "New Channel".
Step-4: In the new channel creation screen, fill out the details of the device from which data will be
received.
Step-5: In the new channel creation screen, scroll down further and make this channel public. So that
you can post data to it.
Step-6: After saving the channel, the channel details screen will get displayed (as shown below). Notice
that there will be 5 tabs: Private View, Public View, Channel Settings, API Keys and Data
Import/Export. You are all set! Browse through them to get a feeling of the contents. Make note of the
Channel ID, as you will need it for posting and reading data to ThingSpeak.
Step-7: Now we will see how to log data and read data to and from this channel. Browse to the API
Keys tab for your channel. Note down the read and write api_keys (as shown below), as you will need
it for posting and reading data to ThingSpeak. I have obscured the api keys for my channel intentionally.
Never share your channel api keys with unintented recipients as they might spam the channel
inadvertently.
Step-8: Use the following URL format to log data to ThingSpeak.
https://api.thingspeak.com/update.json?api_key=<your-write-api-key>&field1=58
Upon hitting the above URL, the data '58' will get logged in the ThingSpeak IoT cloud.
Correspondingly, you can also see the logged data in the ThingSpeak channel's Private/Public.
Step-9: Use the following URL format to read the logged data from ThingSpeak.
http://api.thingspeak.com/channels/<your-channel-id>/feeds.json?key=<your-read-api-
key>&results=1
On hitting the above URL in the browser, you will receive the last posted data row from ThingSpeak.

Code:

char ssid[] = "networkssid"; // your network SSID (name) char


pass[] = "password"; // your network password char
thingSpeakAddress[] = "api.thingspeak.com";
String APIKey = "O2JUIN8J6CPPX1AW"; //enter your channel's Write API Key
const int updateThingSpeakInterval = 20 * 1000; // 20 second interval at which to update ThingSpeak float
voltage = analogRead(A1) * (3.3 / 1024); // convert from range 0 - 1023 to 0 - 3.3V
int tempVal = (voltage - 0.5) * 100; // convert to Celsius using offset of 0.5V
String light = String(analogRead(A0),DEC);
String temp = String(tempVal,DEC);
if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval)) {
updateThingSpeak("field1=" + light + "&field2=" + temp);
}

RESULT:

Thus, the IoT cloud platform ThinkSpeak was set up to log the data and the output was

verified.
EX.NO:09 LOG DATA USING RASPBERRY PI AND UPLOAD TO THE CLOUD
PLATFORM

Aim:
To write the python program for Log Temperature Data using Raspberry Pi and upload to
the Cloud Platform.

Apparatus Required:
1. Raspberry Pi
2. PiCo W
3. LM35 Temperature Sensor

Theory:

LM35 sensor uses the basic principle of a diode, whereas the temperature increases, the
voltage across a diode increases at a known rate. By precisely amplifying the voltage change, it is
easy to generate an analog signal that is directly proportional to temperature.

Program:
Import network
import urequests
from time import sleep
import machine
sensor_temp = machine.ADC(26)
#Network Initialization
ssid = "IElec Systems"
password = "9840838264"
def ConnectWiFi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while wlan.isconnected() == False:
print('Waiting for connection...')
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
return ip
#Connect to Network
ip = ConnectWiFi()
#ThingSpeak Initialization
server = "http://api.thingspeak.com/"
apikey = "74085BCYRZG0G9YJ"
field = 1
#Main Program
while True:
temperature = sensor_temp.read_u16()
temperature = ((temperature/65535)*3300)/10
print(temperature)

url = f"{server}/update?api_key={apikey}&field{field}={temperature}"
request = urequests.post(url)
request.close()

sleep(20)

RESULT:

Thus, the data was logged using Raspberry Pi and uploaded to the Cloud Platform.
EX.NO:10 DESIGN AN IOT BASED SYSTEM

Aim:

To write a program to design a Home Automation system using Ardunio and Bluetooth control.

Apparatus Required
1. PIR Motion Sensor (generic)
2. HC-05 Bluetooth Module
3. LDR (Light Dependent Resistor)
4. LED (generic)
5. Arduino UNO
6. Temperature Sensor
7. Relay (generic)
8. Jumper wires (generic)
9. Apps and platforms
10. Arduino IDE
11. Windows 10

Theory:

Configurations for room:

An Arduino UNO will control devices and reads sensor data. The figure "Room
Architecture" depicts how the Arduino UNO will connects with the devices and sensors. Room
have multiple controllable devices (i.e. Light(s), Fan, Wall Socket(s), etc.), one PassiveIR (to
detect human presence in the room), one temperature sensor (LM35 to collect room temperature)
and LDR (to detect light intensity near room window).

PIR:

PIR sensor consists of three pins, ground, signal, and power at the side or bottom.
Generally, the PIR sensor power is up to 5V, but, the large size PIR modules operate a relay instead
of direct output.

Program:

float x,y; //TEMP


#define trigPin 12 //ULTRA
#define echoPin 10
int ledPin= 13;
int duration, distance; //ULTRA
#include<Servo.h> //servo
Servo my; //servo
char val; //bluetooth
void setup() {
Serial.begin(9600);
pinMode(2,INPUT); //IR GATE FIRST
pinMode(3,INPUT);
my.attach(11); //servo
pinMode(4, OUTPUT); //IR GATE FIRST
pinMode(7,OUTPUT); //TEM
pinMode(8,INPUT); //pir 1
pinMode(9,OUTPUT); //LED 1
// pinMode(10,INPUT); //pir 2
//pinMode(11,OUTPUT); //LED2
pinMode(trigPin, OUTPUT); //12 PIN ULTRA
pinMode(echoPin, INPUT); //10 PIN ULTRA
pinMode(ledPin, OUTPUT); //13 PIN ULTRA
pinMode(3,OUTPUT); //bluetooth
}
void loop() {
x=analogRead(0); //TEMP
y=((x/1024)*5)*100;
Serial.println(y);
delay(500);
if(y>44)
{
digitalWrite(7,1);
}
else
{
digitalWrite(7,0);
delay(500);
}
//TEMP

if(digitalRead(8)==HIGH) //pir
{
digitalWrite(9,HIGH);
}
Else
{ digitalWrite(9,LOW);}
digitalWrite(trigPin, HIGH); //ULTRA
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 10 || distance <= 0)
{
// Serial.println("no object detected");
digitalWrite(ledPin,LOW);
}
else
{
Serial.println("object detected \
");
Serial.print("distance= ");
Serial.print(distance);
digitalWrite(ledPin,HIGH);
} //ULTRA
if(digitalRead(2)==HIGH) //gate first
{
my.write(0); //servo
}
Else
{
my.write(90); //servo
}
analogRead(5); //ldr
float a = analogRead(5);
Serial.println(a);
if (a <=200) {
digitalWrite(4,1);
Serial.println("LDR is DARK, LED is ON");
}
else {
digitalWrite(4,0);
Serial.println(" ----- ");
} //ldr
if (Serial.available()) //bluetooth
{
val = Serial.read();
Serial.println(val);
if(val == 'TV')
digitalWrite(3,HIGH);
else if(val == 'tv')
digitalWrite(3,LOW);
} //Bluetooth
}
RESULT:

Thus, the program was written to design a Home Automation system using Ardunio
and Bluetooth control and the output was verified.

You might also like