SlideShare a Scribd company logo
I2C LCD Display
Pin Description of I2C Module
• The term I2C stands for “Inter Integrated Circuits”.
• It is normally denoted as IIC or I squared C or even as 2-
wire interface protocol (TWI).
• I2C is a synchronous communication protocol, means both
the devices that are sharing the information must share a
common clock signal.
• It has only two wires, SDA (serial data) and SCL to share
information, out of which SCL(serial clock ) is used for the
clock signal and SDA is used for sending and receiving data.
• It is very useful IC and can be used in LED signs boards,
displays, Key pads, Industrial control, etc.
• There are 8 I/O pins, 3 pins (A0, A1, A2) for I2C bus address
and SDA, SCL pins.
Hardware Required
Interfacing Diagram
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 16, 2); // Format ->
(Address,Width,Height )
void setup( )
{
lcd.init( ); // initialize the lcd
lcd.backlight (); // Turn on the Backlight
}
void loop( )
{
lcd.clear( ); // Clear the display buffer
lcd.setCursor(0, 0); // Set cursor (Column, Row)
lcd.print("Hello"); // print "Hello" at (0, 0)
lcd.setCursor(0,1); // Set cursor (Column, Row)
lcd.print("Geek"); // print "Geek" at (0, 1)
delay(100);
}
Buzzer with Arduino
• By interfacing a buzzer with Arduino, you can
create sound effects, alarms, melodies, and more.
• Buzzers can be found in alarm devices,
computers, timers and confirmation of user input
such as a mouse click or keystroke.
• converting electronic vibrations into speaker
pulses which vibrate the air.
• Ex: Arduino to play “Twinkle Twinkle Little
Star”
•For this tutorial you will
need:Arduino uno
•Breadboard
•Buzzer/piezo speaker
•100 Ohm resistor
Computer networks unit III CHAPTER of frameworks
const int buzzer = 9; //buzzer to arduino pin 9
void setup()
{
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an
output
}
void loop()
{
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
Using Sensors and Actuators with
Arduino
Sensors: Sensor is a device used for the
conversion of physical events or characteristics
into the electrical signals. capturing data from
the physical world.
This is a hardware device that takes the input
from environment and gives to the system by
converting it.
Types of Sensors
 Accelerometer
 Light sensor
 Sound sensor
 Pressure sensor
 Temperature sensor
 IR sensor
 Ultrasonic sensor
 humidity sensor
 PIR sensor
 Water detector sensor
 Light distance sensor
Actuator: Actuator is a device that converts the
electrical signals into the physical events or
characteristics.
It takes the input from the system and gives
output to the environment.
Ex: motors and heaters
Interfacing IR Sensor Module with Arduino
An infrared proximity sensor or IR Sensor is
an electronic device that emits infrared lights to
sense some aspect of the surroundings and can
be employed to detect the motion of an object.
This sensor is very common in the electronic
industry and if you’ve ever tried to design an
obstacle avoidance robot or any other
proximity detection-based system.
• The IR sensor has a 3-pin connector that
interfaces it to the outside world.
Computer networks unit III CHAPTER of frameworks
• The working of the IR sensor module is very
simple, it consists of two main components:
the first is the IR transmitter section and the
second is the IR receiver section. In the
transmitter section, IR led is used and in the
receiver section, a photodiode is used to
receive infrared signal and after some signal
processing and conditioning, you will get the
output.
int IRSensor = 9; // connect IR sensor module to Arduino pin D9
int LED = 13; // connect LED to Arduino pin 13
void setup( )
{
Serial.begin(115200); // Init Serial at 115200 Baud Rate.
Serial.println("Serial Working"); // Test to check if serial is
working or not
pinMode(IRSensor, INPUT); // IR Sensor pin INPUT
pinMode(LED, OUTPUT); // LED Pin Output
}
void loop( )
{
int sensorStatus = digitalRead(IRSensor); // Set the GPIO as Input
if (sensorStatus == 1) // Check if the pin high or not
{
// if the pin is high turn off the onboard Led
digitalWrite(LED, LOW); // LED LOW
Serial.println("Motion Detected!"); // print Motion Detected! on the serial monitor window
}
else
{
//else turn on the onboard LED
digitalWrite(LED, HIGH); // LED High
Serial.println("Motion Ended!"); // print Motion Ended! on the serial monitor window
}
}
Humidity sensor with Arduino
 Humidity: Humidity is the amount of water in the
surrounding air.
 Humidity Sensor (DHT22)
 The DHT-22 (also named as AM2302) is a digital-
output.
 Humidity is the water vapor around you mixed with
air.
 It is measured in per cents.
Computer networks unit III CHAPTER of frameworks
#include <dht22.h>
#define DHT22PIN 4
dht22 DHT22;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println();
int chk = DHT22.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT22.humidity,
2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT22.temperature,
2);
delay(2000);
}
Water Level Sensor Interface with Arduino
Water Level Sensor measure the water
level(detect the presence of water.)
The Water Level Sensor has ten exposed
copper traces.
 five of which are power traces and the
