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

Arduino 3

The document provides a comprehensive overview of interfacing a Seven Segment Display (SSD) with Arduino, detailing its types (Common Cathode and Common Anode), how to display digits, and the necessary driving circuitry. It explains the importance of current limiting resistors to protect the LEDs and includes Arduino code examples for controlling the display. Additionally, it covers the registers and ports of the ATmega328 microcontroller used in Arduino for managing the SSD connections.

Uploaded by

Kshitij harsh
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Arduino 3

The document provides a comprehensive overview of interfacing a Seven Segment Display (SSD) with Arduino, detailing its types (Common Cathode and Common Anode), how to display digits, and the necessary driving circuitry. It explains the importance of current limiting resistors to protect the LEDs and includes Arduino code examples for controlling the display. Additionally, it covers the registers and ports of the ATmega328 microcontroller used in Arduino for managing the SSD connections.

Uploaded by

Kshitij harsh
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 82

Seven Segment Display (SSD)

Interfacing with Arduino


Agenda
• Introduction to Seven Segment Display
• Types of 7-Segment Display
• Common Cathode
• Common Anode
• Displaying Digital Digits
• Driving 7-Segment Display
• Interfacing 7-Segment Display to Arduino
• Ports and Registers of ATmega328
Introduction
• The 7-segment display, also written as “seven
segment display”, consists of seven LEDs arranged in
a rectangular fashion as shown in the Figure.
• Each of the seven LEDs is called a segment.
Introduction
• Each one of the seven LEDs in the display is given a positional segment which
is controlled by one pin.
• These LED pins are labeled a, b, c, d, e, f, and g representing each individual
LED.
• The other LED pins are connected together and wired to form a common pin.
• By forward biasing the appropriate pins of the LED segments, some segments
will be light and others will be dark allowing the desired character pattern of
the number to be generated on the display.
• This allows us to display each of the ten decimal digits 0 through to 9 or hexa
decimal numbers 0 through to F , on the same 7-segment display.
• An additional 8th LED is sometimes used within the same package thus
allowing the indication of a decimal point, (DP) when two or more 7-segment
displays are connected together to display numbers greater than ten.
Types of 7-Segment Displays
• The displays common pin is generally used to identify
which type of 7-segment display it is.
• As each LED has two connecting pins, one called the
“Anode” and the other called the “Cathode”.
• Therefore , there are two types of LED 7-segment
display:
– 1. Common Cathode (CC)
– 2. Common Anode (CA)
Common Cathode (CC)
• In the common cathode display,
– all the cathode connections of the LED segments are joined
together to logic “0″ or ground.
– The individual segments are illuminated by application of a
“HIGH”, or logic “1″ signal via a current limiting resistor to
forward bias the individual Anode terminals (a-g).
Common Anode (CA)
• In the common anode display,
– all the anode connections of the LED segments are joined
together to “HIGH”, or logic “1″.
– The individual segments are illuminated by application of a
logic “0″ or ground signal via a suitable current limiting
resistor to the Cathode of the particular segment (a-g).
Displaying Digital Digits
• Depending upon the decimal digit to be
displayed, the particular set of LEDs is forward
biased.
• The various digits from 0 through 9 can be
displayed using a 7-segment display as shown.
Displaying Digital Digits (Cont..)
• Table 1: Display decimal digits using the 7-segments (Common Cathode)

Decimal Digit G F E D C B A
0 0 1 1 1 1 1 1
1 0 0 0 0 1 1 0
2 1 0 1 1 0 1 1 A
F G B
3 1 0 0 1 1 1 1
4 1 1 0 0 1 1 0 E D C

