computer-architecture
computer-architecture
Computer
Architecture
Lab Manual
Computer
Architecture
Lab Manual
Compiled by: Razia Qamar
CID: Semester: _
StudentID:
StudentName:
InstructorName:
INDEX
Lab
Date Particulars Instructor Marks
Signature
Lab 1: Introduction to Computer Architecture /
Development Boards
Table of Contents
LAB: 01 ................................................................................................................................................... 1
Introduction to Computer Architecture / Development Boards........................................................... 1
OBJECTIVES: Introducing Introduction to Computer Architecture /Development Boards ............... 1
Computer Architecture ........................................................................................................................ 1
Microcontroller ................................................................................................................................... 1
Previous Microcontrollers Disadvantages ......................................................................................... 1
Development Boards ......................................................................................................................... 1
Beagle Board ..................................................................................................................................... 2
Raspberry PI ...................................................................................................................................... 2
Features ............................................................................................................................................. 2
ARDUINO .......................................................................................................................................... 3
The best way to describe an ARDUINO is with a few examples ...................................................... 3
Why ARDUINO?......................................................................................................................... 3
ARDUINO Uno ........................................................................................................................... 4
Specs ............................................................................................................................................. 4
ARDUINO IDE (Web+ Desktop) ................................................................................................ 4
Libraries ......................................................................................................................................... 4
Sensors .......................................................................................................................................... 5
Next Lab Materials ......................................................................................................................... 5
Purchase if you want (Not Necessary) .......................................................................................... 5
LAB: 02 ...................................................................................................................................................... 6
Introduction to ARDUINO Board -LED, Button ............................................................................... 6
OBJECTIVES: Introducing ARDUINO board with its syntax and setup ................................... 6
Sketch ......................................................................................................................................... 7
Some Basic Circuit Components ............................................................................................... 7
Resistors..................................................................................................................................... 7
Resistor Reading ........................................................................................................................ 7
Breadboard ................................................................................................................................. 8
LED ............................................................................................................................................. 8
Get an ARDUINO board and USB cable ................................................................................... 8
Download the ARDUINO environment....................................................................................... 8
Install the drivers ........................................................................................................................ 9
Select your board ...................................................................................................................... 9
Select your serial port................................................................................................................. 9
Uploading the program ............................................................................................................. 10
Blink Example........................................................................................................................... 10
Hardware .................................................................................................................................. 10
CODE ....................................................................................................................................... 10
FADE Example ......................................................................................................................... 10
Hardware .................................................................................................................................. 10
CONCEPT ................................................................................................................................ 11
Circuit Diagram ......................................................................................................................... 12
CODE ....................................................................................................................................... 12
CONCEPT ................................................................................................................................ 12
HIGHIMPEDENCE................................................................................................................... 12
Pull Up / Pull Down Resistors .................................................................................................. 13
Button Example ........................................................................................................................ 13
Hardware .................................................................................................................................. 13
BUTTON Circuit Diagram ......................................................................................................... 13
CODE ....................................................................................................................................... 13
INPUT_PULL UP Example ...................................................................................................... 13
Hardware .................................................................................................................................. 13
Circuit Diagram ......................................................................................................................... 13
CODE ........................................................................................................................................... 13
LAB: 03 ................................................................................................................................................... 14
Interfacing 16x2 LCD with ARDUINOUNO...................................................................................... 15
OBJECTIVES: the main object is to interfacing 16x2 LCD with ARDUINO to display data ... 15
Hardware .................................................................................................................................. 15
Instruments ............................................................................................................................... 15
Basic Theory............................................................................................................................. 16
Experiment ............................................................................................................................... 16
Circuit ....................................................................................................................................... 16
Schematic ............................................................................................................................................... 17
Example Code Of HelloWorld .................................................................................................. 10
SCROLLLCDTEXT................................................................................................................... 18
Scroll Display Left () and scroll Display Right()methods .......................................................... 19
CIRCUITDIAGRAM .................................................................................................................. 19
CODE ....................................................................................................................................... 19
LAB: 04 ................................................................................................................................................. 20
Introduction to Analog Channel &Using Temperature SensorLM35 ............................................... 20
HARDWARE ............................................................................................................................................ 21
Instruments ............................................................................................................................................ 21
Code ......................................................................................................................................... 22
Downloaded by Okorie Promise (okoriechinedup@gmail.com)
lOMoARcPSD|12193041
LAB: 05 .................................................................................................................................................... 23
INTERFACING SONAR (RANGE) SENSORWITHARDUINO........................................................ 23
OBJECTIVES: How to measure the distance using ultrasonic sensor .................................... 23
HARDWARE............................................................................................................................. 23
Instruments ............................................................................................................................... 24
Wire connecting direct as following .......................................................................................... 24
Difference between 3 Pin And 4 Pin Ultrasonic Sensor .......................................................... 24
EXAMPLECODE(4-PIN) .......................................................................................................... 25
3-PINCONNECTION ................................................................................................................ 26
EXAMPLECODE(3-PIN) .......................................................................................................... 27
LAB: 06 ..................................................................................................................................................... 29
Controlling LED with a Remote Control using IRreceiver ............................................................... 29
OBJECTIVES:ControllingLED(Anydevice)withaRemoteControlusingIRreceiver ..................... 29
HARDWARE............................................................................................................................. 29
CIRCUITDIAGRAM .................................................................................................................. 30
CIRCUITDIAGRAM ............................................................................................................................ 31
ARDUINO Code ....................................................................................................................... 32
LAB: 07 ..................................................................................................................................................... 32
Make a REAL TIME CLOCK USING RTC DS3231MODULE......................................................... 33
OBJECTIVES:Makeareal-timeclockusingrtcds3231moduleandshowtimeon16*2LCD .................... 33
HARDWARE............................................................................................................................. 33
Software ................................................................................................................................... 33
Overview ................................................................................................................................... 33
Working Explanation ................................................................................................................ 34
CIRCUITDIAGRAM .................................................................................................................. 35
CONNECTIONS ....................................................................................................................... 35
LCD Connections ..................................................................................................................... 36
Setting the Time in the RTC ..................................................................................................... 37
Uploading the Time Sketch ...................................................................................................... 38
LAB: 08 ................................................................................................................................................ 39
Detecting Motion using PIRMOTIONSENSOR ............................................................................... 39
OBJECTIVES: Detecting Motion using PIR MOTION SENSOR and indicating motion by
lighting up Led……………………………………………………………………………………….39
HARDWARE............................................................................................................................. 39
Instruments ............................................................................................................................... 39
Working Explanation ................................................................................................................ 40
PINOUT .................................................................................................................................... 40
ARDUINO Code ....................................................................................................................... 40
Downloaded by Okorie Promise (okoriechinedup@gmail.com)
lOMoARcPSD|12193041
LAB: 09 ................................................................................................................................................. 41
Keypad Interfacing with ARDUINO Uno .......................................................................................... 41
OBJECTIVES: Keypad Interfacing with ARDUINO Uno and showing characters on LCD screen 41
HARDWARE............................................................................................................................. 41
Instruments ............................................................................................................................... 41
Working Explanation ................................................................................................................ 42
CONNECTIONS ....................................................................................................................... 42
CIRCUITDIAGRAM .................................................................................................................. 43
LAB: 10 ................................................................................................................................................. 44
TO INTERFACE DC-MOTORS WITHARDUINOUNO .................................................................... 44
OBJECTIVES: To demonstrate how to interface three types of motor i.e. DC, Stepper and
Servo motor…………………………………………………………………………………………..44
HARDWARE............................................................................................................................. 45
Instruments ............................................................................................................................... 45
BASICTHEORY........................................................................................................................ 46
DC Motor .................................................................................................................................. 46
Stepper Motor ........................................................................................................................... 46
Servo Motor .............................................................................................................................. 47
EXPLORATION ........................................................................................................................ 47
DC Motor .................................................................................................................................. 48
Commonly use for small application Dual Hbridge .................................................................. 48
Stepper Motor ........................................................................................................................... 49
WORKING PRINCIPLE OFSERVOMOTOR ........................................................................... 49
Sample Code: To control single DC motor using H-bridge L298d .......................................... 49
Sample Code: For Stepper motorwithULN2003/ULN2008 ...................................................... 49
Sample Code: For Servo Motor ............................................................................................... 49
LAB: 11 .................................................................................................................................................. 50
INTERFACING ARDUINO WITH RELAY TO CONTROL HIGHVOLTAGEDEVICES ................... 50
OBJECTIVES: Learn how to Control High Voltage Devices using the ARDUINO Board ...... 50
HARDWARE............................................................................................................................. 50
Software ................................................................................................................................... 50
Introduction ............................................................................................................................... 51
High Voltage Warning .............................................................................................................. 51
Relay Module............................................................................................................................ 51
What is NO NC and COM in relay? ......................................................................................... 52
Circuit Diagram ......................................................................................................................... 52
Code ......................................................................................................................................... 52
LAB: 12 .................................................................................................................................................... 53
INTERFACING ARDUINOWITHESP8266 .................................................................................. 53
OBJECTIVES: Programming ESP8266 ESP-01with ARDUINO ............................................ 53
HARDWARE............................................................................................................................. 53
Introduction ............................................................................................................................... 54
ARDUINO Setup ...................................................................................................................... 54
ESP8266Modes ....................................................................................................................... 55
InstallingESP8266Platform ...................................................................................................... 56
References ............................................................................................................................... 57
LAB: 13 .................................................................................................................................................... 58
Introduction to Bluetooth Serial Communication ............................................................................. 58
OBJECTIVES: The main objective of the lab is to understand how the communication system
works and discus serial and parallel communication 58
HARDWARE............................................................................................................................. 58
Instruments ............................................................................................................................... 58
BASICTHEORY........................................................................................................................ 58
USART ..................................................................................................................................... 59
UART ........................................................................................................................................ 59
Data Transmission ................................................................................................................... 59
Standard BAUD Rates ............................................................................................................. 59
Lab-1
Course Title: Computer Architecture Introduction to Computer Architecture
LAB: 01
Introduction to Computer Architecture / Development Boards
Computer Architecture
Computer architecture is a specification detailing how a set of software and hardware technology
standards interact to form a computer system or platform. In short, computer architecture refers to how a
computer system is designed and what technologies it is compatible with.
Microcontroller
A microcontroller (MCU) is a small computer on a single integrated circuit.
Microcontrollers are used in automatically controlled products and devices, such as automobile engine control
systems, implantable medical devices, remote controls, office machines, appliances, power tools, toys and
other embedded systems. By reducing the size and cost compared to a design that uses a separate
microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control
even more devices andprocesses.
Development Boards
Intel Edison
Lab-1
Course Title: Computer Architecture Introduction to Computer Architecture
The ARDUINO breakout board has 20 digital input/output pins, including four pins as PWM outputs,
Six analog inputs, one UART (Rx/Tx), and one I2C pin. Edison runs on a distribution of embedded Linux called
Yocto. Certified by Microsoft, AWS, and IBM for cloud connectivity.
Beagle Board
The Beagle Bone Black is one of the industry’s favorite development platforms.
With 512MB of RAM, 4GB of onboard flash, a Cortex A8 processor and tons of
hardware support, The Beagle Bone Black Industrial takes it a step further by
adding industrial temperature capabilities, meaning this board will run at
temperatures anywhere from -40 degrees Celsius all the way up to blistering +85
degreesCelsius
Raspberry PI
Raspberry Pi is the most popular platform used by many hobbyists and hackers. Even non-technical users
depend on it for configuring their digital media systems and surveillance cameras. The recently launched
Raspberry Pi 3 included built-in WiFi and Bluetooth. Based on a Broadcom BCM2837 SoC with a 1.2 GHz
64-bit quad-core ARM Cortex-A53 processor and 1GB RAM. The
Raspberry Pi 3 is equipped with 2.4 GHz WiFi 802.11n and
Bluetooth 4.1 in addition to the 10/100 Ethernet port. The HDMI port
makes it further easy to hook up A/V sources.
Features
• Quad Core 1.2GHz Broadcom BCM2837 64bitCPU
• 1GBRAM
• BCM43438 WiFi and Bluetooth Low Energy (BLE) onboard
• 40-pin ExtendedGPIO
• 4x USB 2ports
• 4 Pole stereo output and composite videoport
• Full sizeHDMI
• CSI camera port for connecting a Raspberry Picamera
• DSI display port for connecting a Raspberry Pi touchscreendisplay
• Micro SD port for loading your operating system and storingdata
• Upgraded switched Micro USB power source up to2.5
College of Computing & Information 2
Sciences
Lab-1
Course Title: Computer Architecture Introduction to Computer Architecture
ARDUINO
ARDUINO is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and
software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or
environments.
It is based on the ATmega328P which has 14 digital input/output pins and six analog inputs. Though it
comes with just 32 KB of Flash memory, it can accommodate code that deals with complex logic and
operations.
https://www.ARDUINO.cc/
ARDUINO can sense the environment by receiving input from a variety of sensors and can affect its
surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is
programmed using the ARDUINO programming language (based on Wiring) and the ARDUINO
development environment (based on Processing). ARDUINO projects can be stand-alone or they can
communicate with software on running on acomputer.
Why ARDUINO?
• Cheaper
• Less PowerConsumption
• Small Hardware
• Easy ChipIntegration
ARDUINO Nano
ARDUINO Meg
Lab-1
Course Title: Computer Architecture Introduction to Computer Architecture
ARDUINORoboto UNO
ARDUINO Uno
Specs
• Runs at16mhz
• 32 KB ProgrammingMemory
• 2KB ~ 2048Bytes
• 1KBEPROM
• Built in Bootloader
The IDE works on a Mac, Win, and Linux, and it’s completely open source. The IDE is how you program
the ARDUINO — it’s based on Processing (a graphics programming language and development system
popular with artists and designers)
It’s based on a strong and well-supported backend, the open source GCC tool chain, and wrapped in Java
Libraries
There are tons of object-wrapped libraries to do complex things, like writing to SD cards, LCD screens,
parsing GPS.Like UART (Universal asynchronous receiver/transmitter) set up code.
Serial begin (9600)
Lab-1
Course Title: Computer Architecture Introduction to Computer Architecture
Sensors
The ARDUINO really took off because it has analog-to-digital input, in other words, you can take in sensor
data like light, temperature, sound, or whatever using the low-cost sensors already on the market and get
that into the ARDUINO easily. It also has ready-to-go SPI and I2C for digital sensors. This covers 99% of
sensors on themarket.
Unlike Beagle Board (great product) with an ARDUINO strapped to it just to get sensor datain.
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
LAB:02
Introduction to ARDUINOBoard, LED,Button
Sketch
A sketch is the name that ARDUINO uses for a program. It's the unit of code that is uploaded to and run on an
ARDUINO board.
• Comments
• Variables
• Functions
• Pin Mode(), digital Write(), anddelay()
• setup() and loop()
• LEDs
• Transistor
• Resistors
• Solder less Breadboard
• Switches
• Throwswitch
• Push button
Resistors
Resistor Reading
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
Breadboard
LED
https://www.ARDUINO.cc/en/Main/Software
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
When the download finishes, unzip the downloaded file. Make sure to preserve the folder structure. Double-
click the folder to open it. There should be a few files and sub-folders inside.
• Plug in your board and wait for Windows to begin its driver installation process. After a few
moments, the process will fail, despite its bestefforts
• Click on the Start Menu, and open up the ControlPanel.
• While in the Control Panel, navigate to System and Security. Next, click on System. Once the System
window is up, open the DeviceManager.
• Look under Ports (COM & LPT). You should see an open port named “ARDUINO UNO
(COM**)".IfthereisnoCOM&LPTsection,lookunder"OtherDevices"for"UnknownDevice".
• Right click on the "ARDUINO UNO (COM**)" port and choose the "Update Driver Software”
option.
• Next, choose the "Browse my computer for Driver software"option.
• Finally, navigate to and select the driver file named "ARDUINO.inf", located in the "Driver’s" folder
of the ARDUINO Software download (not the "FTDI USB Drivers" sub-directory). If you are using
anoldversionoftheIDE(1.0.3orolder),choosetheUnodriverfilenamed"ARDUINOUNO.inf"
• Windows will finish the driver installation fromthere.
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
Now, simply click the "Upload" button in the environment. Wait a few seconds - you should see the RX
and TX led on the board flashing. If the upload is successful, the message "Done uploading." will appear
in the status bar
Blink Example
This example shows the simplest thing you can do with an ARDUINO or GENUINO to see physical
output: it blinks the on-board LED. Turns on an LED on for one second, then off for one second,
repeatedly
Hardware
• ARDUINO or GENUINOBoard
• optional
• LED
• 220-ohmresistor
Circuit Diagram
CODE:
void setup() {
//initialize digital pin LED_BUILTIN as an output.
Pin Mode (LED_BUILTIN,OUTPUT);
}
// the loop function runs over and over again forever void
loop() {
Digital Write (LED_BUILTIN, H I G H ); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for asecond
Digital Write(LED_BUILTIN,LOW); // turn the LED off by making the voltage
LOW delay(1000); // wait for a second}
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
FADE Example
This example demonstrates the use of the analog Write () function in fading an LED off and on. Analog
Write uses pulse width modulation (PWM), turning a digital pin on and off very quickly with different
ratio between on and off, to create a fading effect.
The analog Write() function uses PWM, so if you want to change the pin you're using, be sure to use
another PWM capable pin. On most ARDUINO, the PWM pins are identified with a "~" sign, like ~3,
~5, ~6, ~9, ~10 and ~11.
Hardware
• ARDUINO or GENUINOboard
• LED
• 220 ohmresistor
• hook-upwires
• breadboard
CONCEPT:
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means.Digital
control is used to create a squarewave, asignal switched between on and off. The duration of "on time" is
called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you
repeat this on-off pattern fast enough a call to analog Write() is on a scale of 0 - 255, such that analog
Write (255) requests a 100% duty cycle (always on), and analog Write(127) is a 50% duty cycle (on half
the time)
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
Circuit Diagram
CODE
void setup() {
pinMode(12,OUTPUT);
void loop() {
digitalWrite(12, HIGH);
delay(500);
digitalWrite(12,LOW);
delay(500);
}
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
CONCEPT:
HIGH IMPEDENCE
In digital circuits, a high impedance (tri-stated or floating) output is not being driven to any defined logic
level by the output circuit. The signal is neither driven to a logical high nor low level; this third condition
leads to the description "tri-stated".
Pins configured as pin Mode(pin, INPUT) with nothing connected to them, or with wires connected to
them that are not connected to other circuits, will report seemingly random changes in pin state, picking
up electrical noise from the environment, or capacitive coupling the state of a nearby pin.
Button Example
Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-
in LED on pin 13 when you press the button.
Hardware
• ARDUINOUNO
• Momentary button orSwitch
• 10K ohmresistor
• hook-upwires
Lab-2
Course Title: Computer Architecture Introduction to ARDUINO Board
CODE
void setup() {
Serial. Begin(9600);
pinMode(10,INPUT);
pinMode(12,INPUT);
}
void loop() {
int a=digitalRead(10);
int b=digitalRead(12);
if(a==1){
Serial.println("Welcome");
}
delay(1000);
if(b==1){
Serial.println("Serial button 12");
}
Lab-3
Course Title: Computer Architecture Interfacing 16x2 LCD with ARDUINO UNO
LAB: 03
Interfacing 16x2 LCD with ARDUINO UNO
OBJECTIVES: The main object is to interfacing 16x2 LCD with ARDUINO to display data.
Hardware
1. ARDUINOUno
2. LCD Screen
3. 10k ohmpotentiometer
4. hook-upwires
Instruments
Basic Theory:
LCD/LED display one of the way to interact computer and provide human to machine interface. To work
with microcontroller, most of the time we need to know what is actually running in the background and
we need many reading to be display on LCD like temperature sensor, distance sensor etc. So, whatever
you need to display one should know how LCD works how pixels map on display and how all pixel
joins to formimage.
Experiment:
The Liquid Crystal library allows you to control LCD displays that are compatible with the Hitachi
HD44780 driver. There are many of them out there, and you can usually tell them by the 16pin interface.
This example sketch prints "Hello World!" to the LCD and shows the time in seconds since the
ARDUINO wasreset.
Lab-3
Course Title: Computer Architecture Interfacing 16x2 LCD with ARDUINO UNO
8 data pins (D0 -D7). The states of these pins (high or low) are the bits that you’re writing to aregister when
you write, or the values you're reading when youread.
There's also a display contrast pin (Vo),power supply pins (+5V and Gnd) and LED Backlight (Bklt+
and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn on and off the
LED backlight,respectively.
The process of controlling the display involves putting the data that form the image of what you want to
display into the data registers, then putting instructions in the instruction register. The Liquid Crystal Library
simplifies this for you so you don't need to know the low-levelinstructions.
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 most everything in 4-bit mode, so example shows how to control a 2x16 LCD in 4-bit mode.
Circuit
Before wiring the LCD screen to your ARDUINO or GENUINO board we suggest to solder a pin header strip
to the 14 (or 16) pin count connector of the LCD screen, as you can see in the image above.
To wire your LCD screen to your board, connect the following pins:
Lab-3
Course Title: Computer Architecture Interfacing 16x2 LCD with ARDUINO UNO
Schematic
Lab-3
Course Title: Computer Architecture Interfacing 16x2 LCD with ARDUINO UNO
Example Code:
/*
Liquid Crystal Library - Hello World
Demonstrates the use a 16x2 LCD display. This
sketch prints "Hello World!" to the LCD and
shows the time.
The circuit:
* LCD RS pin to digital pin12
* LCD Enable pin to digital pin11
* LCD D4 pin to digital pin5
* LCD D5 pin to digital pin4
* LCD D6 pin to digital pin3
* LCD D7 pin to digital pin2
* LCD R/W pin toground
* LCD VSS pin to ground * LCD VCC pin to 5V * 10Kresistor:
* ends to +5V andground
* wiper to LCD VO pin (pin3)
*/
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Welcome in CA Class!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor (0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
Lab-3
Course Title: Computer Architecture Interfacing 16x2 LCD with ARDUINO UNO
The Liquid Crystal Library allows you to control LCD displays that are compatible with the Hitachi
HD44780driver.Therearemanyofthemoutthere,andyoucanusuallytellthembythe16-pininterface.
This example sketch shows how to use the scroll Display Left () and scroll Display Right () methods to
reverse the direction the text is flowing. It prints "Hello World!” scrolls it off screen to the left, then off
screen to the right, then back to home.
CIRCUIT DIAGRAM
Lab-3
Course Title: Computer Architecture Interfacing 16x2 LCD with ARDUINO UNO
CODE:
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Welcome in CA Class!");
}
void loop() {
for(int pos=0;pos<11;pos++){
lcd.scrollDisplayLeft();
delay(500);
}
lcd.clear();
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
Lab-4
Course Title: Computer Architecture Temperature Sensor LM35
LAB: 04
Introduction to Analog Channel & Using Temperature Sensor LM35
OBJECTIVES:Themainobjectiveofthelabistounderstanddifferencebetweenanalog
and digital system and how digital system see analog signal.
HARDWARE
1. ARDUINO
2. LM35 Temperature sensor(TMP36)
3. hook-upwires
4. breadboard
Instruments
BASIC THEORY:
Analog signal is a continuous signal mean that it exist infinite number of values. For example from 0 to 1
there is infinite numbers either 0.1 or 0.00000001. So it is impossible for digital system to handle infinite
number. This is the limitation of digital system. So what digital system does is it set threshold level of
values from which it can read which is called step size. The accuracy or resolution of digital system is
given bybits.
Resolution defines the number of possible analog-to-digital converter output states. As previously
discussed, the result is a digital or whole number, so for an 8-bit converter the possible states will be zero,
one, two, three and so on, with 255 as the maximum state. A 10-bit converter will have 1023 as the
maximum state, and a 12-bit converter will have 4095 as the maximum state. If the input range remains
constant, a higher resolution converter will have less quantization error because the range is divided into
smallersteps.
Lab-4
Course Title: Computer Architecture Temperature Sensor LM35
The LM35 is a common TO-92 temperature sensor. It is often used with the equation temp
However, this does not yield high resolution. This can easily be avoided, however. The LM35 only
produces voltages from 0 to +1V. The ADC uses 5V as the highest possible value. This is wasting 8 0 % of
the possible range. If you change aRef to 1.1V, you will get almost the highest resolution possible.
The original equation came from taking the reading, finding what percentage of the range (1024) it is,
multiplying that by the range itself(aRef, or 5000 mV), and dividing by ten (10 mV per degree Celsius,
according to the datasheet:http://www.ti.com/lit/ds/symlink/lm35.pdf
However, if you use 1.1V as aRef, the equation changes entirely. If you divide1.1V over 1024, each step
up in the analog reading is equal to approximately 0.001074V = 1.0742 mV. If 10mV is equal to 1 degree
Celsius, 10 / 1.0742 = ~9.31. So, for every change of 9.31 in the analog reading, there is one degree of
temperaturechange.
To change aRef to 1.1V, you use the command "analog Reference (INTERNAL);"
Circuit Diagram
Lab-4
Course Title: Computer Architecture Temperature Sensor LM35
Code:
FloattempC;//VariableforholdingCelsiustemp(floatingfordecimalpointsprecision)
Int reading;
int temp Pin = 0;
void setup()
{
Analog Reference (INTERNAL);
Serial begin (9600);
}
void loop()
{
reading = analogRead(tempPin);
// conversion math of LM35 sample to readable temperature and stores result to samples array.
tempC = reading / 9.31; Serial.println(tempC);
delay(1000);
}
Lab-5
Course Title: Computer Architecture Interfacing Sonar (RANGE) sensor with ARDUINO
LAB: 05
INTERFACING SONAR (RANGE) SENSOR WITH ARDUINO
HARDWARE
1. 1 xARDUINO
2. HC-SR04 (ultrasonic sensor)
3. LCD or SerialMonitor
Instruments
Ultrasonic modules include ultrasonic transmitters, receiver and control circuit. The basic principle ofwork:
Lab-5
Course Title: Computer Architecture Interfacing Sonar (RANGE) sensor with ARDUINO
There are two versions of this device. In the three pins version, you trigger the measurement and receive the echo
pulse on the same pin. In the four-pinversion,trigger and echo are on separate pins.
Lab-5
Course Title: Computer Architecture Interfacing Sonar (RANGE) sensor with ARDUINO
Lab-5
Course Title: Computer Architecture Interfacing Sonar (RANGE) sensor with ARDUINO
3- PINCONNECTION:
This sketch reads a PING))) ultrasonic rangefinder and returns the distance to the closest object in range. To
do this, it sends a pulse to the sensor to initiate a reading, then listens for a pulse to return. The length of the
returning pulse is proportional to the distance of the object from thesensor.
The circuit:
- +V connection of the PING))) attached to +5V
- GND connection of the PING))) attached toground
- SIG connection of the PING))) attached to digital pin7
// this constant won't change. It's the pin number of the sensor's output:
const int pingPin = 7; void
setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
Lab-5
Course Title: Computer Architecture Interfacing Sonar (RANGE) sensor with ARDUINO
// establish variables for duration of the ping, and the distance result
// in inches and centimeters: long duration, inches, cm;
// The same pin is used to read the signal from the PING))): a HIGH pulse
// whose duration is the time (in microseconds) from the sending of the ping
// to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
Lab-6
Course Title: Computer Architecture Controlling LED with a remote control using IR
receiver
LAB: 06
Controlling LED with a Remote Control using IR receiver
OBJECTIVES: Controlling LED (Any device) with a Remote Control using IR receiver.
HARDWARE
1. ARDUINOUNO
2. TSOP1738
3. IR TV/DVDRemote
4. LED
Instruments
Working Explanation
When we press any button of IR Remote then remote sends a code in form of train of encoded pulses using
38Khz modulating frequency. These pulses are received by TSOP1738 sensor and read by ARDUINO and
then ARDUINO decodes received train of pulse into a hex value and compares that decoded value with the
predefined hex value of the pressed button. If any match occurs then ARDUINO perform relative
operation, in our case turning on and off al ed.
For detecting IR remote signal, we use TSOP1738 IR Receiver. This TSOP1738 sensor can sense
38Khz Frequency signal.
If you don’t know the Decoded output for your IR remote, it can be easily found, just follow these steps
2. Unzip it, and place it in your ARDUINO ‘Libraries’ folder. Then rename the extracted folder to
IRremote.
3. Run the below program from your ARDUINO and open the Serial Monitor window in ARDUINO
IDE. Now press any IR Remote button and see the corresponding decoded hex output in Serial
Monitor window.
Lab-6
Course Title: Computer Architecture Controlling LED with a remote control using IR
receiver
#include
<IRremote.h>intRECV_P
IN=11;
IRrecvirrecv(RECV_PIN);
decode_resultsresults;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();//Startthe receiver
}void loop(){ if
(irrecv.decode(&results)){
Serial.println(results.value,HEX);
delay(100);
The above program is taken from IRremote libraries ‘examples’ folder, you can check out more
examples to learn more about using the IR remote. So that’s how we decoded the IR remote output.
Lab-6
Course Title: Computer Architecture Controlling LED with a remote control using IR
receiver
CIRCUIT DIAGRAM
Whenever a button is pressed on the remote, it sends an Infrared signal in encoded form. This
signal is then received by the IR receiver and then given to the ARDUINO.
We will save the code for the buttons we want to control the LEDs in the ARDUINO code.
Whenever a button on the remote is pressed, a code will be received by the ARDUINO. The
ARDUINO will compare this code with the codes already saved and if any of them match, the
ARDUINO will turn on the LED connected to that button.
CIRCUIT DIAGRAM
First, connect the four LEDs to the ARDUINO. Connect the positives of the four LEDs to the pins 7, 6,
5,
First, connect the LED to the ARDUINO. Connect the positive of the LED to the pins 13. Connect
the negative of the LED to GND on the ARDUINO through the 220-ohm resistors. The longer
wireson the LEDs are positive and the shorter wires arenegative.
Lab-6
Course Title: Computer Architecture Controlling LED with a remote control using IR
receiver
Then connect the IR sensor to the ARDUINO. The connections for the IR sensor with the
ARDUINO are asfollows
Code:
#include <IRremote.h>
int RECV_PIN = 2; //IR SENSOR
int led1=13; // LEDPIN
int itsONled[] = {0,0}; // STATUS ARRAY
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(led1,
OUTPUT);
}
void loop() { if
(irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value){ casecode1:
if(itsONled[1] == 1) { // if first led is on then
digitalWrite(led1, LOW); // turn it off when button ispressed
itsONled[1]=0; // and set its state asoff
}else{ // else if first led isoff
digitalWrite(led1, HIGH); // turn it on when the button is pressed
itsONled[1]=1; // and set its state ason
}
break;
}
Serial.println(value); // you can comment this line
irrecv.resume(); // Receive the next value
}
Lab-7
Course Title: Computer Architecture Make a real time clock using RTC DS3231
Module
LAB: 07
Make a REAL TIME CLOCK USING RTC DS3231 MODULE
OBJECTIVES: Make a real-time clock using RTC DS3231 module and show time on 16*2 LCD
HARDWARE
1. ARDUINO UnoRev3
2. 16x2 LCDDisplay
3. DS3231 Real Time ClockModule
4. USB Cable (Type A to TypeB)
5. Jumper Cable
Software
ARDUINOIDE
Proteus 8
Overview
Why we actually need a separate RTC for our ARDUINO Project when the ARDUINO itself has
built-in timekeeper. Well the point is that the RTC module runs on a battery and can keep track of
the time even if we reprogram the micro controller or disconnect the main power.
Working Explanation
The DS3231 is a low-cost, highly accurate Real Time Clock, which can maintain hours,
minutes and seconds, as well as, day, month and year information. Also, it has automatic
compensation for leap years and for months with fewer than 31days.
The module can work on either 3.3 or 5V, which makes it suitable for many development
platforms or microcontrollers. The battery input is 3V and a typical CR2032 3V battery can
power the module and maintain the information for more than a year.
The module uses the I2C Communication Protocol that makes the connection to the ARDUINO
Boardveryeasy.
Lab-7
Course Title: Computer Architecture Make a real time clock using RTC DS3231
Module
CIRCUIT DIAGRAM
Lab-7
Course Title: Computer Architecture Make a real time clock using RTC DS3231
Module
Code:
// Real time clock and calendar with set buttons using DS3231 and Arduino
void setup() {
pinMode(8, INPUT_PULLUP); // button1 is connected to pin 8
pinMode(9, INPUT_PULLUP); // button2 is connected to pin 9
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
Wire.begin(); // Join i2c bus
}
void DS3231_display(){
// Convert BCD to decimal
second = (second >> 4) * 10 + (second & 0x0F);
minute = (minute >> 4) * 10 + (minute & 0x0F);
hour = (hour >> 4) * 10 + (hour & 0x0F);
date = (date >> 4) * 10 + (date & 0x0F);
month = (month >> 4) * 10 + (month & 0x0F);
year = (year >> 4) * 10 + (year & 0x0F);
// End conversion
Time[12] = second % 10 + 48;
Time[11] = second / 10 + 48;
Time[9] = minute % 10 + 48;
Time[8] = minute / 10 + 48;
Time[6] = hour % 10 + 48;
Time[5] = hour / 10 + 48;
Calendar[14] = year % 10 + 48;
Calendar[13] = year / 10 + 48;
Calendar[9] = month % 10 + 48;
Calendar[8] = month / 10 + 48;
Calendar[6] = date % 10 + 48;
Calendar[5] = date / 10 + 48;
lcd.setCursor(0, 0);
lcd.print(Time); // Display time
lcd.setCursor(0, 1);
lcd.print(Calendar); // Display calendar
}
void blink_parameter(){
byte j = 0;
College of Computing & Information 38
Sciences
Lab-7
Course Title: Computer Architecture Make a real time clock using RTC DS3231
Module
while(j < 10 && digitalRead(8) && digitalRead(9)){
j++;
delay(25);
}
}
byte edit(byte x, byte y, byte parameter){
char text[3];
while(!digitalRead(8)); // Wait until button (pin #8) released
while(true){
while(!digitalRead(9)){ // If button (pin #9) is pressed
parameter++;
if(i == 0 && parameter > 23) // If hours > 23 ==> hours = 0
parameter = 0;
if(i == 1 && parameter > 59) // If minutes > 59 ==> minutes = 0
parameter = 0;
if(i == 2 && parameter > 31) // If date > 31 ==> date = 1
parameter = 1;
if(i == 3 && parameter > 12) // If month > 12 ==> month = 1
parameter = 1;
if(i == 4 && parameter > 99) // If year > 99 ==> year = 0
parameter = 0;
sprintf(text,"%02u", parameter);
lcd.setCursor(x, y);
lcd.print(text);
delay(200); // Wait 200ms
}
lcd.setCursor(x, y);
lcd.print(" "); // Display two spaces
blink_parameter();
sprintf(text,"%02u", parameter);
lcd.setCursor(x, y);
lcd.print(text);
blink_parameter();
if(!digitalRead(8)){ // If button (pin #8) is pressed
i++; // Increament 'i' for the next parameter
return parameter; // Return parameter value and exit
}
}
}
void loop() {
if(!digitalRead(8)){ // If button (pin #8) is pressed
i = 0;
hour = edit(5, 0, hour);
minute = edit(8, 0, minute);
date = edit(5, 1, date);
month = edit(8, 1, month);
year = edit(13, 1, year);
// Convert decimal to BCD
minute = ((minute / 10) << 4) + (minute % 10);
hour = ((hour / 10) << 4) + (hour % 10);
date = ((date / 10) << 4) + (date % 10);
College of Computing & Information 38
Sciences
Lab-7
Course Title: Computer Architecture Make a real time clock using RTC DS3231
Module
month = ((month / 10) << 4) + (month % 10);
year = ((year / 10) << 4) + (year % 10);
// End conversion
// Write data to DS3231 RTC
Wire.beginTransmission(0x68); // Start I2C protocol with DS3231 address
Wire.write(0); // Send register address
Wire.write(0); // Reset sesonds and start oscillator
Wire.write(minute); // Write minute
Wire.write(hour); // Write hour
Wire.write(1); // Write day (not used)
Wire.write(date); // Write date
Wire.write(month); // Write month
Wire.write(year); // Write year
Wire.endTransmission(); // Stop transmission and release the I2C bus
delay(200); // Wait 200ms
}
Wire.beginTransmission(0x68); // Start I2C protocol with DS3231 address
Wire.write(0); // Send register address
Wire.endTransmission(false); // I2C restart
Wire.requestFrom(0x68, 7); // Request 7 bytes from DS3231 and release I2C bus at end of reading
second = Wire.read(); // Read seconds from register 0
minute = Wire.read(); // Read minuts from register 1
hour = Wire.read(); // Read hour from register 2
Wire.read(); // Read day from register 3 (not used)
date = Wire.read(); // Read date from register 4
month = Wire.read(); // Read month from register 5
year = Wire.read(); // Read year from register 6
DS3231_display(); // Display time & calendar
delay(50); // Wait 50ms
}
Lab-8
Course Title: Computer Architecture Detecting motion using PIR Motion sensor
LAB: 08
Detecting Motion using PIR MOTION SENSOR
OBJECTIVES: Detecting Motion using PIR MOTION SENSOR and indicating motion by lighting up Led.
HARDWARE
1. ARDUINOUNO
2. PIR Motion Sensor
3. LED
4. Jumper Cables
Instruments
Working Explanation
PINOUT:
Wiring the PIR motion sensor to an ARDUINO is straightforward, the sensor has only 3 pins.
GND – connect to ground
OUT – connect to an ARDUINO digital
pin 5V – connect to 5V
Lab-8
Course Title: Computer Architecture Detecting motion using PIR Motion sensor
CIRCUIT DIAGRAM
ARDUINO Code
int led=13; // the pin that the LED is attached to
int sensor= 3; // the pin that the sensor is attached to
int state=LOW; // by default, no motiondetected
int val=0; // variable to store the sensor status(value)
void setup() {
pinMode(led,OUTPUT); // initalize LED as an
output pinMode(sensor, INPUT); // initialize sensor
as an input Serial.begin(9600); // initializeserial
}
void loop(){ val = digitalRead(sensor); //
read sensor value if (val ==HIGH){ //
check if the sensorisHIGH
digitalWrite(led, HIGH); // turn
LED ON delay(100); // delay 100
milliseconds if (state == LOW){
Serial.println("Motiondetected!"); state =
HIGH; // update variable state toHIGH
}
}
else {
digitalWrite(led, LOW); // turn LED
OFF delay(200); //delay 200
milliseconds if (state ==HIGH){
Serial.println ("Motion stopped!");
state = LOW;
// update variable state to LOW
}
}}
Lab-9
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
LAB: 09
Keypad Interfacing with ARDUINO Uno
OBJECTIVES: Keypad Interfacing with ARDUINO Uno and showing characters on LCD screen.
HARDWARE
1. ARDUINOUNO
2. Keypad4*4
3. LCD
Instruments
In this experiment, we are going to interface a 4x4 (16-key) keypad with ARDUINO UNO. We
all know keypad is one of the most important input devices used. Keypad is the easiest and the
cheapest way to give commands or instructions to an electronic system. Whenever a key is
pressed in keypad module, the ARDUINO Uno detects it and shoes the corresponding key on
16x2 LCD.
Working Explanation
In 16x2 LCD there are 16 pins over all if there is a back light, if there is no back light there will
be 14 pins. One can power or leave the back-light pins. Now in the 14 pins there are 8 data pins
(7-14 or D0-D7), 2 power supply pins (1&2 or VSS&VDD or GND&+5v), 3rd pin for contrast
control (VEE-controls how thick the characters should be shown) and 3 control pins
(RS&RW&E).
In the ARDUINO Uno keypad interfacing circuit, you can observe that I have only took two
control pins. This give the flexibility of better understanding; the contrast bit and READ/WRITE
are not often used so they can be shorted to ground. This puts LCD in highest contrast and read
mode. We just need to control ENABLE and RS pins to send characters and data accordingly.
CONNECTIONS
LCD:
PIN1 or VSS to ground
PIN2 or VDD or VCC to +5v power
PIN3 or VEE to ground (gives maximum contrast best for a
beginner) PIN4 or RS (Register Selection) to PIN8 of ARDUINO
UNO
PIN5 or RW (Read/Write) to ground (puts LCD in read mode eases the communication for user)
Lab-9
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
KEYPAD:
We are going to connect the keypad module between pins 0-7 of ARDUINO Uno, as shown in
the circuit diagram. All the eight pins of keypad module are connected accordingly.
Now for setting up a connection between Keypad Module and UNO, we need to get the
keypad library from the ARDUINO website.
CIRCUIT DIAGRAM:
Lab-9
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
CODE:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface
pins LiquidCrystal lcd(8, 9, 10, 11,
12,13);//RS,EN,D4,D5,D6,D7
#include <Keypad.h>//header
const byte ROWS = 4; // Four rows const byte COLS = 4;
// Three columns
// Define the Keymap char
keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'#','0','*','D'} };
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these ARDUINO
pins. byte rowPins[ROWS] = { 7,6,5,4};
// Connect keypad COL0, COL1 and COL2 to these ARDUINO
pins. byte colPins[COLS] = { 3,2,1,0};
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
for(int k=8;k<14;k++)
{
pinMode(k,OUTPUT);//pins 8-14 are enabled as output
}
lcd.begin(16, 2);//initializing LCD
}
void loop()
{
char key = kpd.getKey(); //storing pressed key value in a
char if (key !=NO_KEY)
{
lcd.print (key); //showing pressed character on LCD
}
}
Lab-10
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
LAB: 10
TO INTERFACE DC-MOTORS WITH ARDUINO UNO
OBJECTIVES: To demonstrate how to interface three types of motor i.e. . DC, Stepper and Servo
motors.
HARDWARE
Arduino
L293D Motor Driver IC
DC Motor
Stepper Motor
Servo Motor
Instruments
BASIC THEORY:
The main objective of this program is to make the student understand how to interface and control DC,
Stepper and Servomotor.
DC Motor:
A direct current (DC) motor is a simple electric motor that uses electricity and a magnetic field to
produce torque, which turns themotor.
Stepper Motor:
A stepper motor is a special type of electric motor that moves in
increments, or steps, rather than turning smoothly as a conventional motor
does. The size of the increment is measuredin degrees and can vary
depending on theapplication.
Lab-10
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
Inside the device, sets of coils produce magnetic fields that interact with the fields of permanent magnets.
The coils are switched on and off in a specific sequence to cause the motor shaft to turn through the
desired angle. The motor can operate in either direction (clockwise or counterclockwise).
WORKING OF L293D:
The L293D is a 16 pin IC which is known for their efficiency in controlling DC motors. There are two types of supply
voltage for this IC Vs, Vss. Vs is meant for its own internal operation, and it will not use this input for driving motors.
This Vs input voltage should not exceed 7 V or it will damage the IC.Vss is meant for supplying power to the motor
we are about to drive, for example if we are going to drive a 12V motor you should give 12V input to this 16th pin
Vss.
Enable pins are meant to make the respective motor drivers ready to operate; supplying high signal will activate the
corresponding drivers. Enable1 for motor 1 and Enable 2 is for motor 2. Input pins 2, 7, 10, 15 are used to operate the
motor in your desired direction. Output pins 3 & 6 should be connected to motor 1, Pins 11 & 14 should be connected
to motor 2. Here is a logic table for the inputs of L293D and the motor state corresponding to that input.
Lab-10
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
Lab-10
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
Code:
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
analogWrite(9,val);
analogWrite(10,0);
delay(10);
}
Lab-10
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
Servo Motor:
Simple DC motor which is controlled for specific angular rotation with
help of additional servomechanism (a typical closed loop feedback control
system). If the motor as controlled device, associated with
servomechanism is DC motor, then it is commonly known DC Servo
Motor. If AC operates the controlled motor, it is called AC Servo Motor
The main reason behind using a servo is that it provides angular precision, i.e. it will only rotate as much
we want and then stop and wait for next signal to take further action. This is unlike a normal electrical
motor, which starts rotating as, and when power is applied to it and the rotation continues until we switch
off the power. We cannot control the rotational progress of electrical motor; but we can only control the
speed of rotation and can turn it ON and OFF.
Code:
#include <Servo.h>
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
Lab-10
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it for use with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
Stepper Motor:
This type of motor rotates in steps rather than continuous rotation. The minimum step of the stepper motor
is called step angle. A stepper motor is a Varies types of Stepper motors are available in different sizes and
step angles. In our lab, we would be interfacing a uni-polar 1.8’/step stepper motor.
Lab-10
Course Title: Computer Architecture Keypad Interfacing with ARDUINOUNO
Code:
#include <Stepper.h>
const int spr=4;
Stepper steper (spr,8,9,10,11);
void setup() {
steper.setSpeed (10);
Serial.begin (9600);
}
void loop() {
steper.step (60);
delay (200);
//CS01
steper.step (-40);
delay (200);
}
Lab-11
Course Title: Computer Architecture ARDUINO with Relay to control High Voltage Device
LAB: 11
INTERFACING ARDUINO WITH RELAY TO CONTROL HIGH
VOLTAGE DEVICES
OBJECTIVES: Learn how to Control High Voltage Devices using the ARDUINO Board.
HARDWARE
1. ARDUINO
2. 5V RelayModule
3. JumpWires
4. Cable, Plug,Socket
Software
• ARDUINOIDE.
• Proteus 8
Introduction
We can control High Voltage electronic devices using relays. A Relay is actually a switch, which is
electrically operated by an electromagnet. The electromagnet is activated with a low voltage, for example, 5
volts from a microcontroller and it pulls a contact to make or break a high voltage circuit.
Before we continue with this tutorial, I will warn you here that we will use High Voltage which if
incorrectly or improperly used could result in serious injuries or death. So be very caution of what you are
doing because I take no responsibility for any of your actions.
Relay Module
The high voltage output connector has 3 pins, the middle on is the common pin and as we can see fromthe
markings one of the two other pins is for normally open connection and the other one for normally closed
connection. On the other side of the, there are 3 pins, a Ground and a VCC pin for powering the module and 1
input pin In1 which receives the signal from ARDUINO in form of digital output0/1.
67
College of Computing & Information 50
Sciences
Lab-11
Course Title: Computer Architecture ARDUINO with Relay to control High Voltage Device
C = Common Connection
NC = Normally Closed Connection
NO = Normally Open Connection
COM - Common Connection
It is the center terminal; it is hot as power to the load is connected at this terminal.
It acts like a switch, since it is open - there will be no contact between COM and NO, when we trigger the relay
module, it connects to COM by the electromagnet inside the relay and supply to the load is provided, which
powers up the light. Thus, the circuit is closed until we trigger the state to low in relay.
NC Normally Closed. It is always in contact with COM, even when relay is not powered.
When we trigger the relay, it opens the circuit, so the connection is lost. It behaves just opposite to NO.
Circuit Diagram
Lab-11
Course Title: Computer Architecture ARDUINO with Relay to control High Voltage Device
Code:
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(13, OUTPUT);
}
Lab-12
Course Title: Computer Architecture Interfacing ARDUINO with ESP8266
LAB: 12
INTERFACING ARDUINO WITH ESP8266
OBJECTIVES: Programming ESP8266 ESP-01 with
ARDUINO. HARDWARE
1. ARDUINO
2. ESP 8266 – 01
3. Jumper wires / Breadboard
Introduction
The ESP8266 ESP-01 is a Wi-Fi module that allows microcontrollers access to a Wi-Fi network. ESP8266
module is of low cost and comes pre-programmed with an AT command set firmware .This module is a
self-contained SOC (System On a Chip) that doesn’t necessarily need a microcontroller to manipulate inputs
and outputs as you would normally do with an ARDUINO for example, because the ESP-01 acts as a small
computer. Depending on the version of the ESP8266, it is possible to have up to 9 GPIOs (General Purpose
Input Output). Thus, we can give a microcontroller internet access like the Wi-Fi shield does to the
ARDUINO, or we can simply program the ESP8266 to not only have access to a Wi-Fi network, but to act as
a microcontroller as well. This makes the ESP8266 very versatile.
ARDUINO Setup
First download ARDUINO IDE ensure that you have the latest
software version (some older versions won’t work), visit the
following URL: https://www.ARDUINO.cc/en/Main/Software.
AT firmware is compatible with the ARDUINO IDE, so we are going to use this firmware for this
tutorial. Connect ESP8266 as per the above circuit.
Lab-12
Course Title: Computer Architecture Interfacing ARDUINO with ESP8266
ESP8266 Modes:
Open the serial monitor change the baud rate to 115200 and choose NL and CR (new line and carriage return).
Type AT on the serial monitor you will see an OK response. If you see garbage value on the screen, try to
resetting the module, or checking your baud rate. Make sure the NL and CR option is set. ESP8266 module has
three operational modes.
1. Access Point(AP)
In AP the Wi-Fi module acts as a Wi-Fi network, or access point (hence the name), allowing other devices to
connect to it. It establishes a two-way communication between the ESP8266 and the device that is connected to it
via Wi-Fi.
2. Station(STA)
In STA mode, the ESP-01 can connect to an AP (access point) such as the Wi-Fi network from your house. This
allows any device connected to that network to communicate with the module.
3. Both
In this mode ESP-01, act as both an AP as well as in
STA mode.
You can refer the following site for more ESP8266
AT command set click here.
Lab-12
Course Title: Computer Architecture Interfacing ARDUINO with ESP8266
Lab-12
Course Title: Computer Architecture Interfacing ARDUINO with ESP8266
4. Scroll down, select the ESP8266 board menu and install “ESP8266platform”
Lab-12
Course Title: Computer Architecture Interfacing ARDUINO with ESP8266
5. Choose your ESP8266 board from Tools > Board > Generic ESP8266Module.
References:
• http://www.instructables.com/id/Getting-Started-With-the-ESP8266-ESP-01
• https://create.ARDUINO.cc/projecthub/ROBINTHOMAS/programming-esp8266-esp-01-with-
ARDUINO011389
Lab-13
Course Title: Computer Architecture Introduction to Bluetooth serial communication
LAB:13
Introduction to Bluetooth Serial Communication
OBJECTIVES: The main objective of the lab is to understand how the communication system works and
discus serial and parallel communication
HARDWARE
2x ARDUINO
Optional HC-05 (Bluetooth Module) and android phone
Instruments
BASIC THEORY:
Communication is a way to understand and share ideas. In digital world, communication is necessary to
define machine what we actually want it to do. There is two way to communicate with devices parallel and
serial. In parallel data is transfer by mean of parallel connection between machine to machine, which in
term increase hardware size cost, and connection. In Serial communication data has send one by one on a
single channel, which reduces cost, connection and hardware.
Lab-13
Course Title: Computer Architecture Introduction to Bluetooth serial communication
We prefer serial because It use less connecting then parallel so we do not have bunch of wire.USB
(Universal Serial Bus) is also a Serial data transfer device. So here in microcontroller, we have 5 or more
communication protocol USART, SPI, CAN, I2C, and Parallel. As a beginner, we learn simple
communication protocol USART.
USAT
• Two Signals are required for the bi-directional communication (TX,RX)
• Asynchronous Communication (No clock signal required)
• Both devices must have same BAUD rate
UART
Data Transmission
88