Fiot-Ii Unit

You might also like

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

Fundamentals Of Internet Of Things

-Md.Umalawara

UNIT II

Machine-to-Machine Communications, Difference between IoT and M2M,


Interoperability in IoT, Introduction to Arduino Programming, Integration of Sensors
and Actuators with Arduino.

Machine-to-Machine Communications
IoT Communication: IoT is the connection of devices over the internet, where these smart devices
communicate with each other , exchange data , perform some tasks without any human involvement. These
devices are embedded with electronics, software, network and sensors which help in communication.
Communication between smart devices is very important in IOT as it enables these devices to gather,
exchange data which contribute in success of that IOT product/project.

Types of Communications in IOT:

The following are some communication types in IoT:-


1. Human to Machine (H2M):
In this human gives input to IOT device i.e as speech/text/image etc. IOT device (Machine) like sensors
and actuators then understands input, analyses it and responds back to human by means of text or Visual
Display. This is very useful as these machines assist humans in every everyday tasks. It is a combo of
software and hardware that includes human interaction with a machine to perform a task.

H2M communication

Merits: This H2M has a user-friendly interface that can be quickly accessed by following the
instructions. It responds more quickly to any fault or failure. Its features and functions can be customized.
Examples:
 Facial recognition.
 Bio-metric Attendance system.
 Speech or voice recognition.
2. Machine to Machine (M2M):

The process of exchanging information or messages between two or more machines or devices is known
as Machine to Machine (M2M) communication.
It is the communication among the physical things which do not need human intervention.
M2M communication is also named as Machine Type communication in 3GPP(3rd Generation Partnership
Project).
In this the interaction or communication takes place between machines by automating data/programs. In thi s
machine level instructions are required for communication. Here communication takes place without human
interaction. The machines may be either connected through wires or by wireless connection. An M2M
connection is a point-to-point connection between two network devices that helps in transmitting
information using public networking technologies like Ethernet and cellular networks. IoT uses the basic
concepts of M2M and expands by creating large ―cloud‖ networks of devices that communicate with one
another through cloud networking platforms.

M2M communication

Advantages –
This M2M can operate over cellular networks and is simple to manage. It can be used both indoors and
outdoors and aids in the communication of smart objects without the need for human interaction. The M2M
contact facility is used to address security and privacy problems in IoT networks. Large-scale data
collection, processing, and security are all feasible.
Disadvantages –
However, in M2M, use of cloud computing restricts versatility and creativity. Data security and
ownership are major concerns here. The challenge of achieving interoperability between cloud/M2M IoT
systems is daunting. M2M connectivity necessitates the existence of a reliable internet connection.
Examples:
 Smart Washing machine sends alerts to the owners‘ smart devices after completion of washing or drying
of clothes.
 Smart meters tracks amount of energy used in household or in companies and automatically alert the
owner.
3. Machine to Human (M2H) :
In this machine interacts with Humans. Machine triggers information(text
messages/images/voice/signals) respective / irrespective of any human presence. This type of
communication is most commonly used where machines guide humans in their daily life. It is way of
interaction in which humans co-work with smart systems and other machines by using tools or devices to
finish a task.
M2H communication

Examples:
 Fire Alarms
 Traffic Light
 Fitness bands
 Health monitoring devices
4. Human to Human (H2H) :
This is generally how humans communicate with each other to exchange information by speech,
writing, drawing, facial expressions, body language etc. Without H2H, M2M applications cannot produce
the expected benefits unless humans can immediately fix issues, solve challenges, and manage scenarios.
The process of exchanging information
or messages between two or more people is known as human to human (H2H) communication. This can be
done through various means such as verbal,
non-verbal, or written communication.

H2H communication

For, communication of IoT devices many protocols are used. These IoT protocols are modes of communication which
give security to the data being exchanged between IoT connected devices. Example bluetooth, wifi, zigbee etc.
MACHINE TO MACHINE COMMUNICAION (M2M)
in IoT
Introduction

 Communication between machine or devices with computing and communication facilities.


 Free of any human intervention.
 Similar to industrial supervisory control and data acquisition systems (SCADA).
 SCADA is designed for isolated systems using proprietary solutions, whereas MACHINE TO