5 1 1 0 1 1 0 1
6 1 1 1 1 1 0 1
7 0 0 0 0 1 1 1
8 1 1 1 1 1 1 1
9 1 1 0 1 1 1 1
Driving a 7-Segment Display
• Although a 7-segment display can be thought of as a single
display, it is still seven individual LEDs within a single package
and as such these LEDs need protection from over-current.
• LEDs produce light only when it is forward biased with the
amount of light emitted being proportional to the forward
current.
• This means that an LEDs light intensity increases in an
approximately linear manner with an increasing current.
• So this forward current must be controlled and limited to a safe
value by an external resistor to prevent damaging the LED
segments.
Driving a 7-Segment Display (Cont..)

• The forward voltage drop across a red LED segment is very low at
about 2-to-2.2 volts.
• To illuminate correctly, the LED segments should be connected to a
voltage source in excess of this forward voltage value with a series
resistance used to limit the forward current to a desirable value.
• Typically for a standard red colored 7-segment display, each LED
segment can draw about 15mA to illuminated correctly, so on a 5
volt digital logic circuit,
– the value of the current limiting resistor would be about 200Ω
(5v – 2v)/15mA, or
– 220Ω to the nearest higher preferred value.
Driving a 7-Segment Display (Cont..)

• So to understand how the segments of the display are connected


to a 220Ω current limiting resistor consider the circuit below.
Driving a 7-Segment Display (Cont..)

• In this example,
– the segments of a common anode display are illuminated using
the switches.
– If switch a is closed, current will flow through the “a” segment
of the LED to the current limiting resistor connected to pin a
and to 0 volts, making the circuit.
– Then only segment a will be illuminated.
– If we want the decimal number “4″ to
illuminate on the display, then switches
b, c, f and g would be closed to light the
corresponding LED segments.
Interfacing 7-Segment Display to Arduino

• The 7-Segment Display (shown in Figure below) can be interfaced to the


Arduino Uno Board as shown in the next two slides.
• Power supply of 5V DC is provided, either through Vcc1 pin or Vcc2 pin.,
with respect to a resister connected across.

Pin configuration of the 7-Segment