remaining five are sense traces.
These traces are interlaced so that there is one
sense trace between every two power traces.
Normally, power and sense traces are not
connected, but when immersed in water, they
are bridged.
Computer networks unit III CHAPTER of frameworks
Computer networks unit III CHAPTER of frameworks
#define sensorPower 7
#define sensorPin A0
// Value for storing water level
int val = 0;
void setup()
{
// Set D7 as an OUTPUT
pinMode(sensorPower, OUTPUT); // Set to LOW so no power
flows through the sensor
digitalWrite(sensorPower, LOW);
Serial.begin(9600);
}
void loop()
{
//get the reading from the function below and print it
Int level = readSensor();
Serial.print("Water level: ");
Serial.println(level);
delay(1000); }
//This is a function used to get the reading
int readSensor()
{
digitalWrite(sensorPower, HIGH);
// Turn the sensor ON
delay(10); // wait 10 milliseconds
val = analogRead(sensorPin); // Read the analog value form sensor
digitalWrite(sensorPower, LOW); // Turn the sensor OFF
return val; // send current reading
}
Ultrasonic sensor with Arduino
 Sensors are widely used for detecting devices by
approximating their distance from the source.
 example of a sensor is the HC-SR04
 ultrasonic sensor which uses the SONAR technique
for the sensing purpose.
 The main feature of this sensor is to mimic the nature
of bats and therefore predict the distance of objects
without actually establishing contact with the device.
Working of the Ultrasonic Sensor
• The Ultrasonic Sensor works on the principle of
reflection.
• The sensor is used to emit waves known as
ultrasound with a frequency of 40 KHz.
• The transmitted wave moves in a straight line path
and gets obstructed by an object if present.
• After being obstructed, the wave reflects and is
detected by the sensor.
• The time of transmission and reflection of the wave
is noticed and the distance of the object is
calculated using the speed-time formula. s= 2d/t
 Connect a wire to supply Vcc with 5V to the
appropriate pin on Arduino.
 Make a ground-to-ground connection from GND to
GND on Arduino.
 Connect the trigger i.e. Trig to any pin on Arduino
like pin 8.
 Connect the Echo to any pin on Arduino like pin 9.
Computer networks unit III CHAPTER of frameworks
const int trigPin = 9;
const int echoPin = 10;
float duration,
distance;
void setup()
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin,
HIGH);
distance =(duration*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance);
delay(100);
}
const int pingPin = 8;
const int echoPin = 9;
void setup()
{
Serial.begin(9600);
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches =microsecondsToInches(duration);
cm =microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println(); delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long
microseconds)
{
return microseconds / 29 / 2;
}
Accelerometer Interface with Arduino
 Accelerometers is the device capable of detecting
changes in motion in the form of acceleration.
 It can also measure the vibration of the structure.
 Accelerometers are widely used in low-power, low-cost