MACHINE (M2M) is designed for cross-platform integration.

1. M2M Overview
2. M2M SYSTEM ARCHITECTURE
3. M2M GATEWAY
4. M2M APPLICATION
5. M2M Service Platform (M2SP)(SERVIVE LAYER STARDIZATION)
1.M2M Overview
2.M2M SYSTEM ARCHITECTURE:
3.M2M GATEWAY
4.M2M Application****

 Environmental monitoring
 Civil protection and public safety
 Supply Chain Management (SCM)
 Energy & utility distribution industry (smart grid)
 Intelligent Transport Systems (ITSs)
 Healthcare
 Automation of building
 Military Applications
 Agriculture
 Home networks

Machine 2 Machine (hereafter M2M) communication is an important part for Internet of Things (hereafter
IoT) inspired world to become a reality. M2M technology is needed to create a common network of
communication between all physical objects. These communications help the businesses in improving their
processes, monitoring their assets and generating more revenues.

 In this article, we‘ll talk about some of the applications of Machine to Machine Technology.
1. Utility Companies: M2M communications help the utility companies in harvesting energy
products, like oil, gas, etc. and in billing their customers. The remote sensors deployed in oil drilling
sites collect regular data about the presence of oil at a particular field and send that data to a remote
computer. They are also capable of sending information about the flow rates, temperature, pressure,
fuel levels, etc. wirelessly to the remote computer.
2. Traffic Control: Traffic Control is another common area where the use of M2M communication
can be seen. A traffic system collects data related to the speed and volume of the traffic with the help
of various sensors and sends this information across the computers that control the devices such as
signals and lights. The cameras installed on the traffic signals also collect data about the vehicles not
following the traffic rules and send pictures to the software which then sends challan receipts to the
defaulters.
3. Telemedicine: Another common area of application of M2M communications is Telemedicine.
Heart patients wear special devices which monitor their heart rate. This data is sent to the implanted
device which sends back shocks to the patient for correcting any errant rhythms in the heart beat.
4. Inventory Management: Products are tagged with RFID tags which send signals to the
computers and alert the retailer in case of a theft attempt. These tags also help the retailers to keep a
track of their goods which are sold online in large quantities and have high chances of theft/shortage.
5. Banking: Banking is another common area to make use of M2M. With an increase in the
smartphone market, people have started making mobile payments for their purchases. They can
deposit money into the bank, transfer money to other accounts and can even withdraw at their
convenience. The mobile system is connected to the bank‘s central system and updates the mobile
transaction in the books as and when they happen. On the other hand, Banks can monitor the cash
available in the ATMs and also the technical issues they are facing.

 Large number of nodes or devices.


 Low cost.
 Energy efficient.
 Small traffic per machine/device.
 Large quantity of collective data.
 M2M communication free from human intervention.
 Human intervention required for operational stability and sustainability.
 5.M2M Ecosystem
6.M2M Service Platform (M2SP)

USING ONE M2M SERVICE LAYER :

Difference between IoT and M2M:

1. Internet of Things : IOT is known as the Internet of Things where things are said to be the communicating
devices that can interact with each other using a communication media. Usually every day some new devices
are being integrated which uses IoT devices for its function. These devices use various sensors and actuators
for sending and receiving data over the internet. It is an ecosystem where the devices share data through a
communication media known as the internet or Iot is an ecosystem of connected physical object that are
accessible through internet. Iot means anything which can be connected to internet and can be controlled or
monitored using internet from smart devices or PC.
2. Machine to Machine : This is commonly known as Machine to machine communication. It is a concept
where two or more than two machines communicate with each other without human interaction using a wired
or wireless mechanism. M2M is an technology that helps the devices to connect between devices without
using internet. M2M communications offer several applications such as security, tracking and tracing,
manufacturing and facility management.
M2M is also named as Machine Type Communication (MTC) in 3GPP ( 3rd Generation Partnership
Project).
M2M is communication could carried over mobile networks, for ex- GSM-GPRS, CDMA EVDO Networks .
In M2M communication, the role of mobile networks is largely confined to server as a transport networks.
M2M is only subset of IoT .

\Difference between IoT and M2M :

Basis of IoT M2M

Abbreviation Internet of Things Machine to Machine

