0% found this document useful (0 votes)
210 views21 pages

Cs3691-Unit 4

Internet of Things
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)
210 views21 pages

Cs3691-Unit 4

Internet of Things
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/ 21

CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

UNIT-4
IOT COMMUNICATION AND OPEN PLATFORMS
PART-A
1)What is Raspberry Pi?
Raspberry Pi is a computer which is capable of doing all the operations like a conventional
computer. It has other features such as onboard WiFi, GPIO pins, and Bluetooth in order to
communicate with external things.

2) How to run Raspberry pi in headless mode?


Raspberry pi in headless mode can be run by using SSH. The latest operating system has an inbuilt
VNC server that is installed for taking remote desktop on Raspberry Pi.

3) List available wireless communications boards available in Raspberry Pi


Wireless communications boards available in Raspberry Pi are

1) WiFi and 2) BLE/Bluetooth.

4) What is Bluetooth Low Energy?


Bluetooth Low Energy is a wireless PAN (Personal Area Network) technology. It uses less power
to transmit long-distance over a short distance.

5) List available models in Raspberry Pi


Models of Raspberry Pi are:

 Raspberry Pi 1 Model B
 Raspberry Pi 1 Model B+
 Raspberry Pi 1 Model A
 Raspberry Pi Zero
 Raspberry Pi 3 Model B
 Raspberry Pi 1model A+
 Raspberry Pi Zero W
 Raspberry Pi 2

Page | 1
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

6) Differentiate between Arduino and Raspberry pi


The difference between Arduino and Raspberry pi is:

S
No. Arduino Raspberry Pi

In the year 2005, the classrooms of


the Interactive Design Institute in In the year 2012, Eben Upton first introduced the
1.
Ivrea, Italy, first introduced the Raspberry Pi device in February.
Arduino board.

Control unit of the Arduino is from The control unit of Raspberry Pi is from the ARM
2.
the Atmega family. family.

Arduino is based on a
3. While Raspberry Pi is based on a microprocessor.
microcontroller.

It is designed to control the electrical While Raspberry Pi computes data and produces
4. components connected to the circuit valuable outputs, and controls components in a
board in a system. system based on the outcome of its computation.

Arduino boards have a simple While Raspberry Pi boards have a complex


5.
hardware and software structure. architecture of hardware and software.

6. CPU architecture: 8 bit. CPU architecture: 64 bit.

7. It uses very little RAM, 2 kB. While Raspberry Pi requires more RAM, 1 GB.

It clocks a processing speed of 16 While Raspberry Pi clocks a processing speed of


8.
MHz. 1.4 GHz.

9. It is cheaper in cost. While Raspberry Pi is expensive.

It has a higher I/O current drive While Raspberry Pi has a lower I/O current drive
10.
strength. strength.

11. It consumes about 200 MW of power. While it consumes about 700 MW of power.

Page | 2
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

S
No. Arduino Raspberry Pi

12. Its logic level is 5V. Its logic level is 3V.

13. It does not have internet support. It has inbuilt Ethernet port and WiFi support.

14. It has higher current drive strength. It has lower current drive strength.

Some of the applications of Arduino Some of the applications of Raspberry Pi are Stop
15. are traffic light countdown timer , motion cameras , Robot Controllers , Game
Weighing machines , etc. Servers.

Operating systems are required in


16. Operating System is required in Raspberry Pi.
Arduino.

17. Two tiny cores Arduino with 32 Mhz Single core and 700 MHz

7) What is Salesforce IoT Cloud?


The Salesforce IoT Cloud is an online platform for storing and processing IoT information.

It is an assortment of various application development elements, which are called lightning.

This program gathers information from websites, devices, customers, and partners. It then triggers
actions for period responses.

8) Explain IoT GE-PREDIX


GE or General Electric Predix is a software for the information assortment from industrial
instruments. It offers a PaaS which allows users performance management and operation
optimization facility. It connects instrumentation, people, and information in an exceedingly
conventional technique.

9) Mention real-time usage of Raspberry pi

 Home a
 Portable webserver
 manipulating the robots
 Internet radio

Page | 3
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

10) What is Zigbee?


Zigbee is the same like Bluetooth. It used in a complex system for low power operation, robustness,
and high security.

11) What is Z-Wave?


Z-Wave is an IoT technology that uses low power RF communication. It is designed for home
automation products like lamp controllers and sensors.

