Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

UNIT – I

FUNDAMENTALS OF IoT
PART – A
1. What is an IoT?
Internet of Things (IoT) is a network of physical objects or people called "things" that
are embedded with software, electronics, network, and sensors that allows these objects
to collect and exchange data.
The goal of an IoT is to extend to internet connectivity from standard devices like
computer, mobile, tablet to relatively dumb devices like a toaster.

2. Illustrate the evolutionary trend towards building an IoT.

3. List the Four Pillars of an IOT.


 RFID – Radio-frequency identification.
 WSN – Wireless Sensor Network.
 M2M – Machine-to-Machine.
 SCADA – Supervisory Control and Data Acquisition.

4. What are the Challenges of an IoT.


At present IoT is faced with many challenges, such as:
 Insufficient testing and updating
 Concern regarding data security and privacy
 Software complexity
 Data volumes and interpretation
 Integration with AI and automation
 Devices require a constant power supply which is difficult
 Interaction and short-range communication

5. Summarize the benefits of an IoT.


Technical Optimization: IoT technology helps a lot in improving technologies and
making them better.
Example, with IoT, a manufacturer is able to collect data from various car sensors. The
manufacturer analyzes them to improve its design and make them more efficient.

1
Improved Data Collection: Traditional data collection has its limitations and its design
for passive use. IoT facilitates immediate action on data.
Reduced Waste: IoT offers real-time information leading to effective decision making &
management of resources.
Improved Customer Engagement: IoT allows to improve customer experience by
detecting problems and improving the process.

6. What are the disadvantages of an IoT?


 Security: IoT technology creates an ecosystem of connected devices. However,
during this process, the system may offer little authentication control despite sufficient
security measures.
 Privacy: The use of IOT, exposes a substantial amount of personal data, in extreme
detail, without the user's active participation. This creates lots of privacy issues.
 Flexibility: There is a huge concern regarding the flexibility of an IoT system. It is
mainly regarding integrating with another system as there are many diverse systems
involved in the process.
 Complexity: The design of the IOT system is also quite complicated. Moreover, it's
deployment and maintenance also not very easy.
 Compliance: IOT has its own set of rules and regulations. However, because of its
complexity, the task of compliance is quite challenging.

7. List the characteristics of an IoT.


 Connectivity
 Things
 Data
 Communication
 Intelligence
 Action
 Ecosystem

8. Highlight the applications of an IoT.


 Smart home
 Wearables
 Smart City
 Smart grids
 Industrial internet
 Connected car
 Connected Health (Digital health/Tele health/Telemedicine)
 Smart retail
 Smart supply chain
 Smart farming

9. Summarize the technologies of IoT.


 Hardware (Device)
 Communication Technology
 Protocols for IoT
 Software (IDE)
 Cloud Platforms.
2
10. Summarize the IOT enabling technologies.
 Wireless Sensor Network
 Cloud Computing
 Big Data Analytics
 Embedded Systems

11. How do IoT devices communicate with each other?


 An IoT device is connected through an IP network to the internet. The devices
connect to the net either through Ethernet — wired or wireless — or Bluetooth.

12. What is the Future of IoT Technology?


 The applications of IoT looks promising in the years ahead. IoT technologies will
likely be used with other technological trends like artificial intelligence (AI) and
automated things to deliver integrated smart solutions. The integration of
technologies will create disruptions in different industries driving new
opportunities.

13. What is an IoT gateway?


 An internet of things (IoT) gateway is a physical device or software program
 It serves the connection point between the cloud and controllers, sensors and
intelligent devices.
 All data moving between IoT devices and the cloud passes through an IoT gateway,
which can be either a dedicated hardware appliance or software program.
 An IoT gateway might also be referred to as an intelligent gateway or a control tier.

14. What are the hardware and software components of an IoT?


IoT hardware involved all of the tangible devices that are involved with the collection and
flow of data within an IoT ecosystem. On the other hand, the software is executing
programs on IoT hardware, ensuring that data is properly processed, contextualized,
standardized, visualized, analyzed, etc.
IoT Hardware IoT Software
IoT Sensors Data Collection
Edge Devices Standardization
Mobile Devices Contextualization
PLCs Analytics
Actuators Visualization

