Professional Documents
Culture Documents
Screenshot 2024-03-28 at 2.50.29 AM
Screenshot 2024-03-28 at 2.50.29 AM
2021 Edition
Prepared by
Dr. Abdulrahman Ikram Siddiq
Contents
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
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
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:
9
THIRD Light Sensor MICROCONTROLLER
STAGE Experiment Number (8) LABORATORY
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.
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.
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