Devices have objects that are responsible Some degree of intelligence is


Intelligence
for decision making observed in this.

Connection type The connection is via Network and using


The connection is a point to point
used various communication types.

Traditional protocols and


Communication Internet protocols are used such
communication technology
protocol used as HTTP, FTP, and Telnet.
techniques are used

Data is shared between other applications


Data is shared with only the
Data Sharing that are used to improve the end-user
communicating parties.
experience.

Internet connection is required for Devices are not dependent on the


Internet
communication Internet.

Type of It supports point-to-point


It supports cloud communication
Communication communication.

Involves the usage of both Hardware and


Computer System Mostly hardware-based technology
Software.

A large number of devices yet scope is


Scope Limited Scope for devices.
large.

Business 2 Business(B2B) and Business 2


Business Type used Business 2 Business (B2B)
Consumer(B2C)
Basis of IoT M2M

Open API support Supports Open API integrations. There is no support for Open APIs

It requires Generic commodity devices. Specialized device solutions.

Centric Information and service centric Communication and device centric.

Approach used Horizontal enabler approach Vertical system solution approach .

Devices/sensors, connectivity, data Device, area networks, gateway,


Components
processing, user interface Application server.

Examples Smart wearables, Big Data and Cloud, etc. Sensors, Data and Information, etc.

Interoperability in IOT
Interoperability focuses on ensuring that two IoT systems or their components can engage in a
working interaction. Figure 2 shows the interaction of several IoT systems or peer IoT systems. For instance, a
taxi reservation service can interact with a traffic management system.

Current Challenges in IoT

Large Scale of Co-Operation :

 The cooperation and coordination of millions of distributed devices are required on Internet
Global Heterogeneity :

 Heterogeneous IoT devices and their subnets


Unknown IoT Device Configuration :

 The difference configuration modes for IoT devices which come from unknown owners.
Semantic Conflicts :

 Different processing logic's applied to same IoT networked devices or applications.

What is Interoperability ?

Interoperability is a characteristic of a product or system, whose interfaces are completely understood, to


work with other products or systems, present or future, in either implementation or access, without any
restrictions.

 Communicate meaning fully


 Exchange data or services
Why Interoperability is Important in Context of IoT ?

To fulfill the IoT objectives

 Physical objects can interact with any other physical objects and can share their information
 Any devices can communicate with other devices anytime from anywhere
 Machine to Machine communication (M2M) , Device to Device Communication (D2D), Device to
Machine Communication (D2M)
 Seamless device integration with IoT network

Why Interoperability is required ?

Heterogeneity

 Different wireless communication protocols such as ZigBee(IEEE 802.15.4), Bluetooth (IEEE


802.15.1), GPRS, 6LowPAN, and Wi-Fi (IEEE 802.11)
 Different wired communication protocols like Ethernet (IEEE 802.3) and Higher Layer LAN Protocols
(IEEE 802.1)
 Different programming language used in computing systems and website such as JavaScript, JAVA,
C, C++,Visual Basic, PHP, and Python
 Different hardware platforms such as Crossbow, NI, etc.

Different Types of Interoperability ?

1.User Interoperability

 Interoperability problem between a user and a device


2.Device Interoperability

 Interoperability problem between two different devices

Example of Device and User Interoperability

 Using IoT, both A and B provide a real-time security service


 A is placed at delhi, India, while B is placed at Tokyo, Japan
 A,B, U use Hindi, Japanese, and English language , respectively
 User U wants real-time service of CCTV camera from the device A and B
1.User Interoperability

The following problems need to be solved

 Device identification and categorization for discovery


 Syntactic interoperability for device interaction
 Semantic interoperability for device interaction
2.Syntactic Interoperability:

Syntactic interoperability for device interaction the interoperability between devices and device
user in terms of message formats is what is the concern of this type of interoperability. The
message format from a device to a user is understandable for the user‗s computer. On the other
hand the message format from the user to the device is executable by the device. middleware
technology is sort of like a software middleware bridge, which dynamically maps the physical
devices with the different domains and based on the map the devices can be discovered and
controlled remotely. Then we have the cross context syntactic interoperability, which
concerns collaborative concept exchange and using XML syntax.
3.Semantic interoperability