15. What is Transducer?


 A transducer converts a signal from one physical structure to another.
 It converts one type of energy into another type.
 It might be used as actuators in various systems.

16. Point out the advantages of Raspberry Pi over Arduino

Raspberry Pi Arduino
Multitasking and suitable for complex Runs one program at a time, used for
projects repetitive work
Suitable for software projects Suitable for hardware projects
3
No limiting to programming language Limited to Arduini, C/C++
Need to connect external hardware and
Built-in Ethernet port for networking
implement coding
Act as a server and communicate to other Excels in controlling small devices like
computers, connected devices. sensors, motors, and lights

PART – B & C

1. Explain the Characteristics of an IoT in detail.

Connectivity
Connectivity is an important requirement of the IoT infrastructure. Things of IoT should
be connected to the IoT infrastructure. Anyone, anywhere, anytime can connect, this
should be guaranteed at all times.
For example, connection between people through internet devices like mobile phones
and other gadgets, also connection between Internet devices such as routers, gateways,
sensors, etc.
Intelligence and Identity
The extraction of knowledge from the generated data is very important. For example, a
sensor generates data, but that data will only be useful if it is interpreted properly. Each
IoT device has a unique identity. This identification is helpful in tracking the equipment
and at times for querying its status.
Scalability
The number of elements connected to the IoT zone is increasing day by day. Hence, an
IoT setup should be capable of handling the massive expansion. The data generated as
an outcome is enormous, and it should be handled appropriately.
Dynamic and Self-Adapting (Complexity)
IoT devices should dynamically adapt themselves to the changing contexts and
scenarios. Assume a camera meant for the surveillance. It should be adaptable to work
in different conditions and different light situations (morning, afternoon, night).
Architecture
IoT architecture cannot be homogeneous in nature. It should be hybrid, supporting
different manufacturers ‘products to function in the IoT network. IoT is not owned by
anyone engineering branch. IoT is a reality when multiple domains come together.
Safety
There is a danger of the sensitive personal details of the users getting compromised
when all their devices are connected to the internet. This can cause a loss to the user.
Hence, data security is the major challenge. Besides, the equipment involved is huge.
IoT networks may also be at the risk. Therefore, equipment safety is also critical.
Self-Configuring
This is one of the most important characteristics of IoT. IoT devices are able to upgrade
their software in accordance with requirements with a minimum of user participation.
Additionally, they can set up the network, allowing for the addition of new devices to an
already-existing network.

4
2. Describe an IoT architecture in detail.

IoT architecture refers to the tangle of components such as sensors, actuators,


cloud services, Protocols, and layers that make up IoT networking systems. In
general, it is divided into layers that allow administrators to evaluate, monitor, and
maintain the integrity of the system.

Different Layers of IoT Architecture

Perception/Sensing Layer
The first layer of any IoT system involves “things” or endpoint devices that serve
as a conduit between the physical and the digital worlds. Perception refers to the
physical layer, which includes sensors and actuators that are capable of
collecting, accepting, and processing data over the network. Sensors and
actuators can be connected either wirelessly or via wired connections. The
architecture does not limit the scope of its components nor their location.
Network Layer
Network layers provide an overview of how data is moved throughout the
application. This layer contains Data Acquiring Systems (DAS) and
Internet/Network gateways. A DAS performs data aggregation and conversion
functions (collecting and aggregating data from sensors, then converting analog
data to digital data, etc.). It is necessary to transmit and process the data collected
by the sensor devices. That’s what the network layer does. It allows these devices
to connect and communicate with other servers, smart devices, and network
devices. As well, it handles all data transmissions for the devices.
Processing Layer
The processing layer is the brain of the IoT ecosystem. Typically, data is
analyzed, pre-processed, and stored here before being sent to the data center,
where it is accessed by software applications that both monitor and manage the
5
data as well as prepare further actions. This is where Edge IT or edge analytics
enters the picture.
Application Layer
User interaction takes place at the application layer, which delivers application-
specific services to the user. An example might be a smart home application
where users can turn on a coffee maker by tapping a button in an app or a
dashboard that shows the status of the devices in a system. There are many ways
in which the Internet of Things can be deployed such as smart cities, smart
homes, and smart health.

