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

Northern Technical University

Technical College / Kirkuk


Electronic and Control Techniques Eng. Dept.
Third Stage

MICROCONTROLLER LAB MANUAL


USING THE ARDUINO BOARD

2021 Edition

Prepared by
Dr. Abdulrahman Ikram Siddiq
Contents

Exp. No. Title Page

1 Digital Output 3

2 Digital Input 4

3 Digital I/O 5

4 Serial I/O 6

5 Analog Input 7

6 Load Driving 8

7 Analog Output – PWM 9

8 Light Sensor 10

9 LCD Interfacing 11

10 Heat Sensor 14
Arduino UNO Board Briefly

Component Explanations
Analog input pins – pins (A0-A5) that take-in analog values to be converted to be
represented with a number range 0-1023 through an Analog to Digital Converter (ADC).
ATmega328 chip – 8-bit microcontroller that processes the sketch you programmed.
Built-in LED – an on board LED to pin 13.
Crystal Oscillator – clock that has a frequency of 16MHz
DC Jack – where the power source (AC-to-DC adapter or battery) should be connected.
It is limited to input values between 6-20V but recommended to be around 7-12V.
Digital I/O pins – input and output pins (0-13) of which 6 of them (3, 5, 6, 9, 10 and
11) also provide PWM (Pulse Width Modulated) output by using the analogWrite()
function. Pins (0 (RX) and 1 (TX)) are also used to transmit and receive serial data.
ICSP Header – pins for “In-Circuit Serial Programming” which is another method of
programming.
ON indicator – LED that lights up when the board is connected to a power source.
Power Pins – pins that can be used to supply a circuit with values VIN (voltage from
DC Jack), 3.3V and 5V.
Reset Button – a button that is pressed whenever you need to restart the sketch
programmed in the board.
USB port – allows the user to connect with a USB cable the board to a PC to upload
sketches or provide a voltage supply to the board. This is also used for serial
communication through the serial monitor from the Arduino software.

1
Integrated Development Environment (IDE):

 Once the board is installed, it’s time to open the Arduino IDE.
 It is fairly simple when compared to larger desktop C language
development systems.

2
THIRD Digital Output MICROCONTROLLER
STAGE Experiment Number (1) LABORATORY

Objective: To learn how to implement digital output from the Arduino board.
Instructions: The software of this experiment requires the following instructions:
(pinMode, digitalWrite, and delay). See the instruction reference book.
Equipment:
 Arduino UNO board
 LDEs
 220 resistors

Procedure:
1. Connect the circuit of Fig.1.
2. Write a program to:
 define pin 13 as a digital output line. Fig. 1
 make the LED blink every 1 second.
3. Modify the circuit of Fig.1 to have 2 output LEDs on pins 8 and 9, and write
a program to make them blink complementarily every 1 second.
Discussion:
1. What is the roll of the 220 resistor? Can we just remove it?
2. Design and write a program for an Arduino based traffic light control
system for the traffic junction below.

3
THIRD Digital Input MICROCONTROLLER
STAGE Experiment Number (2) LABORATORY

Objective: To learn how to implement digital input using the Arduino board.
Instructions: (digitalRead) See the instruction reference book.
Equipment:
 Arduino UNO board
 LDE
 Resistors 220 and 10
 Two pushbuttons
Procedure:
1. Connect the circuit of Fig.1.
2. Write a program to output the state of pin 2 on pin 13.
3. Modify the circuit of Fig.1 and write a program to read the state of two
input switches sw1 and sw2. When sw1 is pressed, pin 13 becomes 1.
When sw2 is pressed, pin 13 becomes 0.

Fig. 1

Discussion:
1. What is the difference between pulled-up and pulled-down input pins?
2. Repeat step 2 of the procedure using a pulled-up input.

4
THIRD Digital I/O MICROCONTROLLER
STAGE Experiment Number (3) LABORATORY

Objective: To implement an Arduino based simple digital I/O system.