display with common anode
G F Vcc1 A B
CommonAnode(CA):
Com: Vcc=5V (through a Resistor)
A – G : Vcc=5V i.e. bibary ‘1’ => LEDs (A – G) will be OFF
A – G : Gnd=0V i.e. bibary ‘0’ => LEDs (A – G) will be ON
CommonCathode(CC):
Com: Gnd=0v (through a Resistor)
A – G : Vcc=5V i.e. bibary ‘1’ => LEDs (A – G) will be ON
A – G : Gnd=0V i.e. bibary ‘0’ => LEDs (A – G) will be OFF
E D Vcc2 C DP
Glowing the Led’s of 7-segment display
//Arduino sketch to test common anode 7 segment//
//Arduino pins from 6-12 are connected with a-g pins of common anode 7 segment display/
void setup() void loop()
{
{
// loop to turn leds of seven seg ON
// define pin modes for(int i=6;i<13;i++) //for_loop-1
{
pinMode(6,OUTPUT); //pin6-a led digitalWrite(i, LOW); //digitalWrite(6-12,LOW);
pinMode(7,OUTPUT); //pin7-b led delay(500); //500ms
}
pinMode(8,OUTPUT); //pin8-c led //delay(1000); //1sec delay
pinMode(9,OUTPUT); //pin9-d led // loop to turn leds of seven seg OFF
for(int i=6;i<13;i++) //for_loop-2
pinMode(10,OUTPUT); //pin10-e led {
digitalWrite(i, HIGH); //digitalWrite(6-12,HIGH);
pinMode(11,OUTPUT); //pin11-f led
delay(500); //0.5 seconds
pinMode(12,OUTPUT); //pin12-g led }
delay(1000); //1sec delay
} }
Glowing the Led’s of 7-segment display(Cont..)
//Arduino sketch to test common anode 7 segment//
//Arduino pins from 0-7 are connected with a-g pins of common anode 7 segment display//
void setup() void loop()
{
{
// loop to turn leds of seven seg ON
// define pin modes for(int i=0;i<7;i++) //for_loop-1
{
pinMode(0,OUTPUT); //pin0-a led digitalWrite(i, LOW); //digitalWrite(0-6,LOW);
pinMode(1,OUTPUT); //pin1-b led //delay(500); //500ms
}
pinMode(2,OUTPUT); //pin2-c led delay(1000); //1sec delay
pinMode(3,OUTPUT); //pin3-d led // loop to turn leds of seven seg OFF
for(int i=0;i<7;i++) //for_loop-2
pinMode(4,OUTPUT); //pin4-e led {
digitalWrite(i, HIGH); //digitalWrite(0-6,HIGH);
pinMode(5,OUTPUT); //pin5-f led
//delay(500); //500ms
pinMode(6,OUTPUT); //pin6-g led }
delay(1000); //1sec delay
} }
Display 0 and 1 on 7-segment display(Cont..)
//Arduino sketch to test common anode 7 segment//
//Arduino pins from 0-7 are connected with a-g pins of common anode 7 segment display//
void setup() void loop()
{
{ digitalWrite(0, LOW); // a-led ON
digitalWrite(1, LOW); // b-led ON
pinMode(0,OUTPUT); //pin0-a led digitalWrite(2, LOW); // c-led ON
digitalWrite(3, LOW); // d-led ON
pinMode(1,OUTPUT); //pin1-b led digitalWrite(4, LOW); // e-led ON
digitalWrite(5, LOW); // f-led ON
pinMode(2,OUTPUT); //pin2-c led digitalWrite(6, HIGH); // g-led OFF
digitalWrite(7, LOW); // dp-led ON
pinMode(3,OUTPUT); //pin3-d led delay(1000); //1sec delay
digitalWrite(0, HIGH); // a-led OFF
pinMode(4,OUTPUT); //pin4-e led digitalWrite(1, LOW); // b-led ON
digitalWrite(2, LOW); // c-led ON
pinMode(5,OUTPUT); //pin5-f led digitalWrite(3, HIGH); // d-led OFF
digitalWrite(4, HIGH); // e-led OFF
pinMode(6,OUTPUT); //pin6-g led digitalWrite(5, HIGH); // f-led OFF
digitalWrite(6, HIGH); // g-led OFF
pinMode(7,OUTPUT); //pin7-dp led digitalWrite(7, LOW); // dp-led ON
delay(1000); //1sec delay
} }
Proteus Design (CommonAnode)

Registers of ATmega328
• All the work of MCU happens through registers
(special memory locations)
– Registers on the Atmega328 are 8-bits wide
• The data direction register (DDRx) handles the data
directions for pins in PORTx
Registers of ATmega328 (Cont..)

Data Direction Register:


•If the bit is zero -> pin will be an input
– Making a bit to be zero == ‘clearing the bit’
•If the bit is one -> pin will be an output
– Making a bit to be one == ‘setting the bit’
•To change the data direction for a set of pins belonging
to PORTx at the same time:
1. Determine which bits need to be set and cleared in DDRx
2. Store the binary number or its equivalent (in an alternate
base, such as hex) into DDRx
Registers of ATmega328 (Cont..)

• For digital IO, the important registers are:


– DDRx
• Data Direction bit in DDRx register: i/p or o/p (read/write)
– PORTx
• PORTx data register: controls wether the pin is HIGH or LOW
(read/write)
– PINx
• PINx register: to read the status of INPUT pins (read only)
Ports of ATmega328
PORTD maps to Arduino digital pins 0 to 7

DDRD - The Port D Data Direction Register - read/write


PORTD - The Port D Data Register - read/write
PIND - The Port D Input Pins Register - read only
PORTB maps to Arduino digital pins 8 to 13 The two high bits (6 & 7) map to

the crystal pins and are not usable

DDRB - The Port B Data Direction Register - read/write