Semantic interoperability for device interaction; and here we are talking about the semantics
and the exchange of the semantics. So, the messages that are sent between these different
devices whether they are understood by the respective party if not there has to be some
middleware in between which has to make it happen. So, the device can understand the meaning
of users instructions that is sent from the user to the device, similarly the user can understand the
meaning of devices response sent from the device.
Introduction to Arduino Programming
Arduino-The company

Arduino was a project started at Interaction Design Institute Ivrea (IDII) in Ivrea, Italy, with its
primary goal being creating affordable and straightforward tools for non-engineers to use and create digital
projects. During its infancy, the project consisted of just three members- Hernando Barragán, Massimo
Banzi, and Casey Reas. Hernando Barragán worked under the guidance of Massimo Banzi and Casey Reas
and created a development platform called Wiring as his masters‘ thesis project at IDII.
The development platform consisted of the ATMega168 microcontroller as its brains and used an
IDE based on Processing, which was co-created by Casy Reas. Later, Massimo Banzi, along with two other
students from IDII, namely- David Mellis and David Cuartielles, added support for the cheaper ATMega8
microcontroller. The three, instead of working on developing and improving Wiring, they forked it and
renamed the project to Arduino. The initial core Arduino team consisted of Massimo Banzi, David
Cuartielles, Tom Igoe, Gianluca Martino, and David Mellis, but Barragán was not included.

The Hardware

Now that you know the origin of Arduino, it is essential to get yourself acquainted with the hardware that
Arduino as a company offers. One of the main reasons for Arduino being so accessible and affordable
across the globe is because all of the Arduino hardware is open-source. Being open-source has a plethora of
advantages- anyone can access the design and build of the device and make improvements; anyone can use
the same hardware design to create their product lineup.
Since Arduino is open-source, it has its own devoted community that strives to help the core
company develop and improve its hardware products. Another significant advantage of being open-source,
especially in the case of hardware, is that local companies can create replicas of the products, making it
more accessible and affordable to the local consumers as it avoids hefty customs and shipping charge s. All
of these advantages contribute to Arduino being so widespread, affordable and ever-improving.
It is necessary to know that Arduino doesn‘t necessarily offer just one piece of hardware, it provides a range
of boards, each of which caters to a different level of expertise and have different use-cases altogether.
Arduino Uno is one of the most basic and popular boards that Arduino offers.
This is because it features an ATMega328 microcontroller that is both cheap and powerful enough
for most basic beginner-level projects. Once you‘re familiar with Arduino IDE, you can move up to boards
with more powerful and sophisticated chipsets like the MKR range which is concerned with IoT
applications and inter compatibility, or the Nano range which as the name suggests is designed to keep the
form factor as small as possible while packing most of the features and power of the full -sized boards.
Features of Arduino
 Open source based electronic programmable board (micro controller) and software (IDE)
 Accepts analog and digital signal as input and gives desired output
 No extra hardware required to load a program into the controller board
Types of Arduino Board
 Arduino boards based on ATMEGA328 microcontroller
 Arduino boards based on ATMEGA32u4 microcontroller
 Arduino boards based on ATMEGA2560 microcontroller
 Arduino boards based on AT91SAM3X8E microcontroller
Arduino UNO
BOARD DETAILS:

So you got yourself an Arduino Uno, and you‘re ready to jump into the world of electronics and join the
community of makers from around the world, but before you begin with programming and external circuitry
through breadboards and whatnot, it is necessary to understand the layout and circuitry of your Arduino
Uno.

Using the above image as a reference, the labeled components of the board respectively are-
1. USB: can be used for both power and communication with the IDE
2. Barrel Jack: used for power supply
3. Voltage Regulator: regulates and stabilizes the input and output voltages
4. Crystal Oscillator: keeps track of time and regulates processor frequency
5. Reset Pin: can be used to reset the Arduino Uno
6. 3.3V pin: can be used as a 3.3V output
7. 5V pin: can be used as a 5V output
8. GND pin: can be used to ground the circuit
9. Vin pin: can be used to supply power to the board
10. Analog pins(A0-A5): can be used to read analog signals to the board
11. Microcontroller(ATMega328): the processing and logical unit of the board
12. ICSP pin: a programming header on the board also called SPI
13. Power indicator LED: indicates the power status of the board
14. RX and TX LEDs: receive(RX) and transmit(TX) LEDs, blink when sending or receiving serial data
respectively
15. Digital I/O pins: 14 pins capable of reading and outputting digital signals; 6 of these pins are also
capable of PWM
16. AREF pins: can be used to set an external reference voltage as the upper limit for the analog pins
17. Reset button: can be used to reset the board