motion and tilt sensing applications such as mobile
devices, gaming systems, disk drive protection, image
stabilization, and sports and health devices.
 Ex: ADXL320, ADXL321, ADXL322, ADXL330
 It can measure not only static acceleration caused by
gravity, but also dynamic acceleration caused by
motion, shock, or vibration.
Computer networks unit III CHAPTER of frameworks
Computer networks unit III CHAPTER of frameworks
 Connect the VCC pin to the Arduino’s 5V pin and the
GND pin to the Arduino’s Ground pin. Connect the
X, Y, and Z outputs to Arduino’s analog pins A0, A1,
and A2.
 To get accurate results, we need to change the analog
reference (AREF) voltage on the Arduino. This is
accomplished by connecting the Arduino’s 3.3V pin
to the AREF pin.
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
void setup()
{
Serial.begin(9600);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop() {
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
delay(100);
}
Arduino - PIR Sensor
 PIR sensors allow you to sense motion.
 They are used to detect whether a human has moved
in or out of the sensor’s range.
 They are commonly found in appliances and gadgets
used at home or for businesses.
 They are often referred to as PIR, "Passive Infrared",
"Pyroelectric", or "IR motion" sensors.
 PIRs are made of pyroelectric sensors, a round metal
can with a rectangular crystal in the center, which can
detect levels of infrared radiation.
Computer networks unit III CHAPTER of frameworks
#define pirPin 2;
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
}
• void PIRSensor()
• {
• if(digitalRead(pirPin) == HIGH)
• {
• if(lockLow)
• {
• PIRValue = 1;
• lockLow = false;
• Serial.println("Motion detected."); delay(50); } takeLowTime = true;
• }
• if(digitalRead(pirPin) == LOW)
• { if(takeLowTime)
• {
• lowIn = millis();
• takeLowTime = false;
• }
• if(!lockLow && millis() - lowIn > pause)
• {
• PIRValue = 0;
• lockLow = true;
• Serial.println("Motion ended.");
• delay(50);
• }
• }
• }

More Related Content

Similar to Computer networks unit III CHAPTER of frameworks (20)

DOCX
Arduino embedded systems and advanced robotics
Shubham Bhattacharya
 
PDF
Arduino-workshop.computer engineering.pdf
AbhishekGiri933736
 
PPTX
Arduino intro.pptx
SanthanaMari11
 
PPTX
Tinkercad Workshop PPT, Dept. of ECE.pptx
JayashreeSelvam5
 
PDF
Arduino workshop sensors
Jhonny Wladimir Peñaloza Cabello
 
PPTX
Robotics and Automation Using Arduino
ABHISHEKJAISWAL282
 
PPTX
sensors.pptx
ParthaSarathi208940
 
PDF
introductiontoarduino-111120102058-phpapp02.pdf
HebaEng
 
PPTX
Arduino with brief description of sensorsppt.pptx
BhuvanaN12
 
PDF
02 Sensors and Actuators Understand .pdf
engsharaf2025
 
PDF
Lab2ppt
Zhentao Xu
 
PDF
Iot for smart agriculture
Atit Patumvan
 
PPTX
ARDUINO Presentation1.pptx
SourabhSalunkhe10
 
PPT
IoT Basics with few Embedded System Connections for sensors
saritasapkal
 
PDF
Embedded system course projects - Arduino Course
Elaf A.Saeed
 
PPTX
INTRODUCTION TO ARDUINO and sensors for arduino.pptx
Jo Mebs
 
PPTX
Arduino tutorial A to Z
Md. Asaduzzaman Jabin
 
PPT
01 Intro to the Arduino and it's basics.ppt
pindi2197
 
PDF
INT4073 L07(Sensors and AcutTORS).pdf
MSingh88
 
PPTX
Lecture2- Smart Parking Assistant using Arduino
HassanKhan180094
 
Arduino embedded systems and advanced robotics
Shubham Bhattacharya
 
Arduino-workshop.computer engineering.pdf
AbhishekGiri933736
 
Arduino intro.pptx
SanthanaMari11
 