12) What is MQTT?


The full form of MQTT is Message Queue Telemetry Transport Protocol. It is a messaging
protocol that is used for tracking devices in IoT.

13) What are the operating systems supported by Pi?


Operating systems supported by Pi are:

 Raspbian
 Open ELEC (Open Embedded Linux Entertainment center)
 RISC OS
 Lakka
 OSMC (Open Source Media Centre)
 Windows IoT Core

14) What is the difference between M2M and IoT?


M2M IoT

Communication is done within an embedded


Communication is done for grand-scale projects.
software at the client site.

It uses isolated systems of devices having the It uses integrated devices, applications, and data
same standards. across varying standards.

M2M offers limited scalability options. IoT is inherently more scalable.

A cellular network or wired network is used for It uses an active Internet connection for device
device connectivity. connectivity.

Machines can communicate with one machine at Many machines can communicate with each other
a time. over the Internet.

Page | 4
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

15)List the applications of BLE.

i)Wearables

ii)Smart Home devices

iii)Health care appliances

iv)Beacons

16)Define Wi-Fi

Wifi is the short range Wireless communication technique. It is an alternative network to a wired
network which is commonly used to connect the devices in wireless mode.

17)List the types of status LEDs and its functions.


S No Status LED Functions
1 ACT SD Card access
2 PWR 3.3V power is present
3 FDX Full Duplex LAN connected
4 LNK Link/Network connectivity
5 100 100 Mbits LAN connected
18) What is Raspberry Pi? State its importance
Raspberry Pi is defined as a minicomputer the size of a credit card that is interoperable with any
input and output hardware device like a monitor, a television, a mouse, or a keyboard –
effectively converting the set-up into a full-fledged PC at a low cost.
19)What is Subscriber?
The Publish-subscribe pattern is a messaging pattern that decouples the clients that send
messages (publishers) from the clients that receive messages (subscribers) by allowing them to
communicate without having direct connections or knowledge of each other's existence

Page | 5
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

PART-B

1) Explain in detail about IOT Communication API’s.

IoT Communications APIs are a set of protocols and interfaces that allow IoT devices and
platforms to communicate with one another. Internet of Things Communications APIs
standardizes how IoT devices communicate with one another and with other systems. They enable
developers to design applications and services that can access and operate IoT devices without
worrying about underlying communication protocols and interfaces.

Benefits of Communication APIs in IoT

There are multiple benefits to adopting Internet of Things Communications APIs. One of the
primary benefits is that they give a standardized method of connecting with IoT devices, making
it simpler for developers to construct apps and services that work with many types of devices. This
can save developers a lot of time and effort because they don't have to establish specific
communication protocols for each device with which they want to interact.

Another benefit of adopting Communications APIs is that they might make the development
process easier. Developers can utilize high−level APIs that abstract away the specifics of
communication protocols and interfaces instead of writing low−level code to handle
communication with IoT devices. This can assist minimize the amount of code required and make
it easier to construct reliable and scalable systems.

IoT Communications APIs can also aid in the enhancement of security. APIs may ensure that
devices communicate securely and that data is encrypted and secured from unauthorized access by
offering a standardized communication method with IoT devices. This can aid in the prevention
of data breaches and other security issues.

Internet of Things Communications APIs are also built to be extremely scalable. As more devices
are added to an IoT system, the APIs can handle the increasing traffic while also ensuring that
device communication stays reliable and consistent.

Page | 6
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

Another advantage of adopting communications APIs is that they make the building of IoT
applications easier. Developers can utilize pre−built APIs to connect their apps to IoT devices and
platforms, saving time and reducing development complexity.

Types of Communication APIs in IoT

Generally we used Two APIs For IoT Communication. These IoT Communication APIs are:

a) REST-based Communication APIs


b) WebSocket-based Communication APIs
a) REST based Communicattion APIs:
Representational state transfer (REST) is a set of architectural principles by which you
can design Web services the Web APIs that focus on systems’s resources and how
resource states are addressed and transferred. REST APIs that follow the request
response communication model, the rest architectural constraint apply to the
components, connector and data elements, within a distributed hypermedia
system. The rest architectural constraint are as follows:

i) Client-server – The principle behind the client-server constraint is the separation of