Power supply : USB or power barrel jack


 Voltage Regulator
 LED Power Indicator
 Tx-Rx LED Indicator
 Output power, Ground
 Analog Input Pins
 Digital I/O Pins

Pin description:
How To Program Arduino
Once the circuit has been created on the breadboard, you‗ll need to upload the program (known
as a sketch) to the Arduino. The sketch is a set of instructions that tells the board what
functions it needs to perform. An Arduino board can only hold and perform one sketch at a time.
The software used to create Arduino sketches is called the IDE which stands for Integrated
Development Environment.
Every Arduino sketch has two main parts to the program:
void setup() – Sets things up that have to be done once and then don‗t happen again.
void loop() – Contains the instructions that get repeated over and over until the board is turned
off.

Operators:
Logical operators evaluate either one or two relational or logical statements. There are 3 logical
operators in Arduino IDE:

LOGICAL OPERATOR OPERATOR SYMBOL EXAMPLE


OR || a || b
AND && a && b
NOT ! !a

Arduino control statements include:


 If statement
 Else statement
 Else if statement
 For statement
 While statement
 Do while statement
 Switch case
 Continue
IF statement:

IF statement is basically the simplest form conditional control statements, it is a conditional


statement. An ―if statement‖ code evaluates a unique
condition, and executes a series of instructions or just an instruction if the condition is true.
ELSE STATEMENT

Most time, an IF statement is immediately followed by an ELSE statement, the ELSE


statement tells the alternate instruction that should be executed when the IF statement is false.
ELSE IF STATEMENT

―Else if statement‖ is used when we want to check for three different conditions. It includes
an IF statement, ELSE IF statement and ELSE statement all in same.
For statement:

For statement is also a conditional statement for Arduino control structure used for repetitive
operation. As the name implies, it is used to carry out a repetitive operation for a true
condition.
While Statement

A while statement is just like an ―if statement‖ except it continues to repeat block of code (a
block of code is what is within the curly braces) as long as the condition is true.
Do While Statement

A do while statement is like the else if statement but works in the same manner as the while
loop, except that the condition is tested at the end of the loop, hence, the do statement will
always run at least once.
Switch Case Statement

There comes a time in a design, when we wish to have an action taking with respect to a specific
result, in a wide range of results. Take for example, let‗s say you are trying to monitor the level of
water in a tank using an ultrasonic sensor, you wish to turn on an LED various levels of the
water in the tank. Let‗s say we are looking at 10 levels. In our arduino code, we would have a
variable that records the distance of the water from the ultrasonic sensor, with this distance;
we can pick the levels we want.
Loop Statements:

while loop

while loops will loop continuously, and infinitely, until the expression inside the parenthesis, ()
becomes false. Something must change the tested variable, or the while loop will never exit.
do…while loop
The do…while loop is similar to the while loop. In the while loop, the loop- continuation
condition is tested at the beginning of the loop before performed the body of the loop.
for loop

A for loop executes statements a predetermined number of times. The control expression for
the loop is initialized, tested and manipulated entirely within the for loop parentheses.

Nested Loop

This allows you to use one loop inside another loop. The following example illustrates the
concept.
Infinite loop

It is the loop having no terminating condition, so the loop becomes infinite.

Arduino IDE:
 Arduino IDE is an open source software that is used to program the Arduino controller board
 Based on variations of the C and C++ programming language
 It can be downloaded from Arduino's official website and installed into PC
Set Up

 Power the board by connecting it to a PC via USB cable


 Launch the Arduino IDE
 Set the board type and the port for the board
 TOOLS -> BOARD -> select your board
 TOOLS -> PORT -> select your port

Arduino IDE Overview