Stages of an IoT

The IoT Architecture generally comprises of these 4 stages:

Stage 1 (Sensors/Actuators)
Sensors are used to collect the data from the environment and help in turning that data
into meaningful information that can be further used for the analysis.
The role of actuators helps in studying the change that is recorded by the sensors. It is
one of the most basic steps that deals with establishing all the physical devices that can
capture the data.
The sensors and the actuators carry out the sensing and actuating process.
Stage 2 (Data Acquisition Systems)
The data which is captured by the sensors and actuators is in analog form, and to
change this analog data into digital data, we need to have a mechanism in place. To
work out on this process, the internet gateway is used. With the use of Data Acquisition
Systems, the analog data can be converted into a digital system and form. It helps in
aggregation and conversion functions.
Stage 3 (Edge Analytics)
The stage deals with the preprocessing and pre analytics of the data before sending it
into the actual systems. The edge IT system will be located at the sensors’ actual site
and the actuators, not located far from the actual data centers.
The data captured by the sensors and actuators are not always important for the
organization; hence only the required data is processed and sent to the server and the
data centers.
Stage 4 (Cloud Analytics)
Once the data is done with the preprocessing and the analysis, and all the loopholes are
removed from the data, the processed data is sent to the data centers and the servers

6
that can be used for the final analysis and reporting purposes. The data can be sent to
the physical servers or the data centers that are placed away from the sensors and
actuators, possibly very far away from these two. The data can be analyzed and sent for
the final processing either to cloud-based servers or data centers, or physical servers.
The processing and analysis can be in-depth in nature regardless of the platform,
whether physical or cloud-based. The cloud platform helps in reducing the hardware
cost, but at the same time, data security is also concern.

3. How IoT works? Explain in detail.

Working of IoT

Here, are four fundamental components of an IoT system:

Sensors/Devices: Sensors or devices are a key component that helps to collect live
data from the surrounding environment. All this data may have various levels of
complexities. It could be a simple temperature monitoring sensor, or it may be in the form
of the video feed.

A device may have various types of sensors which performs multiple tasks apart from
sensing.
Example: A mobile phone is a device which has multiple sensors like GPS, camera but
our smartphone is not able to sense these things.

Connectivity:
 An internet of things (IoT) gateway is a physical device or software program
 It serves the connection point between the cloud and controllers, sensors and
intelligent devices.
 All data moving between IoT devices and the cloud passes through an IoT gateway,
which can be either a dedicated hardware appliance or software program
 All the collected data is sent to a cloud infrastructure.
 The sensors should be connected to the cloud using various mediums of
communications. These communication mediums include mobile or satellite networks,
Bluetooth, WI-FI, WAN, etc.

Data Processing: Once that data is collected, and it gets to the cloud, the software
performs processing on the gathered data. This process can be just checking the
temperature, reading on devices like AC or heaters. However, it can sometimes also be
very complex like identifying objects, using computer vision on video.

7
User Interface: The information needs to be available to the end-user in some way
which can be achieved by triggering alarms on their phones or sending them notification
through email or text message. The user sometimes might need an interface which
actively checks their IOT system.
For example, the user has a camera installed in his home. He wants to access video
recording and all the feeds with the help of a web server.

However, it's not always one-way communication. Depending on the IoT application and
complexity of the system, the user may also be able to perform an action which may
create cascading effects.

For example, if a user detects any changes in the temperature of the refrigerator, with the
help of IOT technology the user should able to adjust the temperature with the help of
their mobile phone

4. Write about the IoT enabling technologies.

IoT is enabled by several technologies which includes


 Wireless Sensor Network
 Cloud Computing
 Big Data Analytics
 Embedded Systems
Wireless Sensor Network
Distributed Devices with sensors used to monitor the environmental and physical
conditions
Example
 Weather monitoring system
 Indoor Air quality monitoring system
 Soil moisture monitoring system
 Surveillance systems
 Health monitoring systems
Protocols
 Zigbee
 Consists of several end-nodes acting as routers or coordinators too
 Coordinators collects data from all nodes / acts as gateway that connects WSN
to internet
 Routers route the data packets from end nodes to coordinators
