Department of Electromechanical Engineering Workshop For Mechatronics
Department of Electromechanical Engineering Workshop For Mechatronics
1 / 38
Interfacing
1 Introduction
2 Display LED
3 Push button and LED with Arduino
Pull-up circuit
4 7-Segment Display
Programming 7 segment display without Library
Programming of 7-Segment Display Using SevSeg Library
5 Interfacing of Keys
Arduino Programming of Keypad
6 Liquid Crystal Display (LCD)
Temperature sensor and LCD
7 Analog Input Output
2 / 38
Introduction
Introduction
Interfacing is the process of connecting devices together so that
they can exchange the information and that proves to be easier
to write the programs. There are different type of input and out-
put devices as for our requirement such as LEDs, LCDs, 7segment,
keypad, motors and other devices.
Microcontroller Interfaces
4 / 38
Introduction
Microcontroller Interfaces
5 / 38
Display LED
Display LED
The common available LEDs have a 1.7v voltage drop that means
when we apply above 1.7V, the diode conducts. The diode needs
10mA current to glow with full intensity.
6 / 38
Display LED
7 / 38
Push button and LED with Arduino
8 / 38
Push button and LED with Arduino
The following figure is the protues and arduino code for push button
and LED with Arduino.
When your button is not pressed, the internal pull-up resistor con-
nects to 5 volts. This causes the arduino to report ”1” or HIGH.
When the button is pressed, the arduino pin is pulled to ground,
causing the arduino report a ”0”, or LOW.
9 / 38
Push button and LED with Arduino
Pull-up circuit
pull-up circuit
when the switch is open the voltage of the gate input is pulled up
to the level of Vin . when the switch is closed, the input voltage at
the gate goes to ground.
10 / 38
Push button and LED with Arduino
Pull-up circuit
RGB Programming
The RGB LED can emit different colors by mixing the 3 basic colors
red, green and blue. So it actually consists of 3 separate LEDs red,
green and blue packed in a single case.
That’s why it has 4 leads, one lead for each of the 3 colors and one
common cathode or anode depending of the RGB LED type. In this
tutorial I will be using a common cathode one.
11 / 38
Push button and LED with Arduino
Pull-up circuit
The cathode will be connected to the ground and the 3 anodes will
be connected through 220 Ohms resistors to 3 digital pins on the
Arduino Board that can provide PWM signal. We will use PWM for
simulating analog output which will provide different voltage levels
to the LEDs so we can get the desired colors.
12 / 38
Push button and LED with Arduino
Pull-up circuit
We will use PWM for simulating analog output which will provide
different voltage levels to the LEDs so we can get the desired colors.
13 / 38
Push button and LED with Arduino
Pull-up circuit
I will use the pins number 7, 6 and 5 and I will name them redPin,
greenPin and bluePin. In the setup section we need to define them
as outputs.
These values can vary from 0 to 255 which represents 100% duty
cycle of the PWM signal or maximum LED brightness.
14 / 38
Push button and LED with Arduino
Pull-up circuit
15 / 38
Push button and LED with Arduino
Pull-up circuit
So now in the loop function we will make our program which will
change the color of the LED each second.
In order to get red light on the LED we will call the setColor()
function and set value of 255 for the redValue argument and 0 for
the two others. Respectively we can get the two other basic colors,
green and blue.
For getting other colors we need to mix the arguments values. So for
example if set all 3 LEDS to maximum brightness we will get White
color and we will get a purple color if we set the following values to
the arguments: 170 redValue, 0 greenValue and 255 blueValue.
16 / 38
7-Segment Display
7-Segment Display
Seven segment display is the most basic electronic display. It consists
of eight LEDs which are associated in a sequence manner so as to
display digits from 0 to 9 when proper combinations of LEDs are
switched on. A 7-segment display uses seven LEDs to display digits
from 0 to 9 and the 8th LED is used for dot.
17 / 38
7-Segment Display
The following table shows the hex values used to display the
different digits.
19 / 38
7-Segment Display
Programming 7 segment display without Library
20 / 38
7-Segment Display
Programming 7 segment display without Library
21 / 38
7-Segment Display
Programming 7 segment display without Library
22 / 38
7-Segment Display
Programming of 7-Segment Display Using SevSeg Library
We will use the library called SevSeg to control the display. The
library works with single digit and multi-digit seven segment display.
You can download the library’s ZIP file from GitHub.
byte numDigits =1; this sets the number of digits on your display.
I am using a single digit display, so I set it to 1. if you are using a
four digit display, set this to 4.
24 / 38
7-Segment Display
Programming of 7-Segment Display Using SevSeg Library
25 / 38
7-Segment Display
Programming of 7-Segment Display Using SevSeg Library
26 / 38
Interfacing of Keys
Interfacing of Keys
Keypad is a widely used input device with lot of applications such
as telephone, computer, ATM, electronic lock etc. A keypad is used
to take input from the user for further processing. Here a 4 by 4
matrix keypad consisting of switches arranged in rows and columns
is interfaced to the microcontroller.
27 / 38
Interfacing of Keys
Initially all the rows are set to zero (’0’) by the controller and columns
are scanned to check if any key is pressed. In case of no key is pressed
the output of all columns will be high (’1’).
28 / 38
Interfacing of Keys
Arduino Programming of Keypad
29 / 38
Liquid Crystal Display (LCD)
LCD is very important device which is used for almost all auto-
mated devices such as washing machines, an autonomous robot,
power control systems and other devices. This is achieved by dis-
playing their status on small display modules like 7-seven segment
displays, multi segment LEDs etc. LCDs have reasonable price, eas-
ily programmable and they have no limitations of displaying special
characters.
32 / 38
Liquid Crystal Display (LCD)
33 / 38
Liquid Crystal Display (LCD)
Temperature sensor and LCD
where
Vout is the LM35 output voltage
T is the temperature in degree centigrade
The LM35 device has a very wide 4-V to 30-V power supply voltage
range, which makes it ideal for many applications
35 / 38
Liquid Crystal Display (LCD)
Temperature sensor and LCD
36 / 38
Analog Input Output
37 / 38
Analog Input Output
38 / 38