Program coded in Arduino IDE is called a SKETCH


 Verify : Checks the code for compilation errors
 Upload : Uploads the final code to the controller board
 New : Creates a new blank sketch with basic structure
 Open : Opens an existing sketch
 Save : Saves the current sketch
Sketch Structure

 A sketch can be divided into two parts :


 - Setup ( )
 Loop ( )

 The function setup( ) is the point where the code starts , just like the main ( ) function in C and C++
 I/O Variables, pin modes are initialized in the Setup( ) function
 Loop( ) function, as the name suggests, iterates the specified task in the program

Supported Datatype

 Arduino supports the following data types -


void Long
Int Char
Boolean Unsigned char
Byte Unsigned int
Word Unsigned long
Float Double
Array String-char array
String-object Short
Arduino Function Libraries
Input/Output Functions :
 The Arduino pins can be configured to act as input or output pins using the pinMode( ) function
Void setup ( )
{
pinMode (pin , mode);
} }
Pin-pin number on the Arduino board
Mode - INPUT/OUTPUT

ARDUINO PROGRAM
An Arduino program starts by executing the code inside the setup() function once. After that, the
code inside loop() is repeated forever (or until you disconnect the power).
Blinking an LED

The LED blinking sketch is the first program that you should run to test whether your Arduino
board is working and is configured correctly. It is also usually the very first programming
exercise someone does when learning to program a microcontroller. A light-emitting diode
(LED) is a small electronic component that‗s a bit like a light bulb, but is more efficient and
requires lower voltages to operate

Example of led blinking:

const int LED = 13; // LED connected to digital pin 13 void setup()
{
pinMode(LED, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(LED, HIGH); // turns the LED on delay(1000); //
waits for a second digitalWrite(LED, LOW); // turns the LED off
delay(1000); // waits for a second
}
Program explanation:
 Turns pin 13 into an output (just once at the beginning)
 Enters a loop
 Switches on the LED connected to pin 13
 Waits for a second
 Switches off the LED connected to pin 13
 Waits for a second
 Goes back to beginning of the loop.
Example : Turn on LED while the button is pressed
const int LED = 13; // the pin for the LED
const int BUTTON = 7; // the input pin where the pushbutton is connected int val = 0; //val will
be used to store the state
// of the input pin void
setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output pinMode(BUTTON, INPUT);
//and BUTTON is an input
}
void loop(){
val = digitalRead(BUTTON); // read input value and store it
// check whether the input is HIGH (button pressed) if (val ==
HIGH) {
digitalWrite(LED, HIGH); //turn LED ON
} else { digitalWrite(LED,
LOW);
}
}
Now go test this code. You‗ll find that the light changes so rapidly that you can‗t reliably set it
on or off with a button press. Let‗s look at the interesting parts of the code: state is a variable
that stores either 0 or 1 to remember whether the LED is on or off. After the button is released,
we initialise it to 0 (LED off).
Later, we read the current state of the button, and if it‗s pressed (val == HIGH), we change
state from 0 to 1, or vice versa. We do this using a small trick, as state can be only either 1 or 0.
The trick I use involves a small mathematical expression based on the idea that 1 – 0 is 1 and
1 – 1 is 0:state = 1 – state. The line may not make much sense in mathematics, but it does in
programming. The symbol = means ―assign the result of what‗s after me to the variable
name before me‖—in this case, the new value of state is assigned the value of 1 minus the old
value of state.
INTEGRATION OF SENSOR AND ACTUATORS WITH
ARDUINO in IoT
SENSORS
 Basic electronic Device
 Convert a physical quantity/ measurements into electrical signals
 Can be analog or digital
Types of Sensors
Some commonly used sensors :
 Temperature
 Humidity
 Compass
 Light
 Sound
 Accelerometer
Sensor Interface with Arduino
Digital Humidity and Temperature Sensor (DHT)

PIN 1,2,3,4 (from left to right)


 PIN 1-3.3V-5V Power supply
 PIN 2- Data
 PIN 3-Null
 PIN 4- Ground
DHT Sensor Library
 Arduino supports a special library for the DHT11 and DHT22 sensors
 Provides function to read the temperature and humidity values from the data pin