concerns. for example clients should not be concerned with the storage of data which is
concern of the serve. Similarly the server should not be concerned about the user interface,
which is concern of the clien. Separation allows client and server to be independently
developed and updated.
ii) Stateless – Each request from client to server must contain all the information necessary to
understand the request, and cannot take advantage of any stored context on the server. The
session state is kept entirely on the client.
iii) Cache-able – Cache constraints requires that the data within a response to a request be
implicitly or explicitly leveled as cache-able or non cache-able. If a response is cache-able,
then a client cache is given the right to reuse that repsonse data for later, equivalent requests.
caching can partially or completely eliminate some instructions and improve efficiency and
scalability.
iv) Layered system – layered system constraints, constrains the behavior of components such
that each component cannot see beyond the immediate layer with they are interacting. For
example, the client cannot tell whether it is connected directly to the end server or two an
intermediaryalong the way. System scalability can be improved by allowing intermediaries to
respond to requests instead of the end server, without the client having to do anything different.
v) Uniform interface – uniform interface constraints requires that the method of
communication between client and server must be uniform. Resources are identified in the
requests (by URIsin web based systems) and are themselves is separate from the
representations of the resources data returned to the client. When a client holds a representation
of resources it has all the information required to update or delete the resource you (provided
the client has required permissions). Each message includes enough information to describe
how to process the message.
vi) Code on demand – Servers can provide executable code or scripts for clients to execute
in their context. this constraint is the only one that is optional.

Page | 7
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

A RESTful web service is a ” Web API ” implemented using HTTP and REST principles.
REST is most popular IoT Communication APIs.

b) WebSocket based Communication APIs

Websocket APIs allow bi-directional, full duplex communication between clients and servers.
Websocket APIs follow the exclusive pair communication model. Unlike request-response model
such as REST, the WebSocket APIs allow full duplex communication and do not require new
coonection to be setup for each message to be sent. Websocket communication begins with a
connection setup request sent by the client to the server. The request (called websocket handshake)
is sent over HTTP and the server interprets it is an upgrade request. If the server supports
websocket protocol, the server responds to the websocket handshake response. After the
connection setup client and server can send data/mesages to each other in full duplex mode.
Websocket API reduce the network traffic and letency as there is no overhead for connection setup
and termination requests for each message. Websocket suitable for IoT applications that have low
latency or high throughput requirements. So Web socket is most suitable IoT Communication APIs
for IoT System.

Page | 8
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

2.Explain about Bluetooth technology.


The IoT Data Link communication protocol provides service to the Network Layer. There are
various protocols and standard technologies specified by the different organization for data link
protocols.

Bluetooth
Bluetooth is a short-range wireless communication network over a radio frequency. Bluetooth is
mostly integrated into smartphones and mobile devices. The Bluetooth communication network
works within 2.4 ISM band frequencies with data rate up to 3Mbps.
What is Bluetooth In IoT

Bluetooth has become a household name in the Internet of Things (IoT) community, offering more
than just hands-free calling and wireless audio. It is a serious technology that drives IoT
applications, providing fast and seamless device-to-device connections without relying on the
Internet. Since a device-to-device connection is expected to be fast, seamless, and wireless in the
Internet of Things, Bluetooth IoT is highly deployed because of its no-internet function on the one
hand and its capability to create large-scale device networks via Bluetooth mesh, on the other hand.
Bluetooth technology in IoT opens up numerous possibilities.

Bluetooth Mesh Networking

Bluetooth mesh IoT is a computer mesh networking system based on Bluetooth Low Energy
(BLE) that allows for many-to-many communication among connected devices over a Bluetooth
radio. In a Bluetooth mesh IoT network, every message has a source and destination address
through which devices publish messages to their destinations, which is a single thing, group of
things, or everything.

Bluetooth mesh IoT networking is a game-changer for wireless device networks. It is no surprise
that it sets a stage for a new wave of connectivity from whole-building networks to city-wide smart
services, especially in the present era of home, building, community, and industrial automation.

Page | 9
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

There are three categories of Bluetooth technology:

Bluetooth Classic
Bluetooth Low Energy
Bluetooth SmartReady
The features of Bluetooth 5.0 version is introduced as Bluetooth 5 which have been developed
entirely for the Internet of Things.
Properties of Bluetooth network:
o Standard: Bluetooth 4.2
o Frequency: 2.4GHz
o Range: 50-150m
o Data transfer rates: 3Mbps