PORTB - The Port B Data Register - read/write
PINB - The Port B Input Pins Register - read only
PORTC maps to Arduino analog pins 0 to 5. Pins 6 & 7 are only accessible on

the Arduino Mini

DDRC - The Port C Data Direction Register - read/write


PORTC - The Port C Data Register - read/write
PINC - The Port C Input Pins Register - read only
Displaying Hexa-Decimal Values: 0 to F

//int CommonAnode[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,
0x48,0x03,0x46,0x21,0x06,0x0E};
int CommonCathode[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,
0x77,0x7C,0x39,0x5E,0x79,0x71};

void setup()
{
DDRD=B11111111; //pins 7 to 0, set port D as output i.e. pin-0 to A-led
//DDRD=0xFF; //pins 7 to 0 (port D), configured/set as output port
}
void loop()
{
for(int j=0;j<10;j++)
{
//PORTD= CommonAnode[j];
PORTD= CommonCathode[j]; // PORTD= CommonCathode[0]; => 0x3F -->’0’
delay(1000);
}
}
Proteus Design (CommonCathode)

LCD Interfacing with Arduino
Agenda
• Introduction to LCD
• LCD Interfacing (8-bit mode)
• LCD Interfacing (4-bit mode)
• LCD Library Commands
• Still message display on LCD
• Moving message display on LCD
• Custom message display on LCD
Introduction
• Liquid crystal displays (LCDs) offer a convenient and
inexpensive way to provide a user interface for a
project.
Introduction (Cont..)
Introduction (Cont..)
LCD Interfacing (8-bit mode)
int commandvalues[]={0x38,0x0E,0x0F,0x06,0x01,0xC5};
int displaymessage[]={‘L’,’O’,’V’,’E’,’L’,’Y’}; void setup()
void command(unsigned int x) {
{ DDRD=B11111111; //set port D as
output
PORTD=commandvalues[x];
pinMode(10,OUTPUT);
digitalWrite(10,LOW);
pinMode(9,OUTPUT);
digitalWrite(9,LOW);
pinMode(8,OUTPUT);
digitalWrite(8,HIGH);
}
delay(250);
void loop()
digitalWrite(8,LOW);
{
}
for(int x=0;x<=5;x++)
void lcddata1(unsigned int y)
{
{
command(x);
PORTD=displaymessage[y];
delay(250);
digitalWrite(10,HIGH);
}
digitalWrite(9,LOW);
for(int y=0;y<=5;y++)
digitalWrite(8,HIGH);
{
delay(250);
lcddata1(y);
digitalWrite(8,LOW);
delay(250);
}
}
LCD Interfacing (4-bit mode)
LCD Interfacing (4-bit mode)
// Arduino sketch to display: **Hello Students** in Line-0 and **Study Well** in Line-1 of LCD
#include <LiquidCrystal.h> // include the library code
//constants for the number of rows and columns in the LCD
const int numRows = 2; //2 is a decimal number
const int numCols = 16; //16 is a decimal number

//initialize the library with the numbers of the interface pins


LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LiquidCrystal lcd(Rs,En,D4,D5,D6,D7)
//LiquidCrystal LPU(12, 11, 5, 4, 3, 2); // LiquidCrystal lcd(Rs,En,D4,D5,D6,D7)

void setup()
{
lcd.begin(numCols, numRows); // lcd.begin(16, 2); //set up the LCD's number of columns and rows
}
void loop()
{
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print(" **Hello Students** "); //(note: line 0 is the 1st row, since counting begins with 0)
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print(“ **Study Well** "); //(note: line 1 is the 2nd row, since counting begins with 0)
}
LCD Library Commands
begin()

Description
Initializes the interface to the LCD screen, and specifies the dimensions (width
and height) of the display. begin()needs to be called before any other LCD
library commands.

Syntax

lcd.begin(cols, rows)

Parameters
lcd: a variable of type LiquidCrystal
cols: the number of columns that the display has
rows: the number of rows that the display has
LCD Library Commands (Cont..)
setCursor()

Description
Position the LCD cursor; that is, set the location at which subsequent text
written to the LCD will be displayed.

Syntax
lcd.setCursor(col, row)

Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
LCD Library Commands (Cont..)

write()

Description
Write a character to the LCD.

Syntax
lcd.write(data)

Parameters
lcd: a variable of type LiquidCrystal
data: the character to write to the display
LCD Library Commands (Cont..)

print()

Description
Prints text to the LCD.

Syntax

lcd.print(data)

Parameters
lcd: a variable of type LiquidCrystal
LCD Library Commands (Cont..)

cursor() noCursor()

Description: Description
Display the LCD cursor Hides the LCD cursor.
an underscore (line) at the
position to which the next
character will be written.
Syntax
Syntax lcd.noCursor()
lcd.cursor()
LCD Library Commands (Cont..)

noDisplay() display()

Description Description
Turns off the LCD display, without Turns on the LCD display, after it's been
losing the text currently shown on it. turned off with noDisplay(). This will
restore the text (and cursor) that was on
the display.

Syntax
Syntax
lcd.display()
lcd.noDisplay()
LCD Library Commands (Cont..)
setCursor()

Description
Position the LCD cursor; that is, set the location at which subsequent text written to
the LCD will be displayed.

Syntax
lcd.setCursor(col, row)

Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
LCD Library Commands (Cont..)

scrollDisplayLeft() scrollDisplayRight()

Description Description
Scrolls the contents of Scrolls the contents of
the display (text and the display (text and
cursor) one space to the cursor) one space to the
left. right.

Syntax Syntax
lcd.scrollDisplayLeft() lcd.scrollDisplayRight()
LCD Library Commands (Cont..)

leftToRight() rightToLeft()

Description Description
Set the direction for text written to the
Set the direction for text written to the
LCD to right-to-left (the default is left-
LCD to left-to-right, the default. This to-right). This means that subsequent
means that subsequent characters characters written to the display will
written to the display will go from left go from right to left, but does not
to right, but does not affect affect previously-output text.
previously-output text.
Syntax
Syntax lcd.rightToLeft()
lcd.leftToRight()
LCD Library Commands (Cont..)

clear()

Description
Clears the LCD screen and positions the cursor in the
upper-left corner.

Syntax
lcd.clear()

Parameters
lcd: a variable of type LiquidCrystal
Eg1. Still Message Display On LCD

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
lcd.print("hello, world!");
}
void loop()
{
lcd.setCursor(0,1);
delay(250);
}
Eg2. Moving Message Display On LCD
#include <LiquidCrystal.h>
char message[]={"Lovely Professional University"};
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void loop()
void setup() {
{ lcd.setCursor(0, 0);
lcd.begin(16, 2);
} for (int i = 0; i <= 30; i++)
{
lcd.print(message[i]);
delay(200);
if(i>16)
{
lcd.autoscroll();
}
}
}
Eg3. LCD Custom Message Display

• The LCD display has two lines of characters, 16


characters per line.
• Each character is composed of matrix of pixels size 5x8.
Eg3. LCD Custom Message Display (Cont..)

DDRAM Memory (Display Data RAM)


•Display data RAM (DDRAM) stores the information we
send to LCD in ASCII Code.
•For each letter there is a special code that represents it.
•For example, the letter A in ASCII code, “receives” a value
of 65 in base 10 or 01000001 in binary base, or 41 in the
base 16.
•The memory can contain up to 80 letters.
Eg3. LCD Custom Message Display (Cont..)

CGRAM Memory (Character Generator RAM)


•Using CGRAM memory the user can “build” and store their
own letters.
•For 5x8 dots, eight character patterns can be written,
•And for 5x10 dots, four character patterns can be written.
•The difference between the memories is that the DDRAM
memory displays on the screen the “ready” characters in
accordance with the ASCII code, while the CGRAM
memory displays the special characters that the user has
created.
Eg3. LCD Custom Message Display (Cont..)

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte customChar[8] = { byte customChar1[8] = {


0b11111, 0b11111,
0b00100, 0b00101,
0b00100, 0b01001,
0b11100, 0b10111,
0b10111, 0b10101,
0b11101, 0b10111,
0b00101, 0b01001,
0b00101 0b00101
}; };
Eg3. LCD Custom Message Display (Cont..)

void setup()
{
// create new custom characters
lcd.createChar(0, customChar);
lcd.createChar(1, customChar1);

// set up number of columns and rows


lcd.begin(16, 2);
lcd.write((byte)0);
lcd.write(0);
}
void loop()
{
}
DC Motor Interfacing With
Arduino
Agenda
• Introduction & Working principle
• H-Bridge Circuit  L293D/L298
• L293D versus L298
• L293D Motor Driver IC
• DC Motor Connections to L293D
• Arduino Connections to L293D
• Controlling Speed & Direction of DC Motor
• Arduino Sketch
Introduction & Working PrincipleMotor

• A motor is an electrical machine which converts


electrical energy into mechanical energy.
• "whenever a current carrying conductor is placed in
a magnetic field, it experiences a mechanical force".

• A DC motor (Direct Current motor) is the most


common type of motor. DC motors normally have
just two leads, one positive and one negative.
• If you connect these two leads directly to a battery,
the motor will rotate. If you switch the leads, the
motor will rotate in the opposite direction.
H Bridge Circuit  L293D/L298
• To control the direction of the spin of DC motor, without
changing the way that the leads are connected, you can
use a circuit called an H-Bridge.
• An H bridge is an electronic circuit that can drive the motor
in both directions.
• H-bridges are used in many different applications, one of
the most common being to control motors in robots.
• It is called an H-bridge because it uses four transistors
connected in such a way that the schematic diagram looks
like an "H“.
• You can use discrete transistors to make this circuit, but for
this lecture, we will be using the L293D/L298 H-Bridge IC.
L293D versus L298
• In L293D all four input- output lines are independent,
while in L298, a half H driver cannot be used
independently, full H driver has to be used.
• Protective Diodes against back EMF are provided
internally in L293D but must be provided externally
in L298.
• The L298 can control the speed and direction of DC
motors & stepper motors and can control two motors
simultaneously.
• Its current rating is 2A for each motor. At these
currents, however, you will need to use heat sinks.
L293D Motor Driver IC
DC Motor connections to L293D
Arduino connections to L293D
Controlling Speed & Direction of DC Motor

• We will connect the Arduino to IN1 (pin 5), IN2 (pin 7),
and Enable1 (pin 6) of the L293d IC. Pins 5 and 7 are
digital.,
• i.e. ON or OFF inputs, while pin 6 needs a pulse-width
modulated (PWM) signal to control the motor speed.
Arduino Sketch

const int pwm = 3 ; //initializing pin 3 as pwm

const int in_1 = 8 ;


const int in_2 = 9 ; //For providing logic to L293d IC to choose the direction of

the DC motor

void setup()
{
pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output

pinMode(in_1,OUTPUT) ; //Logic pins are also set as output

pinMode(in_2,OUTPUT) ;
}
Arduino Sketch (Cont..)

void loop()
{
//For Clock wise motion , in_1 = High , in_2 = Low

digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,LOW) ;
analogWrite(pwm,255) ; //2^8= 256 (0-255)
delay(3000) ; //3sec.
/*setting pwm of the motor to 255 we can change the speed of rotaion by chaning pwm input but we are only using

arduino so we are using highest value to driver the motor */


Arduino Sketch (Cont..)
//For brake

digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000); //1sec
//For Anti Clock-wise motion - IN_1 = LOW , IN_2 = HIGH