Instructions: (if statement) See the instruction reference book.
Equipment:
 Arduino UNO board
 LDEs
 Resistors
 Pushbuttons
Procedure:
1. Draw the detailed circuit diagram of the system shown in Fig.1, using
pulled-down inputs and LEDs, and then connect it.
2. Write a program such that the system operates according to the table
below.
Inputs Output
Pin2 Pin3 Pin4 Pin9 pin10
1 0 0 0 0
0 1 0 0 1
0 0 1 1 0
otherwise 1 1 Fig. 1

Discussion:
Design and write a program for the system shown in Fig. 2, such that the output
LED is turned ON when the decimal representation of the 4-bit input code is
greater or equal to 8. Otherwise, the output LED is turned OFF.

Fig. 2

5
THIRD Serial I/O MICROCONTROLLER
STAGE Experiment Number (4) LABORATORY

Objective:
To learn how to implement serial I/O between the Arduino board and the PC
using the serial monitor graphical user interface (GUI).

Instructions:
(Serial.begin, Serial.print, Serial.println, and Serial.write). See the instruction
reference book.

Equipment:
 Arduino UNO board
 PC

Procedure:
1. Connect the Arduino card to the PC through the USB cable.
2. Open the serial monitor GUI.
3. Write a program to send the following data to the PC through the serial
port. Observe the output on the serial monitor GUI.
data type
427, 61, 92 integers
a, b, A, C, g characters
Hello string
4. Write a program to receive a binary value X (0 or 1) from the serial monitor
GUI. If X=1, then turn pin 13 ON. Otherwise, (X=0) turn pin 13 OFF.

Discussion:
Write a program to:

1. Print the phrase "Enter the average" on the serial monitor GUI.
2. Receive an average X, ( X ) from the serial monitor GUI.
3. If the average X 50, then turn pin 13 ON. Otherwise, (X 50), then pin 13
is turned OFF.
4. Repeat steps 1-3.

6
THIRD Analog Input MICROCONTROLLER
STAGE Experiment Number (5) LABORATORY

Objective:
To learn how to implement analog input using the Arduino board.
Instructions:
(analogRead, and map). See the instruction reference book.
Equipment:
 Arduino UNO board
 A variable resistance
Procedure:
1. Connect the circuit of Fig.1.
2. Write a program to read the analog voltage on the AN0 pin, and display it
on the serial monitor GUI every 1 second.
3. Repeat step 2 with scaling the analog voltage readings to the range (0-5)V.
4. Repeat step 3 using a different baud rate.

Fig. 1
Discussion:
Design and write the program for an Arduino based system to read two analog
signals continuously. Pin 13 is ON when Sig1>Sig2. Otherwise, pin 13 is OFF.

7
THIRD Load Driving MICROCONTROLLER
STAGE Experiment Number (6) LABORATORY

Objective:
To learn how to interface loads to the Arduino board.
Equipment:
 Arduino UNO board
 npn transistor
 DC motor
 DC power supply
Theory:
 When the load requires an amount of current greater than that can be
supplied by the output pins of the Arduino card, then a driving circuit must
be used.
 The driving circuit connects/disconnects the load to an external power
supply under the control of an Arduino output pin.
 This switching action is implemented by using a transistor or a relay.
Procedure:
1. Connect the circuit of Fig.1.
2. Write a program to turn the DC motor ON and OFF every 1 second.
3. Connect the circuit of Fig. 2, and repeat step 2.

Fig. 1 Fig. 2

Discussion:
1. Compare between using transistors and relays from the driving capability,
size, and cost points of view.
2. Design and write a program for an Arduino based system that controls the
ON/OFF switching of an AC lamp using a switch.

8
THIRD Analog Output (PWM) MICROCONTROLLER
STAGE Experiment Number (7) LABORATORY

Objective:
To learn how to implement analog output from the Arduino board in the form of
Pulse Width Modulation (PWM).
Theory:

For a square wave, the duty cycle is defined as: .

A PWM signal is a variable duty cycle signal.