Advantages of Bluetooth network:


o It is wireless.
o It is cheap.
o It is easy to install.
o It is free to use if the device is installed with it.

Page | 10
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

Disadvantages of Bluetooth network


o It is a short-range communication network.
o It connects only two devices at a time.

3.Explain how Zigbee is interfaced with IOT.

ZigBee is a low power, low data rate wireless personal area network communication protocol. It
is mostly used in home automation and industrial settings. Since ZigBee is a low power
communication protocol, the IoT power devices used with ZigBee technology. The ZigBee
communication protocol is based on the IEEE 802.15.4 standard operating at the 2.4GHz
frequency. The ZigBee protocol supports star, cluster or wireless mesh technology topology.

ZigBee uses the following devices in its network:

o Zigbee Coordinator
o Zigbee End Device
o Zigbee Router

Properties of ZigBee protocol


o Standard: ZigBee 3.0 based on IEEE802.15.4
o Frequency: 2.4GHz
o Range: 10-100m
o Data transfer rate: 250kbps

Page | 11
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

Advantages of ZigBee protocol


o Wireless
o Mesh networking
o Direct communication
o Low power consumption

Disadvantages of ZigBee protocol


o Costly
o Works with low speed within a small distance

Application of ZigBee protocol


o Commercial and residential control
o Personal and healthcare
o Home networking
o Industrial control and management
o Consumer electronics

4.Explain about Wi-Fi.


Wi-Fi stands for Wireless Fidelity or Frequencies, which allows multiple computers to
communicate and provides a means to connect to the Internet from the access point to the computer
or laptop. Wi-Fi networking technology combines and transmits data and information between
devices using different bands of radio waves. Wi-Fi is a widely used technology in today's
smartphones and PCs.

Working of Wi-Fi:

Page | 12
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

Like a mobile phone, a Wi-Fi network uses Radio Waves to send data across a network. The
computer should include a wireless adaptor that converts data transferred to a radio signal. The
identical signals deliver to a router decoder through an Antenna. After decoding, the data is sent
to the Internet over a connected Ethernet connection.

Because the wireless network is bidirectional, data from the Internet will also transit via the router
and coded into a radio signal that the computer's wireless adapter will receive.

Types of Wi-Fi Connections:


Router
Nowadays, most houses are using the Internet using a wireless router.
The benefits include:
Ease of installation.
Mobility within range of the Wi-Fi access point (router).
The ability to connect numerous devices.
Disadvantages:
Limited capacity and decreased performance as more devices join the same Wi-Fi network and
potential interference from other electromagnetic devices in the home.
Wi-Fi In IoT:
Because Wi-Fi is so vulnerable to malicious assaults, a microchip is required for connectivity
between devices in the IoT and robust firmware to maintain the device's Wi-Fi credentials.
Wi-Fi-enabled IoT devices are frequently massive immovable hubs. There are, however, smaller
gadgets that are Wi-Fi capable. If we want to use Wi-Fi, the Wi-Fi IoT device must be reasonably
close to the Wi-Fi access point.
5. Explain briefly about the various communication models available in IOT with neat
diagram.
IoT devices are found everywhere and it is important and useful to understand how various IoT
devices communicate with each other. The IoTs allow people and things to be connected any
time, any space, with anything and anyone, using any network and any service.

Page | 13
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

Types of Communication Model :

1. Request & Response Model :


This model follows a client-server architecture.
 It is a communication model in which the client sends request to the server and the server
responds to the request
 When the server receives a request, it decides how to respond, fetches the data, retrieve
resource representation, prepares the response and send the response to the client.
 It is an example of stateless communication model
 The client, when required, requests the information from the server. This request is usually
in the encoded format.
 This model is stateless since the data between the requests is not retained and each request
is independently handled.
 The server Categories the request, and fetches the data from the database and its resource
representation. This data is converted to response and is transferred in an encoded format to
the client. The client, in turn, receives the response.
 On the other hand — In Request-Response communication model client sends a request to
the server and the server responds to the request. When the server receives the request it
decides how to respond, fetches the data retrieves resources, and prepares the response, and
sends it to the client.

2. Publisher-Subscriber Model :
This model comprises three entities: Publishers, Brokers, and Consumers.
 Publishers are the source of data. It sends the data to the topic which are managed by the
