0% found this document useful (0 votes)
86 views

UNIT 3_part 3 sensor n actuator integration with arduino_SRD

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

UNIT 3_part 3 sensor n actuator integration with arduino_SRD

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Integration of Sensor with Arduino

Sensors
• Electronic elements
• Converts physical quantity/ measurements into
electrical signals
• Can be analog or digital
Types of Sensors
Some commonly used sensors:
• Temperature
• Humidity
• Compass
• Light
• Sound
• Accelerometer
Digital Humidity and Temperature
Sensor(DTH)
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 Supported by Arduino

• 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()
(Here we are using Arduino ATMEGA 2560
IT has 4 UART)
Connection

• Connect pin 1 to the 3.3


V supply.
• Data pin (pin 2) can be
connected to any digital
pin, here 12
• Pin 3 is left open
• Connect pin 4 to the
ground (GND) pin of
the board
Installing the DHT Sensor Library
Go to Sketch ->
Include Library ->
Manage Library
Installing the DHT Sensor Library
• Search for DHT
SENSOR
• Select the “DHT
sensor library”
• install it
Program: Reading temperature and humidity
using DHT sensor
#include <DHT.h>;
DHT dht(8, DHT22); //Initialize DHT sensor
float humidity; //Stores humidity value
float temperature; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht.begin(); //must be written
}
Reading temperature and humidity
using DHT sensor……
void loop()
{ humidity = dht.readHumidity();
temperature= dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("%, Temperature: ");
Serial.print(temperature);
Serial.println(" Celsius");
delay(2000); / /Delay of 2 seconds
}
Screen shot of written sketch
Steps
• 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
Output
Integration of Actuator with Arduino

Actuator

• Mechanical/Electro-mechanical device
• Converts energy into motion
• Mainly used to provide controlled motion to
other components
Basic Working Principle

• 4 Uses different combination of various


mechanical structures like screws, ball
bearings, gears to produce motion.
Types of Motor Actuators

• Servo motor
• Stepper motor
• Hydraulic motor
• Solenoid
• Relay
• AC motor
Servo Motor

• High precision motor


• Provides rotary motion 0
to 180 degree
3 wires in the Servo motor.
✓ Black or the darkest one
is Ground
✓ Red is for power supply
✓ Yellow for signal pin
Servo Library on Arduino

• Arduino provides the library-SERVO to


operate the servo motor.
• Create an instance of servo to use it in the
sketch
Servo motor Program
• #include <Servo.h> • voidloop(){
• int servoPin = 12; • ServoDemo.write(0);
• Servo ServoDemo; • delay(1000);
• void setup() • ServoDemo.write(90);
• { • delay(1000);
• ServoDemo.attach(serv • ServoDemo.write(180);
oPin); • delay(1000);
• } • }
Servo motor Program
• #include <Servo.h> //Including the servo library for the program
• int servoPin = 12;
• Servo ServoDemo; // Creating a servo object /instance
• void setup()
• { ServoDemo.attach(servoPin); // The servo pin must be
attached to the servo before it can be used

• }
Servo motor Program …
• voidloop()
• {
• ServoDemo.write(0); //Servo moves to 0 degrees

• delay(1000);
• ServoDemo.write(90); // Servo moves to90 degrees

• delay(1000);

• ServoDemo.write(180); // Servo moves to 180 degrees


• delay(1000);
• }
Important points about sketch
• Create an instance of Servo .
• The instance must be attached to the pin
before being used in the code .
• Write() function takes the degree value and
rotates the motor accordingly
Connection

• Connect the Ground of the servo to the ground


of the Arduino board.
• Connect the power supply wire to the 5V pin
of the board.
• Connect the signal wire to any digital output
pin (we have used pin 8).
Connection(image)
Board Set up
• Connect the board to the PC .
• Set the port and board type .
• Verify and upload the code
Output
• The motor turns 0, 90
and 180 degrees with a
delay of 1 second each.
Some other functions available with the Servo
library:
• Knob()
• Sweep()
• write()
• writeMicroseconds()
• read()
• attached()
• detach()

You might also like