When the duty cycle is zero, then the average
output is 0 V. When the duty cycle is 100%,
then the average output is at its maximum
value (+5V in Arduino). As the duty cycle
increases from 0 to 100%, the average output voltage increases, and vice versa.
Instructions:
(analog.Write). See the instruction reference book.
Equipment:
 Arduino UNO board
 LDE
 220 resistor
 potentiometer
Procedure:
1. Connect the circuit of Fig.1.
2. Write a program to read the input analog signal
and use it to control the intensity of the LED.
3. Display the intensity as a percentage (%) on the
serial monitor GUI.
Fig. 1
Discussion:
Design and write the program of an Arduino based dc motor speed control using a
potentiometer.

9
THIRD Light Sensor MICROCONTROLLER
STAGE Experiment Number (8) LABORATORY

Objective: To learn how to interface a resistive photo sensor to the Arduino


board.
Equipment:
 Arduino UNO board
 Photo and ordinary resistance
Procedure:
1. Connect the circuit of Fig.1.
2. Write a program to read the analog input value in the cases of light and
darkness.
3. Display these values on the serial monitor GUI.
4. Modify the program to turn the LED ON when it is dark and turn the LED
OFF when there is light on the sensor.

Fig. 1

Discussion:
Design and write a program for an Arduino based system to automatically control
the switching of a house outer lighting using a photo resistance. Assume that
there are five AC lamps.

11
THIRD LCD Interfacing MICROCONTROLLER
STAGE Experiment Number (9) LABORATORY

Objective: To learn how to interface a 2x16 LCD in 4-bit mode to the Arduino
board.
Theory:
 The LCDs have a parallel interface, meaning that the microcontroller has to
manipulate several interface pins at once to control the display.

 The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit.


The 4-bit mode requires seven I/O pins from the Arduino, while the 8-bit
mode requires 11 pins. For displaying text on the screen, you can do almost
everything in 4-bit mode.

Equipment:
 Arduino Board
 LCD Screen (Hitachi HD44780 driver)
 10k Potentiometer + 220 Ohm resistor
 Breadboard + wires

Figure 1

11
Procedure:
1. Connect the circuit of Fig.1.
2. Write programs to:
 Display the phrase "Arduino Lab" on the lower row of the LCD and make it
appear and disappear every 1 second.
 Display a counter that starts at 0 and increments every 1 second.
Discussion:
1. Design and write a program to display a digital clock on the LCD.
2. Design and write a program for a 0 to +5V simple voltmeter using the
Arduino card with an LCD.

Connection

12
Code:

13
THIRD Heat Sensor MICROCONTROLLER
STAGE Experiment Number (10) LABORATORY

Objective: To learn how to interface a heat sensor to the Arduino board and
display its reading on an LCD.
Theory:
The LM35 is a low voltage IC which uses approximately +5VDC of power. This is
ideal because the Arduino's power pin gives out 5V of power. The IC has just 3
pins, 2 for the power supply and one for the analog output.

The output pin provides an analog voltage output


that is linearly proportional to the Celsius
(centigrade) temperature. Pin 2 gives an output of 1
millivolt per 0.1°C (10mV per degree). So to get the
degree value in Celsius, all that must be done is to
take the voltage output and divide it by 10- this give
out the value degrees in Celsius.

So, for example, if the output pin, pin 2, gives out a


value of 315mV (0.315V), this is equivalent to a
temperature of 31.5°C.

Equipment:
 Arduino UNO board
 LM35 heat sensor
 resistances
 LCD
Procedure:
1. Connect the circuit of Fig.1.
2. Write a program to read the analog input
from the sensor, convert it to temperature
in Celsius degrees, and display it on the LCD,
all every 100 ms.
Fig. 1
Discussion:
Design and write a program for a modification to the system of Fig. 1. Such that,
when the temperature is greater than 26 oC, then a fan is turned ON. Otherwise,
the fan is turned OFF.
14
Code

15

You might also like