Cloud Computing
 Deliver applications and services over internet
 Provides computing, networking and storage resources on demand
 Cloud computing performs services such as Iaas, Paas and Saas
 Iaas : Rent Infrastructure
 Paas : supply an on-demand environment for developing, testing, delivering and
managing software applications.
 Saas : method for delivering software applications over the Internet, on demand
and typically on a subscription basis.

8
Big Data Analytics
Collection of data whose volume, velocity or variety is too large and difficult to store,
manage, process and analyse the data using traditional databases.
It involves data cleansing, processing and visualization
Lots of data is being collected and warehoused
 Web data, e-commerce
 purchases at department/ grocery stores
 Bank/Credit Card transactions
 Social Network
Variety Includes different types of data
 Structured
 Unstructured
 Semi Structured
 All of above
Velocity Refers to speed at which data is processed
 Batch
 Real-time
 Streams
Volume refers to the amount of data
 Terabyte
 Records
 Transactions
 Files
 Tables
 Embedded systems:
Embedded system
Embedded system is a combination of hardware and software system used to perform
special tasks.
Embedded system includes microcontroller or microprocessor, memory (RAM, ROM),
networking unit, input / output units and storage. It collects the data analyse and sends
the data to internet.

5. What do you mean by things in IoT? Explain in detail.

The Internet of Things (IoT) describes the network of physical objects —“things”— that
are embedded with sensors, software and other technologies for the purpose of
connecting and exchanging data with other devices and systems over the internet.

The objects are classified into


 Smart Objects.
 Non-Smart Objects.
Smart Object
Smart objects are those physical and digital objects which can be identified,
have sensing/actuating capabilities, processing and calculating powers, also
storing, and networking capabilities

9
Features of Smart Object

Example
Smartphones. Smart fridge, Smart TV, Alexa voice assistant, Micro-controllers.
Non-Smart Objects
Non-smart objects are generally those objects which do not have intelligence
and processing capabilities. Sensors and actuators are non-smart devices.
Sensors
Sensors are those electronic devices which are made of sensitive cells and have
capabilities to measure or sense some physical or scientific quantity like
temperature, pressure, the measure of any toxic gas, etc.
Actuators
Actuators are those electronic devices which perform a specific task by collecting
the information by sensors or like sensors over the internet. We can divide
actuator into two parts

6. What is an IoT Sensor? Explain in detail.

A sensor is a device that detects the change in the environment and responds to
some output on the other system. A sensor converts a physical phenomenon into a
measurable analog voltage (or sometimes a digital signal) converted into a human-
readable display or transmitted for reading or further processing.
IoT sensor data is the data collected by devices found in the Internet of Things
(IoT). These devices can be anything from a thermostat in a device to a car. The internet
part of IoT means that these devices can connect, collect, and send data across
networks where it can be analyzed and acted upon.

10
Sensor data can vary and multiple devices collect different types of data. Devices can
measure anything from temperature, numbers of individuals in a room, activity levels,
and how much water is in the soil.
Sensor Classification
Passive Sensor – It cannot independently sense the input. Ex- Accelerometer, soil
moisture, water level and temperature sensors.
Active Sensor – Independently sense the input. Example- Radar, sounder and laser
altimeter sensors.
Analog Sensor – Analog sensors are those which produce an analog signal based on
what they sense. Example - Light sensors (LDRs), sound sensors, pressure sensors,
and analog temperature sensors.
Digital Sensor – Digital sensors produce digital signals when performing a
measurement. Example – Passive infrared (PIR) sensor and digital temperature
sensor.
Scalar Sensor – The sensor which produce output signal/voltage which is proportional
to magnitude of quantity to be measured is known as scalar sensor.
Example – Temperature sensor, Color sensor, pressure sensor, strain sensor etc.
Vector Sensor – The sensor which produce output signal/voltage which is proportional
to magnitude, direction as well as orientation of quantity being measured is known as
Vector sensor.
Example – Sound sensor, image sensor, velocity sensor, acceleration sensor etc
Sensor Characteristics
When choosing sensors for our IoT platform, there are five characteristics we should
consider.
Accuracy - Accuracy is the ability of a sensor to provide a true measurement of
whatever the sensor is monitoring. There is an uncertainty with the measurement, usually
represented as a percentage of full scale.
Repeatability - Repeatability is the ability of a sensor to provide a constant output when
there is a constant input, when acquiring a new sample.
Linearity - Linearity is a measure of how well the sensor’s response curve approaches a
straight line.
Sensitivity - A sensor’s sensitivity is the amount the input to the sensor must change to
detect any change in the output.
Environmental Impact - Changes in the environment can impact the performance and
accuracy of a sensor. For example, some sensors are particularly sensitive to
temperature and humidity.