Tinkercad Workshop PPT, Dept. of ECE.pptx
JayashreeSelvam5
 
Arduino workshop sensors
Jhonny Wladimir Peñaloza Cabello
 
Robotics and Automation Using Arduino
ABHISHEKJAISWAL282
 
sensors.pptx
ParthaSarathi208940
 
introductiontoarduino-111120102058-phpapp02.pdf
HebaEng
 
Arduino with brief description of sensorsppt.pptx
BhuvanaN12
 
02 Sensors and Actuators Understand .pdf
engsharaf2025
 
Lab2ppt
Zhentao Xu
 
Iot for smart agriculture
Atit Patumvan
 
ARDUINO Presentation1.pptx
SourabhSalunkhe10
 
IoT Basics with few Embedded System Connections for sensors
saritasapkal
 
Embedded system course projects - Arduino Course
Elaf A.Saeed
 
INTRODUCTION TO ARDUINO and sensors for arduino.pptx
Jo Mebs
 
Arduino tutorial A to Z
Md. Asaduzzaman Jabin
 
01 Intro to the Arduino and it's basics.ppt
pindi2197
 
INT4073 L07(Sensors and AcutTORS).pdf
MSingh88
 
Lecture2- Smart Parking Assistant using Arduino
HassanKhan180094
 

Recently uploaded (20)

PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Ad