digitalWrite(in_1,LOW) ;
digitalWrite(in_2,HIGH) ;
delay(3000);
//For brake
//3sec
digitalWrite(in_1,LOW) ;
digitalWrite(in_2,LOW) ;
delay(1000) ; //1sec
}
Servo Motor Interfacing With
Arduino
Agenda
• Introduction
• Circuit connections
• Arduino sketch
Introduction

• A servo motor allows a precise control of the angular


position, velocity, and acceleration. It’s like you’re at
the steering wheel of your car.
• You control precisely the speed of the car and the
direction.

• These servos are essential parts if we need to control


the position of objects, rotate sensors, move arms and
legs, drive wheels and tracks, and more.
Introduction (Cont..)

• Inside the micro servo, you will find the pieces like
they are showing in the image below.
• The top cover hosts the plastic gears while the middle
cover hosts a DC motor, a controller, and the
potentiometer.
Introduction (Cont..)

• The servo motor has three leads, with one more than
a DC motor.

• Each lead has a color code.

• So you have to connect the brown wire from the


micro servo to the GND pin on the Arduino.
• Connect the red wire from the servo to the +5V on
the Arduino.
• And finally, connect the orange wire from the SG90
servo to a digital pin (pin 9) on the Arduino.
Circuit connections
Arduino Sketch
#include <Servo.h> void loop()
Servo myservo; // create servo object to control a servo {
//Servo lpu; val = analogRead(potpin); // reads the
value of the potentiometer (value between 0 and 1023)
int potpin = A0; // analog pin used to connect the
potentiometer val = map(val, 0, 1023, 0, 180); // scale it
to use it with the servo (value between 0 and 180)
int val; // variable to read the value from the analog pin
myservo.write(val);
void setup()
// sets the servo position according to the scaled value
{
delay(100); //0.1 seconds delay
myservo.attach(9); // attaches the servo on pin 9 to
the servo object
// waits for the servo to get there
}
}
DHT11 Sensor Interfacing with Arduino UNO
• DHT11 sensor measures and provides humidity and
temperature values serially over a single wire.
• It can measure relative humidity in percentage (20
to 90% RH) and temperature in degree Celsius in
the range of 0 to 50°C.
• It has 4 pins; one of which is used for data
communication in serial form.
• DHT11 sensor uses resistive humidity measurement
component, and NTC temperature measurement
component.
DHT11 Specifications