7. What do you know about IoT Hardware? Explain in detail.

The set of devices that respond and have the capabilities to capture data, follow the
instructions can be considered as the IoT Hardware. The following fall into such
categories where they not only collect data but also respond to instructions based on the
processed data.

Chips: This is much a broader classification that contains all the electrical and electronic
appliances such as microcontrollers, chips, integrated circuits, radio frequency systems,
etc.

11
Sensors: Sensors, which are one of the base components of an IoT system, have three
modules - Power Management modules, Sensing modules, and Energy modules.
Actuators: These devices provide the motion to a data collection system such as the
solenoids, comb drives, etc to fetch details based on movements.
Standard devices: Standard devices constitute the generally used devices such as
Tablets, Smartphones, Switches, Routers and etc. Each of these devices has its own set
of settings that allow them to collect data.

Types of IoT Hardware: Microcontroller vs. Single-Board Computers


 A microcontroller is a special type of computer with the primary focus of accessing and
interacting with other hardware.
 Memory is limited, usually less than 1MB, E.g. ATMega328 the Arduino
microcontroller has 2KB.
 Storage is in flash, also small, for the ATMega328 is 32KB
 Electronic interfaces like IIC or SPI or UART to use peripherals, only a few
include native support for USB and generally 2.0 or 1.1
 NO extra components, just the micro, our need a regulator, a PCB and more to
make it work.
 An Arduino is a microcontroller, a board designed to interface external sensors and
provides no operating system.

Single-Board Computers
 Single-board Computers, also called systems-on-a-chip, are small full-fledged
computers.
 It has memory and storage.
 It has peripherals that comply a regular standard (usually USB).
 They include everything needed to make them work (usually only needing a
power adapter to our house power line)
 They can run an operating system completely
 A Raspberry Pi is a single-board-computer or system-on-a-chip and it runs a
complete Linux operating system.

8. Write notes on Hardware Platforms – Arduino, Raspberry Pi, Node MCU.

An IoT platform manages the connectivity of the devices and allows developers to build
new mobile software applications. It facilitates the collection of data from devices and
enables business transformation. It connects different components, ensuring an
uninterrupted flow of communication between the devices.

Arduino

The Arduino is a single circuit board, which consists of different interfaces or parts. The
board consists of the set of digital and analog pins that are used to connect various
devices and components, which we want to use for the functioning of the electronic
devices.
Most of the Arduino consists of 14 digital I/O pins.

12
The analog pins in Arduino are mostly useful for fine-grained control. The pins in the
Arduino board are arranged in a specific pattern. The other devices on the Arduino board
are USB port, small components (voltage regulator or oscillator), microcontroller, power
connector, etc.

Arduino Uno Pin Diagram

Applications
Few applications of the Arduino Uno boards are:
 Robotics and Control Systems
 Home and Industry Automation
 Traffic Light Countdown Timer
 Underground Cable Fault Recognition
 Controlling of Electrical Appliances using IR
 Parking Lot Counter
 Weighing Machines
 Medical Instrument
 Emergency Light for Railways
 Auto Intensity Control of Street Lights
 Biotechnology
 Agriculture
Pros
 Inexpensive
 Cross-platform
 Simple, clear programming environment
 Open source and extensible software and hardware
 Large support of community
Cons
 Memory limitations
 Less powerful
 Processing power is weaker than the microcontroller
 Requires effort to accomplish some tasks such as scheduling and database
storage

13
Raspberry Pi

A small, fully functional computer that can be plugged into a computer monitor, keyboard,
and mouse. It has all qualities of a PC- a dedicated processor, memory, and a graphics
driver. It even has its own operating system called Raspberry Pi OS which is an
optimized version of Linux.

