Eee 444 (F)
Eee 444 (F)
EEE 444
Integrated Design Project II
Introduction
There are 2.5 hours allocated to a laboratory session in Integrated Design Project II. It is a
necessary part of the course where the attendance is compulsory. Here are some guidelines to
help the students perform the experiments and submit appropriate reports.
i. Students will read all the instructions carefully and carry them all out.
ii. Students will ask for a demonstration if s/he is unsure of anything.
iii. Student will record actual results and comment on them if the results are unexpected.
iv. Students will write full and suitable conclusions for each experiment.
v. If any student has any doubt about the safety of any procedure, s/he will contact the
demonstrator beforehand.
Arduino Uno
The Arduino Uno is a versatile and widely-used microcontroller board designed around the
ATmega328P microcontroller. It is an excellent choice for both beginners and experienced
developers in the field of electronics and embedded systems due to its user-friendly interface and
extensive community support.
Microcontroller ATmega328P
Operating Voltage 5V
Input Voltage (Recommended) 7 – 12 V
Input Voltage (Limit) 6 – 20 V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current Per I/O Pin 20 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 kB (ATmega328P) of which 0.5 kB used by
bootloader
SRAM 2 kB (ATmega328P)
EEPROM 1 kB (ATmega328P)
Clock Speed 16 MHz
Circuit Construction
Throughout these experiments we will be using Arduino Uno and basic components to construct
circuits. The steps for wiring a circuit should be completed in the following order described
below;
1. Turn off the power supply of Arduino before building the circuit.
2. Make sure to connect regulated supply voltage to the Vin and GND pins of the Arduino
if you are not using the USB cable or DC power jack.
3. Use different grounds for Arduino Uno and the other circuitry.
4. Never detach the ATmega328P IC from the board!!!
Code Uploading
1. Connect the Arduino Uno to the computer via the provided USB cable. Do not use external
cables for code uploading.
2. Open Arduino IDE. Create a new sketch and save it in an appropriate folder.
3. Write down your code. Make sure the code has no typos and syntax errors.
1. Power Supply Issues: The circuit might not turn on or not working properly. There can
be two possible reasons;
a. Insufficient Supply: If the Arduino is not receiving enough power, the circuit
might not work properly. This can happen if the power supply is weak or too
many peripherals are connected.
b. Incorrect Voltage: Supplying incorrect voltage to the Arduino can cause damage
to the board as well as to the circuit.
2. Faulty Connections: Arduino circuits are constructed using jumper wires most often. The
faulty connections can take place due to loosen wires, incorrect wiring, faulty connection
leads, etc.
3. Incorrect Pin Configuration: Incorrect pin assignments in the code can lead to unexpected
results. For example, setting a pin as an output when it should be an input. Again,
exceeding the current limits of the pin (usually 40 mA per pin) can cause damage to the
board.
The following regulations and safety rules must be followed in all concerned laboratory locations;
1. It is the duty of all concerned who use any electrical laboratory to take all reasonable steps
to safeguard the HEALTH and SAFETY of themselves and all other users and visitors.
2. Be sure that all equipment is properly working before using them for laboratory exercises.
Any defective equipment must be reported immediately to the lab instructors or lab
technical staff.
3. Students are allowed to use only the equipment provided in the experiment manual.
4. Power supply terminals connected to any circuit are only energized in the presence of the
instructor or laboratory staff.
5. Students should keep a safe distance from the circuit breakers, electric circuits, or any
moving parts during the experiment.
6. Avoid any part of your body from being connected to the energized circuit and ground.
7. Switch off the equipment and disconnect the power supplies from the circuit before
leaving the laboratory.
8. Observe cleanliness and proper laboratory housekeeping of the equipment and other
related accessories.
9. Wear proper clothes and safety gloves or goggles required in working areas that involve
fabrications of printed circuit boards, chemical process control systems, antenna
communication equipment, and laser facility laboratories.
10. Double-check your circuit connections specifically in handling electrical power machines,
AC motors, and generators before switching “ON” the power supply.
11. Make sure that the last connection to be made in your circuit is the power supply and the
first thing to be disconnected is also the power supply.
12. Equipment should not be removed, or transferred to any location without permission
from the laboratory staff.
13. Software installation in any computer laboratory is not allowed without permission from
the laboratory staff.
14. Computer games are strictly prohibited in the computer laboratory.
15. Students are not allowed to use any equipment without proper orientation and actual
hands-on equipment operation.
16. Smoking and drinking are strictly prohibited in the laboratory.
17. All these rules and regulations are necessary precautions in the Electrical Laboratory to
safeguard the students, laboratory staff, the equipment, and other laboratory users.
1.1 Objectives
1. To familiarize with Arduino IDE
2. To understand Arduino I/O interfacing using Arduino coding
1. Have a basic understanding of the Arduino IDE and the setup procedure of
Arduino Uno with the IDE
2. Understand the structure of the Arduino code
3. Know the operations of digital and analog I/O pins of Arduino and their
interfacing with LEDs, resistors, and potentiometers.
4. Write codes to blink LED arrays, fade LED brightness
1.3 Theory
Arduino is an open-source development board with integrated circuit components. The
brain of Arduino is a microcontroller. For Arduino Uno, it is the ATmega328P
microcontroller. The board provides the necessary circuit setup for the microcontroller
and creates provisions for the user to access the input and output pins of the
microcontroller and control them using simple codes. Arduino Uno has 14 digital pins
and 6 analog pins.
The simplest interfacing with these pins can be done using LEDs. LEDs are semiconductor
devices that emit light upon providing appropriate voltage at their anode and cathode
terminals. The anode of the LED is connected to one of the digital pins of the Arduino
Uno. Depending on the state of that particular digital pin, the LED will turn on or off. The
pin state, timing, and other controls are established through code uploaded to the Arduino
microcontroller using Arduino IDE.
The fading operation provides control over the brightness of the LED. Depending on the
input voltage supplied to the LED terminals, the brightness of the LED varies. The typical
output voltage of the digital pins is 5V. However, to apply a varying voltage at the LED
terminal, a PWM wave is generated at the digital pins (only pins 3, 5, 6, 9, 10, 11). The duty
cycle of the PWM is controlled by a potentiometer connected to one of the analog pins of
the Arduino. With the varying duty cycle, the average voltage of the PWM is reduced or
increased as per Equation 1.1, where 𝐷 is the duty cycle. This average voltage appears at
the digital pin and in terms controls the brightness of the LED.
const int ledPin = 11; // Define the pin where the LED is connected
void setup()
{
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
}
void loop()
{
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(1000); // Wait for 1000 milliseconds (1 second)
digitalWrite(ledPin, LOW); // Turn the LED off
delay(1000); // Wait for 1000 milliseconds (1 second)
}
void loop()
{
analogWrite(led, brightness); // set the brightness of pin 9
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255)
{ fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect
delay(3000);
}
void setup() {
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
}
void loop() {
// Read the potentiometer value (0 to 1023)
potValue = analogRead(potPin);
// Map the potentiometer value to a range suitable for PWM (0 to 255)
ledBrightness = map(potValue, 0, 1023, 0, 255);
// Set the LED brightness using PWM
analogWrite(ledPin, ledBrightness);
// Small delay to make the response smoother
delay(10);
}
1.7 Procedure
1. Place the LED on the breadboard.
2. Connect a 220 Ω resistor to the anode terminal of the LED (the longer lead).
3. Connect the other terminal of the resistor to the digital pin 11 of the Arduino Uno
via a jumper wire.
4. Connect the cathode terminal of the LED (the shorter lead) to the ground pin of
the Arduino Uno.
5. Cross-check the circuit with the one in Figure 1.1.
6. Connect the Arduino Uno to the computer using the USB cable.
7. Open the Arduino IDE and create a new sketch. Write the Code (a).
8. Select Arduino Uno as the board.
9. Save, compile, and upload the code to the Arduino Uno. Check the output.
10. Now do the same for Code (b) and check the output.
11. For the LED fading using a potentiometer, repeat steps 1-4, however, connect the
LED to digital pin 9 (PWM pin) of the Arduino Uno.
12. Place a 1 kΩ potentiometer on the breadboard. Connect the first and third pins of
the potentiometer to the 5V and GND pins of the Arduino Uno.
13. Connect the middle pin of the potentiometer to the A0 pin of the Arduino Uno.
Cross-check the circuit with the one in Figure 1.2.
14. Upload the Code (b) to Arduino Uno and check the output for different values of
the potentiometer.
2.1 Objectives
1. To understand the internal working principle of ultrasound sonar sensor
2. To interact with sensor modules using Arduino interfacing pins
2.3 Theory
Ultrasonic sonar sensors, also known as ultrasonic distance sensors or ultrasonic
rangefinders, are electronic devices used for measuring distances or detecting objects
within a certain range. These sensors work on the principle of echolocation, similar to how
bats and dolphins use sound waves to navigate and perceive their environment. The
sensor includes an ultrasonic transmitter that emits high-frequency sound waves
(ultrasonic waves) into the surrounding environment. These sound waves are inaudible
to the human ear, typically in the ultrasonic range (around 40 kHz or higher). It also
contains a receiver that is capable of detecting the reflected sound waves (echo) when they
bounce off an object. The time taken for the emitted sound wave to return to the sensor is
used to calculate the distance to the object.
The distance is measured as per Equation 2.1; where 𝑣 is the sound velocity in the medium
and 𝑡 is the duration of the HIGH state of the ECHO pin.
𝑑 = 0.5 × 𝑣 × 𝑡 (2.1)
void setup() {
// put your setup code here, to run once:
pinMode(Trig,OUTPUT);
pinMode(Echo,INPUT);
pinMode(LED,OUTPUT);
Serial.begin(9600); // baud rate
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(Trig,LOW);
delayMicroseconds(2); // ensures the TRIG pin is actually LOW
digitalWrite(Trig,HIGH);
delayMicroseconds(10); // creating the 10 microsecond pulse
digitalWrite(Trig,LOW);
if(distance>10)
{
digitalWrite(LED,HIGH);
}
else
{
digitalWrite(LED,LOW);
}
}
2.7 Procedure
1. Place the sonar sensor module on the breadboard.
2. Connect the VCC, GND, TRIG, and ECHO pins of the sensor with the 5V, GND,
digital pin 7, and digital pin 6 of Arduino Uno via jumper wires.
2. A distance-averaging system has been designed using a sonar sensor. The sensor
takes 20 distance values with an interval of 5s. If the average distance exceeds a
certain value, the system turns on an alarm. Write the code for this system.
3.1 Objectives
1. To understand the internal construction and working principle of PIR motion
sensor
2. To interface the PIR sensor with Arduino Uno for real-time motion sensing
3.3 Theory
Passive Infrared Sensor is used to automate systems based on the motion sensed around
them. The name suggests two key operating principles of this sensor. The term ‘Infrared’
indicates that the sensor operates utilizing the IR spectrum and the term ‘Passive’ suggests
that the sensor itself does not produce any IR spectrum. The underlying theory of PIR
sensors is based on the detection of changes in infrared radiation emitted by objects within
the range of the sensor.
The internal construction of PIR includes two pyroelectric materials that generate a
voltage signal when exposed to changes in IR radiation within its range. Objects emit IR
The PIR sensor has three pins among which two are the power pins and one is the output
pin, D0. Whenever the sensor detects a motion, D0 goes HIGH. There are two
potentiometers for sensitivity and time delay adjustments. The sensitivity controls the
detection range of the sensor (3m ~ 7m) whereas the time delay adjusts the duration of the
HIGH state of the D0 pin after the detection of a movement. It ranges from 3 seconds to 5
minutes.
void loop() {:
pir_state=digitalRead(pir);
if(pir_state==HIGH)
3.7 Procedure
1. Place the PIR sensor module on the breadboard.
2. Connect the VCC, GND, and D0 pins of the sensor with the 5V, GND, and digital
pin 7 of Arduino Uno via jumper wires.
3. Connect an LED with the digital pin 13 through a resistor of 220Ω.
4. Cross-check the circuit with Figure 3.4.
5. Open Arduino IDE and create a new sketch.
6. Write the given code in the sketch.
7. Select ‘Arduino Uno’ as the board.
8. Verify, compile, and upload the code to the Arduino.
9. Move your hand across the sensor module and check the output for single trigger
mode.
10. Move your hand across the sensor module and check the output for repeated
trigger mode.
11. Check the serial monitor of Arduino IDE for both steps 9 and 10.
4.1 Objectives
1. Configure 16x2 LCD to receive and display data from Arduino Uno
2. Display custom characters in LCD
1. Connect 16x2 LCD with Arduino Uno and configure different modes
2. Transmit data from Arduino Uno to LCD and perform different display operations
3. Access byte levels to display custom characters in LCD
4.3 Theory
Liquid Crystal Display (LCD) is a type of flat panel display that uses liquid crystals in its
primary form of operation typically found in smartphones, televisions, computer
monitors, and instrument panels. A 16x2 LCD has 2 lines with 16-character box in each
line. Again, each character box is made up of a 5x8 (column x row) pixel matrix. The
character boxes are identified by 𝐶𝑖 𝑅𝑗 where 𝐶 represents the column and 𝑖 ranges from 0
to 15. 𝑅 refers to the row and 𝑗 ranges from 0 to 1.
The LCD unit has 16 pins to interface it with the Arduino Uno among which 8 pins are
used for data transmission and the rest are used to configure the LCD in different modes.
The detailed pin descriptions are provided in Table 4.1.
Pin
Pin Pin Name Pin Description Pin Connection
No.
1 VSS/GND Ground Ground of MCU
Supplies power to the LCD
2 VCC/VDD +5V Supply +5V of MCU
Contrast Adjusts the contrast of the
3 VO Rheostat
Control LCD
LOW for Command Register
4 RS Register Select Digital pin of MCU
HIGH for Data Register
LOW for WRITE operation
5 R/W Read/Write Digital pin of MCU
HIGH for READ operation
Enable the READ/WRITE Digital pin of MCU
6 E Enable
operation (always HIGH)
4-bit or 8-bit data transmission
7-14 D0-D7 8-bit Data Pins Digital pins of MCU
between LCD and MCU
15 A Anode Power supply to the backlight +5V supply of MCU
16 C/K Cathode of the LCD Ground of MCU
This experiment will utilize 4-bit data transmission and so D4-D7 will be connected to the
Arduino Uno. Though 4-bit transmission mode is slower than 8-bit mode as data is
transmitted nibble by nibble in a 4-bit system, it reduces the number of connections
required.
To display custom characters in LCD, the byte-level matrices of the LCD need to be
accessed. An array referring to the custom character needs to be incorporated into the
code.
#include<LiquidCrystal.h>
const int RS= 11;
const int E=10;
const int D4=5;
const int D5=4;
const int D6=3;
const int D7=2;
LiquidCrystal lcd(RS,E,D4,D5,D6,D7); // Creates an LCD object. Parameters: (rs, enable, d4,
// d5, d6, d7)
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions
(width and height) of the display
}
void loop() {
// put your main code here, to run repeatedly:
lcd.print("Arduino"); // Prints "Arduino" on the LCD
delay(3000);
lcd.setCursor(2,1); // Sets the location at which subsequent text written to the LCD will be
// displayed
lcd.print("LCD Tutorial");
delay(3000); // 3 seconds delay
lcd.clear(); // Clears the display
lcd.blink(); //Displays the blinking LCD cursor
delay(4000);
lcd.setCursor(7,1);
delay(3000);
lcd.noBlink(); // Turns off the blinking LCD cursor
lcd.cursor(); // Displays an underscore (line) at the position to which the next character
//will be written
delay(4000);
lcd.noCursor(); // Hides the LCD cursor
lcd.clear(); // Clears the LCD screen
}
#include <LiquidCrystal.h>
// Array of bytes
// B stands for binary formatter and the five numbers are the pixels
void setup() {
// Initializes the interface to the LCD screen, and specifies the dimensions of the display
lcd.begin(16,2);
lcd.createChar(0, heart); // Create a custom character
lcd.createChar(1, smile);
lcd.createChar(2, lock);
lcd.createChar(3, character);
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(1, 1);
lcd.write(byte(0)); // Display the custom character 0, the heart
lcd.setCursor(5, 1);
lcd.write(byte(1));
lcd.setCursor(9, 1);
lcd.write(byte(2));
lcd.setCursor(13, 1);
lcd.write(byte(3));
}
5.1 Objectives
1. To interface a segment display with Arduino Uno without any driver circuit
2. To display numbers on the seven-segment display
5.3 Theory
A seven-segment display is commonly used for displaying numeric data in devices like
digital clocks and calculators. It has seven individual LEDs (labeled ‘a’ to ‘g’ in Figure 5.1)
along with a dot LED, ‘dp’. The LEDs can be accessed through individual pins. By
controlling the voltage states at these pins, numbers 0 to 9 can be displayed. Additionally,
some alphabets can be displayed. Depending on the shorted terminals of the LEDs, two
types of displays are available;
a. Common Cathode (CC): Here all the cathode terminals of the LEDs are
shorted and only one pin is available.
b. Common Anode (CA): Here all the anode terminals of the LEDs are shorted
and only one pin is available.
void setup() {
// Set all pins for the 7-segment display as output
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
void loop() {
for (int i = 0; i <= 9; i++) {
displayNumber(i);
delay(1000); // Delay for 1 second before changing number
}
}
6.1 Objectives
1. To control DC motor’s speed and direction of rotation using L298 Dual H-bridge
Motor Driver
6.3 Theory
Controlling of motors refers to controlling the speed of the motor as well as controlling
the direction of rotation of the motor. The direction of rotation of DC motors can simply
be achieved by swapping the input voltage polarity of the motor whereas the speed can
be controlled by altering the input voltage. Numerous applications require continuous
controlling of these parameters which might be tedious and complex if done manually. A
motor driver can provide the flexibility to control both the speed and direction
simultaneously.
The L298 Dual H-bridge motor driver is a single-board module having L298 IC integrated.
The motor driver has two in-built H-bridges to control the direction of rotation of motors.
With two H-bridges, two motors can be controlled simultaneously. For speed control, the
driver utilizes PWM.
Depending on the ON and OFF state of the switches, different modes of the bridge
are configured. The configuration table relating the modes of the H-bridge and
motor condition is provided in Table 6.1.
The number of states and complexities can be reduced easily. If a setup is done in
such a way that Q2 remains OFF when Q1 is ON and Q3 remains OFF when Q4 is
ON and vice-versa, then the H-bridge can be controlled using only two switches.
(b) Speed Control using PWM: By altering the duty cycle of the PWM signal, the
average voltage value of the signal can be varied. The PWM pins of the Arduino
Uno can be connected to the L298 driver to vary the speed of the motors.
The detailed pin descriptions are provided in Table 6.3. All the pins are broadly
categorized into four distinct sections; Output pins, Power pins, Speed control pins, and
Direction control pins.
void setup() {
// put your setup code here, to run once:
pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);
pinMode(In3, OUTPUT);
pinMode(In4, OUTPUT);
pinMode(EnA, OUTPUT);
pinMode(EnB, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Both motor forward
digitalWrite(In1, HIGH);
digitalWrite(In2, LOW);
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
digitalWrite(EnA, HIGH);
digitalWrite(EnB, HIGH);
delay(2000);
void setup() {
// put your setup code here, to run once:
pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);
pinMode(In3, OUTPUT);
pinMode(In4, OUTPUT);
pinMode(EnA, OUTPUT);
pinMode(EnB, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Both motor forward
digitalWrite(In1, HIGH);
digitalWrite(In2, LOW);
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
analogWrite(EnA, 150);
analogWrite(EnA, 230);
delay(2000);
}
6.7 Procedure
1. Construct the circuit as per section 6.5.
2. Remove the jumper heads that connect the ENA and ENB to the HIGH state pins.
3. Create a new sketch in Arduino IDE and write the code in the sketch.
4. Select ‘Arduino Uno’ as the board.
5. Verify, compile, and upload the code (a) in the Arduino.
6. Detach the USB connection as the Arduino is being powered up from the L298.
7. Connect a 12V power supply to the power jack of the motor controller.
8. Power up the circuit and observe the rotation direction of both of the motors.
9. Now, upload the code (b) in Arduino.
10. Change the duty cycle and observe the change in speed of the motors.
7.1 Objectives
1. To control servo motor in a multi-component system using Arduino
2. To set up servo configuration for required specifications
7.3 Theory
A servo motor is a type of motion control motor, often used in robotics, automation, and
RC systems. In contrast to DC motors, servo motors do not rotate 360 degrees
continuously. The direction of rotation of a servo motor can be precisely controlled. A
closed loop servo motor can rotate between 0° to 180° whereas the open loop servo motors
can rotate between 0° to 360°.
The SG-90 servo motor has a torque of 2.5 kg.cm which refers to the capacity of the rotor
to exert a force equivalent to 2.5 kg at a distance of 1cm from its axis. The internal
construction of the motor includes a DC motor, a motor controller, a gear train, and a
potentiometer. This assembly converts the high-speed low-torque output of the DC motor
to low-speed high-torque with precise control.
The microcontroller sends out PWM signals to the servo, and then the embedded board
in the servo receives the signals through the signal pin and controls the motor inside to
rotate. As a result, the motor drives the gear system and then motivates the shaft after
deceleration. The shaft and potentiometer of the servo are connected together. When the
shaft rotates, it drives the potentiometer, so the potentiometer outputs a voltage signal to
the embedded board. Then the board determines the direction and speed of rotation based
on the current position, so it can stop exactly at the right position as defined and hold
there.
#include <Servo.h>
int servoPin = 9; // Declare the Servo pin
Servo Servo1; // Create a servo object
void setup()
{
Servo1.attach(servoPin); // Attach the servo to the used pin number
}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(1000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
}
#include<Servo.h>
Servo myservo;
int potpin=A0;
int val;
void setup() {
// put your setup code here, to run once:
myservo.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
val=analogRead(potpin);
val=map(val,0,1023,0,180);
myservo.write(val);
delay(15);
}
7.7 Procedure
1. Place the potentiometer on the breadboard.
2. Connect the power pins of the potentiometer to the power pins of the Arduino.
Connect the middle pin of the potentiometer to pin A0 of Arduino.
3. Connect the red, brown, and orange wire of the servo motor to the 5V, GND, and
digital pin 9 of the Arduino, respectively.
4. Cross-check the circuit with Figure 7.4.
5. Open Arduino IDE and create e new sketch and write code (a).
6. Verify, compile, and upload the code to Arduino and observe the output.
7. Connect the oscilloscope probe to the digital pin 9 of the Arduino and observe the
waveshape.
8. Now, upload code (b) to the Arduino.
9. Rotate the knob of the potentiometer and observe the effect on the rotation.
8.1 Objectives
1. To interface 4x4 membrane keypad with Arduino Uno
2. To receive data from the keypad and control other processes
1. Explain the operational principle of a 4x4 membrane keypad and its interfacing
with Arduino
2. Read and visualize data received from the keypad
3. Control outputs based on the received data
8.3 Theory
A membrane keypad is a matrix arrangement of buttons used as an input device. A 4x4
keypad has 4 rows and 4 columns resulting in 16 distinct buttons. The buttons are
organized in a telephonic manner. The keypad utilizes the multiplexing principle to
reduce the number of I/O pins. Hence, all the buttons in a row are shorted and the same
is true for all the buttons in a column. This results in four terminals for four rows and four
terminals for four columns. When the button is pressed, one of the rows is connected to
one of the columns, allowing current to flow between them. When the key ‘4’ is pressed,
for instance, column 1 and row 2 are connected.
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//Create an object of keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();// Read the key
}
}
8.7 Procedure
1. Connect the R1, R2, R3, R4, C1, C2, C3, and C4 of the keypad to the digital pins 9,
8, 7, 6, 5, 4, 3, and 2 of Arduino, respectively.
2. Connect a red LED and a green LED via 220Ω resistors to digital pins 12 and 13,
respectively.
3. Open Arduino IDE and go to Sketch > Include Library > Manage Libraries and search
for ‘keypad’.
9.1 Objectives
1. To design a system combining different components that adhere to certain design
specifications
2. To optimize the design for minimum complexity
1. Combine different components (i.e. servo motor, LCD, sonar sensor, etc.) to design
a proximity door access control system
2. Establish appropriate data interchange between different components of the
system
9.3 Theory
A proximity door access control system utilizes an ultrasonic sensor for distance
measurement to detect the presence of an individual near the door. This system, built
using Arduino, enables automatic door opening when a person approaches within a
specified range, enhancing convenience and accessibility.
The ultrasonic sensor creates a specified range for the detection area. If anyone is within
this detection area, the system gets triggered by the sensor and activates the servo motors
attached to the door. The motors will rotate at a specified angle to make the door wide
open. An LCD connected to the system will display the door status and the distance. The
system has the following design considerations;
// Servo objects
Servo door1;
Servo door2;
// Distance thresholds
const int openThreshold = 50; // Distance (cm) to open doors
// Servo positions
void setup() {
// LCD setup
lcd.begin(16, 2); // Initialize a 16x2 LCD
lcd.print("System Starting...");
// Servo setup
door1.attach(2); // Connect servo 1 to pin 2
door2.attach(3); // Connect servo 2 to pin 3
door1.write(closedPos);
door2.write(closedPos);
delay(2000);
lcd.clear();
lcd.print("Distance System");
}
void loop() {
int distance = measureDistance();
9.7 Procedure
1. Construct the circuit as per the connection details provided in section 9.5 and
cross-check the circuit with Figure 9.1.
2. Open Arduino IDE and create a new sketch.
3. Write the given program and verify.
4. Compile the program and upload it to the Arduino.
5. Power up the circuit.
6. Observe the circuit output for different distances.
10.1 Objectives
1. To design a system combining different components that adhere to certain design
specifications
2. To optimize the design for minimum complexity
10.3 Theory
A single-digit calculator performs mathematical operations on single digits. That means
both the operands for the operation will be single digits. To implement this system with
Arduino, a keypad arrangement can be used. A user will input the first operand, operator,
second operand, and lastly the ‘enter/equal’ instruction. Each of the steps will be
displayed on an LCD.
In the keypad used in this experiment, ‘A’, ‘B’, ‘C’, ‘D’, ‘*’, and ‘#’ refer to the add, subtract,
multiply, divide, clear, and equal/enter operations, respectively. The significant part of
this program is to convert the ASCII characters to integer numbers and perform the
operations. This system can be designed for multi-digit input by using string or array
operations.
// Keypad configuration
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'C', '0', '=', '/'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {A3, A2, A1, A0}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.begin(16, 2); // Initialize a 16x2 LCD
lcd.setCursor(0, 0);
lcd.print("Calculator Ready");
delay(2000);
lcd.clear();
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key >= '0' && key <= '9') { // If a number is pressed
if (!isSecondNum) {
firstNum = key;
lcd.setCursor(0, 0);
lcd.print("First: ");
lcd.print(firstNum);
} else {
switch (operation) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = (float)num1 / num2;
} else {
lcd.clear();
lcd.print("Error: Div by 0");
delay(2000);
resetCalculator();
return;
}
break;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Result: ");
lcd.print(result);
delay(3000);
void resetCalculator() {
firstNum = '\0';
secondNum = '\0';
operation = '\0';
isSecondNum = false;
lcd.clear();
lcd.print("Cleared");
delay(1000);
lcd.clear();
}
10.7 Procedure
1. Connect the components as per the connection details given in Table 10.1 and
cross-check the circuit with Figure 10.1.
2. Open Arduino IDE and create a new sketch.
3. Write the given code and verify it.
4. Compile the code and upload it to the Arduino.
5. Press any number on the keypad.
6. Select the mathematical operator.
7. Press another number on the keypad.
8. Press the ‘#’ button that refers to the ‘=’ operation.
9. Observe the output
10. Observe the outputs for summation, subtraction, multiplication, and division.