dht.readHumidity()
dht.readTemperature()
Connection
 Connect pin 1 of the DHT to the 3.3 V supply pin in the board
 Data pin (pin 2) can be connected to any digital pin, here 12
 Connect pin 4 to the ground (GND) pin of the board




Sketch: DHT_Sensor Install the DHT Sensor Library

 Go to sketch -> Include Library -> Manage Library

 Search for DHT Sensor


 Select the "DHT sensor library" and install it
1.TMP36 Temperature Sensor Example:
So, first of all as we have already learned by now; sensors are basic electronic elements they
convert physical quantities or measurements into electrical signals and more or less sensors
can be classified into either analog or digital sensors.

 Connect the board to the PC


 Set the port and board type
 Verify and upload the code
OUTPUT

The readings are printed at a delay of 2 seconds as specified by the


delay() function

2.Light Sensor:
In this example we will use a light sensor to measure the light intensity of the room. If it's
dark, we will turn on the light (LED). If it's bright, we'll turn off the light (LED). A light sensor /
photocell is a sensor used to detect light. The resistance decreases with increasing light intensity
(stronger light).

Program:
int photocellPin = 2; int
ledPin = 13;
int photocellReading; const
float limit = 100; void
setup(void)
{
Serial.begin(9600); //baud rate of data is 9600bps pinMode(ledPin,
OUTPUT);
}
void loop( )
{
photocellReading = analogRead(photocellPin);

Serial.print("Analog reading = ");


Serial.println(photocellReading);

if (photocellReading < limit)


{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
Delay(1000)
}

ACTUATORS:
So we will learn how to integrate this motors and make it perform according to our requirements.
So, actuators are basically mechanical or electro mechanical devices. They convert energy or
signals into motion. And mainly use to provide controlled motion to other components of various
mechanical structures or devices. So, basic working principle is, in the servo motor you have
various mechanical structures like gears and screws and ball bearings, which are interfaced with
a small motor over here, and this produces very control motion, but is able to perform much
more efficiently then this motor alone would have been able to. So, like generally for servers
the top requirements are high as compared to normal dc motors.
Servo motors are great devices that can turn to a specified position. Usually, we have a servo
arm that can turn 180 degrees. Using the Arduino, we can tell a servo to go to a specified
position and it will go there. A servo motor has everything built in: a motor, a feedback
circuit, and most important, a motor driver. It just needs one power line, one ground, and one
control pin.

1.Program for servo motors:


//Include the Servo library
#include <Servo.h>
// Declare the Servo pin int
servoPin = 3;
//Create a servo object Servo
Servo1;
void setup() {

// We need to attach the servo to the used pin number Servo1.attach(servoPin);


}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(1000);
//Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
}

Circuit diagram:
How to Use an Arduino with Linear Actuators:
Arduino is a specific open-source community\company\project in one, which specializes in
microcontrollers, specifically the building and programming of them. Arduino also offers
simple kits made for easy
assembly. Arduino controllers are small controllers of microchips and boards which allow for
remote control of certain pieces of equipment. These microcontrollers are both digital and
analog, meaning they can be used for a wide variety of equipment, regardless of whether or not
the equipment is digital or analog itself. These microcontrollers can be used with linear
actuators, as a means of controlling them.
As for coding your Arduino microcontroller, we have included a simple sweep program that
shows how to extend and retract a linear actuator at full speed.

//Define pin numbers for Single Board\


int ENABLE1 = 8;

int FWD1 = 11;

int REV1 = 3;

int Speed; void setup() // initialize the digital pins as


an
{

output. pinMode(ENABLE1,OUTPUT);

pinMode(FWD1, OUTPUT);

pinMode(REV1, OUTPUT);

void loop()

Speed = 255; //set a speed between 0-255 Forward();

delay(5000); //5 second delay

Stop();

delay(1000);

Reverse();

delay(500);

Stop();
delay(1000);

void Forward()

digitalWrite(ENABLE1, HIGH);

analogWrite(REV, 0);

analogWrite(FWD, Speed);

void Reverse()

digitalWrite(ENABLE1, HIGH);

analogWrite(FWD, 0);

analogWrite(REV, Speed);

void Stop()

digitalWrite(ENABLE1, LOW);

analogWrite(FWD1, 0);

analogWrite(REV1, 0);

You might also like