Features
 Superior software implementation
 64-bit Quad-core processor
 Large RAM (latest Raspberry Pi 4 Model B Board has up to 8G of RAM)
 Processor speed- 700MHz- 1.5GHz
 Raspberry Pi has 40 input/output pins.
 It can be connected to the Internet.
 It can run all kinds of applications (including MS Office and Email).
 It contains everything- CPU (Central Processing Unit), GPU (Graphics Processing
Unit), Ethernet port, GPIO (General-purpose Input/Output) pins, and power source
connector.
Applications of Raspberry Pi
 Media Streamer
 Arcade machine
 Tablet computer
 Home automation
 Carputer
 Internet radio
 Controlling robots
 Cosmic Computer
 Hunting for meteorites and Coffee
 Raspberry based projects
Advantages
 Following are some of the main advantages of Raspberry Pi
 It is very easy to connect to the internet
 Entire Linux software stack is available
 Can be programmed using a variety of programming languages
Disadvantages
 Following are some of the main limitations of Raspberry Pi.

14
 Accessing hardware is not real-time. If the CPU is busy, then interfacing with the
hardware can be delayed.
 Does not have enough power to drive inductive loads.
 There is no inbuilt Analog to Digital converter available.
 The hardware design is not open source. Even though it is not a big deal, for
some people it might a deal-breaker.

NodeMCU

NodeMCU is an open source platform based on ESP8266 which can connect objects
and let data transfer using the Wi-Fi protocol. In addition, by providing some of the
most important features of microcontrollers such as GPIO, PWM, ADC, and etc, it
can solve many of the project’s needs alone.
The general features of this board are as follows:
 Easy to use
 Programmability with Arduino IDE or IUA languages
 Available as an access point or station
 practicable in Event-driven API applications
 Having an internal antenna
 Containing 13 GPIO pins, 10 PWM channels, I2C, SPI

Applications of NodeMCU
 Geolocation using ESP8266
 ESP8266 based wireless server
 Pressure Sensors on Railway Tracks
 Air Pollution Meter
 Humidity and temperature monitoring
 Wi-Fi controlled robot
 Temperature logging system
 M2M using ESP8266
 Make our personal assistant
Pros
 Provided inbuilt WiFi functionality
 Cost-effective
 Integrated support for WIFI network
 Low energy consumption
Cons
 It is a 3.3V device, so it may not be compatible with some peripherals
 Lack of official documentation
 WiFi code takes a lot of CPU power

15
9. Write the difference between Arduino and Raspberry Pi.

Basis Arduino Raspberry Pi


Arduino is an open-source
Both hardware and software of
License project. Both its software and
Raspberry Pi are closed source.
hardware design are open source.
Control Unit From Atmega Family From ARM Family
Clock
16 MHz (Arduino UNO) Up to 1.5 GHz in Raspberry Pi 4 B
Frequency
Requires large RAM (more than 1
RAM Requires less RAM (2kB)
GB)
CPU
8-bit 64-bit
Architecture
Logic level Arduino’s logic level is 5V. Raspberry Pi’s logic level is 3V.
Power Consumes about 200 MW of
Consumes about 700 MW of power
Consumption power
Raspberry Pi is based on a
Based on Arduino is a Microcontroller
microprocessor
Hardware
Simple hardware structure Complex hardware Structure
Structure
Arduino boards are Raspberry Pi supports its own Linux-
Software programmable using C/C++ based operating system Raspberry Pi
languages. OS.
Arduino does not have internet
support. We need additional Raspberry Pi has a built-in Ethernet
Internet
modules or shields to connect it to port and Wi-Fi support.
the internet.
Cost Arduino boards are cheaper. Raspberry Pi boards are expensive.
Arduino devices begin executing
How they Raspberry Pi requires the same care
code when they are turned on.
handle power as a PC. We have to shut the
Therefore, The code will simply
drop operating system down properly.
start again when plugged in.
Current drive
Higher current drive strength Lower current drive strength
strength
Arduino is generally used to
Raspberry Pi can perform multiple
Capability perform single (and simple) tasks
tasks simultaneously.
repeatedly.
Wireless Arduino does not support Raspberry Pi supports Bluetooth and
connectivity Bluetooth or Wi-Fi. Wi-Fi.
Traffic light countdown timer,
Robot controller, Game servers, Stop
Applications Parking lot counter, Weighing
motion cameras, etc.
machines, etc.