broker. They are not aware of consumers.
 Consumers subscribe to the topics which are managed by the broker.
 Hence, Brokers responsibility is to accept data from publishers and send it to the appropriate
consumers. The broker only has the information regarding the consumer to which a particular
topic belongs to which the publisher is unaware of.

Page | 14
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

3. Push-Pull Model :
The push-pull model constitutes data publishers, data consumers, and data queues.
 Publishers and Consumers are not aware of each other.
 Publishers publish the message/data and push it into the queue. The consumers, present on
the other side, pull the data out of the queue. Thus, the queue acts as the buffer for the
message when the difference occurs in the rate of push or pull of data on the side of a
publisher and consumer.
 Queues help in decoupling the messaging between the producer and consumer. Queues also
act as a buffer which helps in situations where there is a mismatch between the rate at which
the producers push the data and consumers pull the data.

4. Exclusive Pair :
 Exclusive Pair is the bi-directional model, including full-duplex communication among
client and server. The connection is constant and remains open till the client sends a request
to close the connection.
 The Server has the record of all the connections which has been opened.
 This is a state-full connection model and the server is aware of all open connections.

Page | 15
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

 WebSocket based communication API is fully based on this model.

The main entities in an exclusive pair model are client and server. The client and server establish
a full duplex connection for sending and receiving data. Before sending a request, the client
establishes a connection with the server and then sends the request.

The data requests can be one or more. The server receives these requests through the same
connection and sends back responses. After the data transfer is complete, the connection between
the client and server is terminated. Unlike publish-subscribe model, exclusive pair model is
stateful. So, the server can automatically identify that the request is coming from a previous client
or not.

6) Explain how the components/peripherals are labeled in Raspberry pi.


The various components/peripherals present in Raspberry pi are as follows
1. Central Processing Unit (CPU)
Every computer has a Central Processing Unit, and so does the Raspberry Pi. It is the computer’s
brain and carries out instructions using logical and mathematical operations. Raspberry Pi makes
use of the ARM11 series processor on its boards.

2. HDMI port
Raspberry Pi board has an HDMI or High Definition Multimedia Interface port that allows the
device to have video options of the output from the computer displayed. An HDMI cable

Page | 16
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

connects the Raspberry Pi to an HDTV. The supported versions include 1.3 and 1.3. It also comes
with an RCA port for other display options.

3. Graphic Processing Unit (GPU)


This unit, GPU or Graphic Processing Unit, is another part of the Raspberry pi board. Its primary
purpose is to hasten the speed of image calculations.

4. Memory (RAM)
Random Access Memory is a core part of a computer’s processing system. It is where real-time
information is stored for easy access. The initial Raspberry Pi had 256MB RAM. Over the years,
developers gradually and significantly improved the size. Different Raspberry Pi models come
with varying capacities. The model with the maximum capacity presently is the Raspberry Pi 4
with 8GB RAM space.

5. Ethernet port
The Ethernet port is a connectivity hardware feature available on B models of Raspberry Pi. The
Ethernet port enables wired internet access to the minicomputer. Without it, software updates,
web surfing, etc., would not be possible using the Raspberry Pi. The Ethernet port found on
Raspberry computers uses the RJ45 Ethernet jack. With this component, Raspberry Pi can
connect to routers and other devices.

6. SD card slot
Like most other regular computers, Raspberry Pi must have some sort of storage device.
However, unlike conventional PCs, it does not come with a hard drive, nor does it come with a
memory card. The Raspberry Pi board has a Secure Digital card or SD card slot where users
must insert SD cards for the computer to function. The SD card functions like a hard drive as it
contains the operating system necessary for turning the system on. It also serves to store data.

7. General Purpose Input and Output (GPIO) pins


These are upward projecting pins in a cluster on one side of the board. The oldest models of the
Raspberry Pi had 26 pins, but most have 40 GPIO pins. These pins are pretty sensitive and should
be handled carefully. They are essential parts of the Raspberry Pi device as they add to its diverse
applications. GPIO pins are used to interact with other electronic circuits. They can read and
control the electric signals from other boards or devices based on how the user programs them.

Page | 17
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

8. LEDs
These are a group of five light-emitting diodes. They signal the user on the present status of the
Raspberry Pi unit. Their function covers:

PWR (Red): This functions solely to indicate power status. When the unit is on, it emits a red
light and only goes off when the unit is switched off, or disconnected from the power source.
ACT (Green): This flashes to indicate any form of SD card activity.
LNK (Orange): LNK LED gives off an orange light to signify that active Ethernet connectivity
has been established.
100 (Orange): This light comes on during Ethernet connection when the data speed reaches
100Mbps.
FDX (Orange): FDX light also comes during Ethernet connection. It shows that the connection
is a full-duplex.
9. USB ports
Universal service bus (USB) ports are a principal part of Raspberry Pi. They allow the computer
to connect to a keyboard, mouse, hard drives, etc. The first model of Raspberry Pi had only two
USB 2.0 ports. Subsequent models increased this number to four. Raspberry Pi 4 and Pi 400,
much newer models, come with a mix of USB 2.0 and USB 3.0 ports.

10. Power source


Raspberry Pi has a power source connector that typically uses a 5V micro USB power cable. The
amount of electricity any Raspberry Pi consumes depends on what it’s used for and the number
of peripheral hardware devices connected.
7) Explain how a light sensor(LED) is interfaced with Raspberry Pi.
The light-dependent resistor (LDR) sensor is used to detect the intensity of light in the
surroundings. The LDR is a device constructed from a sensitive semiconductor material i.e.
cadmium sulfide, which undergoes a dramatic shift in electrical resistance when exposed to light,
going from several 1000 Ohms in the dark to just a few Ohms, when illuminated.

Page | 18
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

This simple circuit for detecting light consists of a relay activated by exposure to sunlight.
The photoresistor LDR and the resistor R1 make up a potential divider circuit. In the absence of
light, the LDR's resistance rises into the Megaohm (M) range, and as a result, the transistor TR1
receives zero base bias, turning the relay off. The LDR's resistance drops in response to more light,
elevating the base bias voltage at V1. When the base bias voltage of transistor TR1 reaches a
certain threshold, as defined by the resistance R1 in a potential divider network, the transistor turns
"ON," activating the relay, which controls some external circuitry. With a return to darkness, the
LDR's resistance rises, reducing the transistor's base voltage and turning "OFF" the transistor and
relay at a predetermined level of illumination established by the potentiometer circuit.

Changing the relay's "ON" or "OFF" point to a custom brightness is as simple as swapping out the
fixed resistor R1 for a potentiometer VR1. The switching end of a simple circuit like the one
depicted above may need to be more consistent owing to fluctuations in temperature or supply
voltage. Using the LDR in a "Wheatstone Bridge" configuration and substituting an Operational
Amplifier for the transistor makes it simple to construct a light-activated circuit with increased
sensitivity.
Circuit Diagram of LDR with Raspberry pi:

Page | 19
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

i) To begin, attach Pin1 of Raspberry pi to the breadboard's positive rail.


ii) Then, attach pin 6 of Raspberry pi to the breadboard's ground rail.
iii) Next, place the LDR sensor on the board with one end connected to the power
supply's positive rail.
iv) Connect the opposite end of the LDR sensor to the Pin4 of Raspberry pi using
a jumper wire.
8) Construct a python program for switching LED base on reading LDR reading
# Example code Interfacing a light Sensor (LDR) with Raspberry Pi

import RPi.GPIO as GPIO


import time

GPIO.setmode(GPIO.BCM)
ldr_threshold = 1000
LDR_PIN = 18
LIGHT_PIN = 25

def readLDR(PIN):
reading = 0
GPIO.setup(LIGHT_PIN, GPIO.OUT)

Page | 20
CS3691-Embedded Systems and IOT Prepared by: E U Iniyan,AP/ECE

GPIO.output(PIN, false)
time.sleep(0.1)
GPIO.setup(PIN, GPIO.IN)
while (GPIO.input (PIN) ==Flase):

reading=reading+1

return reading

def switchOnLight(PIN):
GPIO.setup(PIN, GPIO.OUT)
GPIO.output(PIN, True)

def switchOffLight(PIN):
GPIO.setup(PIN, GPIO.OUT)
GPIO.output(PIN, False)
while True:
ldr_reading = readLDR(LDR_PIN)
if ldr_reading < ldr_threshold:
switchOnLight (LIGHT_PIN)
else:
switchOffLight(LIGHT_PIN)
time.sleep(1)

Page | 21

You might also like