Computer networks unit III CHAPTER of frameworks

  • 2. Pin Description of I2C Module • The term I2C stands for “Inter Integrated Circuits”. • It is normally denoted as IIC or I squared C or even as 2- wire interface protocol (TWI). • I2C is a synchronous communication protocol, means both the devices that are sharing the information must share a common clock signal. • It has only two wires, SDA (serial data) and SCL to share information, out of which SCL(serial clock ) is used for the clock signal and SDA is used for sending and receiving data.
  • 3. • It is very useful IC and can be used in LED signs boards, displays, Key pads, Industrial control, etc. • There are 8 I/O pins, 3 pins (A0, A1, A2) for I2C bus address and SDA, SCL pins.
  • 6. #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x20, 16, 2); // Format -> (Address,Width,Height ) void setup( ) { lcd.init( ); // initialize the lcd lcd.backlight (); // Turn on the Backlight }
  • 7. void loop( ) { lcd.clear( ); // Clear the display buffer lcd.setCursor(0, 0); // Set cursor (Column, Row) lcd.print("Hello"); // print "Hello" at (0, 0) lcd.setCursor(0,1); // Set cursor (Column, Row) lcd.print("Geek"); // print "Geek" at (0, 1) delay(100); }
  • 8. Buzzer with Arduino • By interfacing a buzzer with Arduino, you can create sound effects, alarms, melodies, and more. • Buzzers can be found in alarm devices, computers, timers and confirmation of user input such as a mouse click or keystroke. • converting electronic vibrations into speaker pulses which vibrate the air. • Ex: Arduino to play “Twinkle Twinkle Little Star”
  • 9. •For this tutorial you will need:Arduino uno •Breadboard •Buzzer/piezo speaker •100 Ohm resistor
  • 11. const int buzzer = 9; //buzzer to arduino pin 9 void setup() { pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output } void loop() { tone(buzzer, 1000); // Send 1KHz sound signal... delay(1000); // ...for 1 sec noTone(buzzer); // Stop sound... delay(1000); // ...for 1sec }
  • 12. Using Sensors and Actuators with Arduino Sensors: Sensor is a device used for the conversion of physical events or characteristics into the electrical signals. capturing data from the physical world. This is a hardware device that takes the input from environment and gives to the system by converting it.
  • 13. Types of Sensors  Accelerometer  Light sensor  Sound sensor  Pressure sensor  Temperature sensor  IR sensor  Ultrasonic sensor  humidity sensor  PIR sensor  Water detector sensor  Light distance sensor
  • 14. Actuator: Actuator is a device that converts the electrical signals into the physical events or characteristics. It takes the input from the system and gives output to the environment. Ex: motors and heaters
  • 15. Interfacing IR Sensor Module with Arduino An infrared proximity sensor or IR Sensor is an electronic device that emits infrared lights to sense some aspect of the surroundings and can be employed to detect the motion of an object. This sensor is very common in the electronic industry and if you’ve ever tried to design an obstacle avoidance robot or any other proximity detection-based system.
  • 16. • The IR sensor has a 3-pin connector that interfaces it to the outside world.
  • 18. • The working of the IR sensor module is very simple, it consists of two main components: the first is the IR transmitter section and the second is the IR receiver section. In the transmitter section, IR led is used and in the receiver section, a photodiode is used to receive infrared signal and after some signal processing and conditioning, you will get the output.
  • 19. int IRSensor = 9; // connect IR sensor module to Arduino pin D9 int LED = 13; // connect LED to Arduino pin 13 void setup( ) { Serial.begin(115200); // Init Serial at 115200 Baud Rate. Serial.println("Serial Working"); // Test to check if serial is working or not pinMode(IRSensor, INPUT); // IR Sensor pin INPUT pinMode(LED, OUTPUT); // LED Pin Output }
  • 20. void loop( ) { int sensorStatus = digitalRead(IRSensor); // Set the GPIO as Input if (sensorStatus == 1) // Check if the pin high or not { // if the pin is high turn off the onboard Led digitalWrite(LED, LOW); // LED LOW Serial.println("Motion Detected!"); // print Motion Detected! on the serial monitor window } else { //else turn on the onboard LED digitalWrite(LED, HIGH); // LED High Serial.println("Motion Ended!"); // print Motion Ended! on the serial monitor window } }
  • 21. Humidity sensor with Arduino  Humidity: Humidity is the amount of water in the surrounding air.  Humidity Sensor (DHT22)  The DHT-22 (also named as AM2302) is a digital- output.  Humidity is the water vapor around you mixed with air.  It is measured in per cents.
  • 23. #include <dht22.h> #define DHT22PIN 4 dht22 DHT22; void setup() { Serial.begin(9600); } void loop() { Serial.println(); int chk = DHT22.read(DHT11PIN); Serial.print("Humidity (%): "); Serial.println((float)DHT22.humidity, 2); Serial.print("Temperature (C): "); Serial.println((float)DHT22.temperature, 2); delay(2000); }
  • 24. Water Level Sensor Interface with Arduino Water Level Sensor measure the water level(detect the presence of water.) The Water Level Sensor has ten exposed copper traces.  five of which are power traces and the remaining five are sense traces. These traces are interlaced so that there is one sense trace between every two power traces.
  • 25. Normally, power and sense traces are not connected, but when immersed in water, they are bridged.
  • 28. #define sensorPower 7 #define sensorPin A0 // Value for storing water level int val = 0; void setup() { // Set D7 as an OUTPUT pinMode(sensorPower, OUTPUT); // Set to LOW so no power flows through the sensor digitalWrite(sensorPower, LOW); Serial.begin(9600); }
  • 29. void loop() { //get the reading from the function below and print it Int level = readSensor(); Serial.print("Water level: "); Serial.println(level); delay(1000); } //This is a function used to get the reading int readSensor() { digitalWrite(sensorPower, HIGH); // Turn the sensor ON delay(10); // wait 10 milliseconds val = analogRead(sensorPin); // Read the analog value form sensor digitalWrite(sensorPower, LOW); // Turn the sensor OFF return val; // send current reading }
  • 30. Ultrasonic sensor with Arduino  Sensors are widely used for detecting devices by approximating their distance from the source.  example of a sensor is the HC-SR04  ultrasonic sensor which uses the SONAR technique for the sensing purpose.  The main feature of this sensor is to mimic the nature of bats and therefore predict the distance of objects without actually establishing contact with the device.
  • 31. Working of the Ultrasonic Sensor • The Ultrasonic Sensor works on the principle of reflection. • The sensor is used to emit waves known as ultrasound with a frequency of 40 KHz. • The transmitted wave moves in a straight line path and gets obstructed by an object if present. • After being obstructed, the wave reflects and is detected by the sensor. • The time of transmission and reflection of the wave is noticed and the distance of the object is calculated using the speed-time formula. s= 2d/t
  • 32.  Connect a wire to supply Vcc with 5V to the appropriate pin on Arduino.  Make a ground-to-ground connection from GND to GND on Arduino.  Connect the trigger i.e. Trig to any pin on Arduino like pin 8.  Connect the Echo to any pin on Arduino like pin 9.
  • 34. const int trigPin = 9; const int echoPin = 10; float duration, distance; void setup() { pinMode(trigPin,OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); } void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance =(duration*.0343)/2; Serial.print("Distance: "); Serial.println(distance); delay(100); }
  • 35. const int pingPin = 8; const int echoPin = 9; void setup() { Serial.begin(9600); } void loop() { long duration, inches, cm; pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(10); digitalWrite(pingPin, LOW); pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); inches =microsecondsToInches(duration); cm =microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); } long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; }
  • 36. Accelerometer Interface with Arduino  Accelerometers is the device capable of detecting changes in motion in the form of acceleration.  It can also measure the vibration of the structure.  Accelerometers are widely used in low-power, low-cost motion and tilt sensing applications such as mobile devices, gaming systems, disk drive protection, image stabilization, and sports and health devices.  Ex: ADXL320, ADXL321, ADXL322, ADXL330  It can measure not only static acceleration caused by gravity, but also dynamic acceleration caused by motion, shock, or vibration.
  • 39.  Connect the VCC pin to the Arduino’s 5V pin and the GND pin to the Arduino’s Ground pin. Connect the X, Y, and Z outputs to Arduino’s analog pins A0, A1, and A2.  To get accurate results, we need to change the analog reference (AREF) voltage on the Arduino. This is accomplished by connecting the Arduino’s 3.3V pin to the AREF pin.
  • 40. const int groundpin = 18; // analog input pin 4 -- ground const int powerpin = 19; // analog input pin 5 -- voltage const int xpin = A3; // x-axis of the accelerometer const int ypin = A2; // y-axis const int zpin = A1; // z-axis (only on 3-axis models) void setup() { Serial.begin(9600); pinMode(groundpin, OUTPUT); pinMode(powerpin, OUTPUT); digitalWrite(groundpin, LOW); digitalWrite(powerpin, HIGH); }
  • 41. void loop() { // print the sensor values: Serial.print(analogRead(xpin)); // print a tab between values: Serial.print("t"); Serial.print(analogRead(ypin)); // print a tab between values: Serial.print("t"); Serial.print(analogRead(zpin)); Serial.println(); // delay before next reading: delay(100); }
  • 42. Arduino - PIR Sensor  PIR sensors allow you to sense motion.  They are used to detect whether a human has moved in or out of the sensor’s range.  They are commonly found in appliances and gadgets used at home or for businesses.  They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.  PIRs are made of pyroelectric sensors, a round metal can with a rectangular crystal in the center, which can detect levels of infrared radiation.
  • 44. #define pirPin 2; int calibrationTime = 30; long unsigned int lowIn; long unsigned int pause = 5000; boolean lockLow = true; boolean takeLowTime; int PIRValue = 0; void setup() { Serial.begin(9600); pinMode(pirPin, INPUT); }
  • 45. • void PIRSensor() • { • if(digitalRead(pirPin) == HIGH) • { • if(lockLow) • { • PIRValue = 1; • lockLow = false; • Serial.println("Motion detected."); delay(50); } takeLowTime = true; • } • if(digitalRead(pirPin) == LOW) • { if(takeLowTime) • { • lowIn = millis(); • takeLowTime = false; • } • if(!lockLow && millis() - lowIn > pause) • { • PIRValue = 0; • lockLow = true; • Serial.println("Motion ended."); • delay(50); • } • } • }