16
10. How to read Analog Sensors using Arduino?

The Arduino has built-in analog and digital input and output (I/O) pins that we can
interface to a variety of sensors and devices.

The difference between analog and digital sensors is that an analog sensor collects
readings over a range of values, and a digital sensor only reads a HIGH or LOW
signal (a bit of data).

The Arduino has a 10-bit Analog-to-Digital-Converter (ADC), which maps sensor


readings between 0 and the operating voltage (5V or 3.3V) into integer values
between 0 and 1023.

Step 1. Wire Analog Sensors to Arduino

The majority of analog sensors for Arduino are wired and programmed the same. So, once
we learn how to wire and read data from one analog sensor, we’ll be able to wire and
program thousands of additional sensors to collect a whole bunch of data. For this example,
consider a wiring and programming a light-dependent resistor (LDR) also known as a photo
resistor.

The first step is to connect the analog sensor to the Arduino. Analog sensors for Arduino
have three wires (Ground, Signal, Power). Refer to the sensor’s datasheet to figure out
which wire is which. Then, connect the ground wire to GND on the Arduino. Next, attach the
Signal wire to an analog pin on the Arduino. Lastly, connect the power wire to the 5V on the
Arduino.

Step 2. Setup our Arduino Sketch

int ldr = A0;


Then, in the setup() method, initialize the sensor as an input and start the Serial monitor.

void setup(){
pinMode(ldr, INPUT); //initialize ldr sensor as INPUT
Serial.begin(9600); //begin the serial monitor at 9600 baud
}
The Arduino UNO has a baud rate of 9600. We can use the begin method to start the Serial
Monitor. Now, we’re ready to write the Arduino code to collect readings from our analog
sensor.

17
Step 3. Write code to collect readings from Analog Sensors

Next, collect a sensor reading using the analogRead(ldr) method, and store it in an integer
variable. I called this variable “data.”

Use a few print statements to show the readings in the Serial monitor.

Serial.print() will print data horizontally across the screen. Serial.println() will print data
vertically down the screen. I used both to label the data while making it easy to read.

void loop(){
int data=analogRead(ldr);
Serial.print(“ldr reading=“);
Serial.println(data);
delay(1000);
}
Finally, add a delay. This prevents the Arduino from taking readings faster than we can see
them. Feel free to adjust this delay to whatever interval makes sense for our application.
Once we have the test code written, save the sketch and upload it to the Arduino. Open up
the serial monitor and we should see values from 0-1023 depending on how bright or dark
the area is.

Step 4. Analyze and Convert Sensor Readings as needed

Some sensors require a unit conversion. For example, it’s easier to understand what
temperature it is when the units are in Celsius or Fahrenheit. Furthermore, with our LDR we
could convert the unit readings into a brightness percentage. That way when we analyze
the data, we can check for conditions based on 25% bright, 100% bright, or a unit that
makes more sense for the application.

Most datasheets specify formulas that we can use to make these conversions. We don’t
always have to “make up” a unit for our sensor.

Step 5. Use sensor data to make decisions

Once we have an understanding of how data is collected from our analog sensor, we can
use the readings to make decisions.

We’ll use conditional statements to check to see if a condition is TRUE or FALSE. Then,
based on that condition, we’ll react accordingly.

Example

If the condition is LIGHT, then let’s write the word “daylight” to the Serial Monitor.
Otherwise, write the word “nighttime” to the Serial Monitor.

First, add a method called lightCheck() to the previous Arduino sketch.

//globals to store data


18
int reading;
int threshold = 900; //range of 0-1023 / higher value = brighter

void lightCheck(){
reading = analogRead(ldr);
if(reading >= threshold){ //this condition means the readings are light
Serial.println("daylight");
}
else{
Serial.println("nighttime");
}
delay(1000);
}
Then, we’ll call lightCheck() in our loop() method. Here’s how it should work.

19

You might also like