• Ultra-low cost
• 3 to 5V power and I/O
• 2.5mA max current use during conversion
(while requesting data)
• Good for 20-80% humidity readings with 5%
accuracy
• Good for 0-50°C temperature readings ±2°C
accuracy
DHT22 Specifications
• Low cost
• 3 to 5V power and I/O
• 2.5mA max current use during conversion
(while requesting data)
• Good for 0-100% humidity readings with 2-5%
accuracy
• Good for -40 to 125°C temperature readings
±0.5°C accuracy
• Before you can use the DHT11 on the Arduino, you’ll need to install the
DHTLib library.

• https://github.com/adafruit/DHT-sensor-library

• It has all the functions needed to get the humidity and temperature
readings from the sensor.

• It’s easy to install, just download the DHTLib.zip and open up the Arduino
IDE.

• Then go to Sketch>Include Library>Add .ZIP Library and select the


DHTLib.zip file.
#include <Adafruit_Sensor.h> void loop()
{
#include "DHT.h"
delay(2000);
#define DHTPIN 2 float h = dht.readHumidity();
#define DHTTYPE DHT11 float t = dht.readTemperature();
DHT dht(DHTPIN, DHTTYPE); Serial.print("Humidity: \t" );
void setup() Serial.print(h);
Serial.print(" %\n");
{
delay(500);
Serial.begin(9600);
Serial.print("Temperature: \t");
Serial.println("DHT11 test!"); Serial.print(t);
dht.begin(); Serial.print(" *C \n");
} }
Our next topic of discussion is
“Sample Questions of ETP”
Thank You & Queries?

You might also like