Professional Documents
Culture Documents
Session: FA20
COMSATS University Islamabad
Attock Campus
Course Details
Credit Hours 01
Core BS CE
Course Prerequisite(s)/Co-Requisite(s)
Pre-requisites: Programming Fundamentals, Computer Organization and Architecture
Recommended
Week Topics
Readings (if any)
1. Introduction to the Arduino
2. Interfacing Sensors (Analog and Digital) with Arduino
3. Obstacle Detection Using Sensors (Interfacing Proximity Sensors with Arduino)
4. Interfacing Actuators with Arduino (High Voltage Devices, and Servo Motors)
5. Serial Communication (Control LED Dimmer using Serial, and Interfacing GPS Sensor as
RS232)
6. Sessional Exam I
7. RFID based Access Control System (Using RFID and Servo Motor)
8. Interfacing Bluetooth with Arduino and Android Bluetooth APP
9. Arduino External Interrupts (An interrupts-based Devices Control)
10. Arduino-Controlled Smart Home Internet-of-Things Platform (Web-Controlled Smart Home
Appliances)
11. Sessional Exam II
12. Data Transfer of Arduino-Controlled Smart Home to Thingspeak Cloud
13. Introduction of Raspberry PI, Installation of RTOS/Raspbian Operating System
14. Basic Interfacing (LDR, Proximity Sensors, Camera) with Raspberry Pi using Python
15. Terminal Project
Important Note: Students will be required to submit their Lab work and Lab handout.
Textbook(s)/Supplementary Readings
[1]. A lab manual will be provided to the students at the beginning of the each labthat carries the details of the experiments and related instructions
to perform those experiments.
.
R1: Lab Safety Rules: While working in the lab, the While working in the lab, the While working in the lab, the While working in the lab, the
Ability to observe safety, be student demonstrates student is attentive to safety, student is mostly attentive to student is unattentive to safety,
courteous to others, attentive exemplary behavior in respectful to instructors and safety, respectful to instructors disrespectful to others, and
to safety, and tidy in the lab. courtesy and safety, and leaves peers, and neat, cleaning the and peers, and neat, Might messy, leaving the area untidy
the area spotless. area before leaving. need reminders to leave the even after being reminded.
area clean.
R2: Use of Engineering
Knowledge and follow The procedure is efficiently The procedure is well The procedure could be better The procedure is inadequately
Engineering Experiment Procedures: followed and student skillfully followed and student followed, but student controls followed, and student does not
Knowledge Ability to follow experimental controls all chosen variables. demonstrates control of all all chosen variables. Most control chosen variables. Many
procedures, control variables, Know all procedural steps, and chosen variables. All procedural steps are recorded procedural steps are not entered
and record procedural steps are clearly and concisely procedural steps are on the lab report. on the lab report.
on lab report. recorded on lab report recorded on the lab report.
R3: Interpretation of Demonstrates a skillful ability Demonstrates an ability to Demonstrates some ability Demonstrates minimal or no
Subject Knowledge: to provide rational provide rational to provide explanations of ability to provide explanation of
Ability to interpret and explanations, and on the basis explanations of mathematical and/or visual mathematical
explain mathematical and/or of that information, can make mathematical and/or forms, and makes occasional and/or visual forms. Frequently
visual forms, including fitting inferences. visual forms. mistakes. misinterprets
equations,
diagrams, graphics, figures
and tables.
Rubrics for PLO#2 (Problem Analysis)
Exceeds expectations [9-10] Meets expectations[7-9) Average [5-7) Unsatisfactory [1-5)
.
R4: Limitations and Point out all significant Point out many significant Point out some limitations Minimal or no ability to identify
Implications: limitations and limitations and implications. and implications. limitations or implications. Has
Ability to point out implications. Demonstrates Demonstrates recognition Demonstrates some no knowledge of hardware or
limitations and implications skillful recognition and and consideration of recognition and software implementation
of Hardware and software consideration of important important assumptions, Consideration of important requirements for the problem
Components. assumptions, hardware or hardware or software requirements of hardware or solution. Didn’t mention about
software requirements requirements when solving software. .Has mentioned assumption and constraints.
Problem when solving a problem. a problem. some of the assumptions.
Analysis
R5: Data/Evidence Raw data/evidence, as well as Raw data/evidence, as well Raw data/evidence, as well as Raw data/evidence, as well as
Measurements: units, are skillfully recorded. as units, are appropriately units, are recorded although units, are not recorded suitably.
Ability to record raw data / The data table is clearly and and clearly recorded. The not as clearly or suitably as The data table is not labeled
evidence. concisely, and/or creatively data table is appropriately they might be. The data table and/or formatted.
labeled and formatted. labeled and formatted. may lack appropriate labels
and/or format.
R6: Experimental Data Accurately analyze the Accurately analyze the Analyze the collected data and Analysis and interpretation of the
Analysis: collected data and interpret the collected data and interpret interpret the findings with findings is illogical, and the
Ability to interpret findings, findings insightfully, and the findings. Correlates minor errors. Correlates findings. No attempt to correlate
compare them to values in the skillfully. Correlates experimental results to experimental results to known experimental results with known
literature, identify weaknesses experimental results to known known theoretical values; theoretical values; accounts for theoretical values; incapable of
and limitations. theoretical values; accounts for accounts for measurement measurement errors and explaining measurement errors or
measurement errors and errors and parameters that parameters that affect parameters that affect the
parameters that affect affect experimental results. experimental results. experimental results.
experimental results.
R7: Implementing .
Design Strategy: Ability Demonstrates a skillful Demonstrates an ability Demonstrates some ability Demonstrates minimal or no
to execute a solution (thorough/insightful/creative) to execute a solution to execute a solution that ability to execute a solution.
taking into consideration ability to execute a solution taking into consideration attends to the problem, but Solution does not directly
design requirements and taking into consideration all design requirements and omits some design attend to the problem.
pertinent contextual design requirements and some contextual requirements and/or
elements. pertinent contextual elements. elements. pertinent contextual
[Block Diagram/Flow elements.
Engineering chart/Circuit Diagram]
Design R8: Best Coding Standards: Coding standards, best Coding standards, best Coding standards, best Coding standards, best
Ability to follow the coding programming practices are programming practices are programming practices are programming practices are not or
standards and programming followed extensively. followed appropriately not appropriately followed. rarely followed.
practices.
Lab #
Lab Title:
Submitted by:
In-Lab Post-Lab
Rubrics to follow
In –Lab
Post- Lab
Lab-1: Introduction to the Arduino
Arduino is an open-source single-board microcontroller, designed to make the process of
using electronics in multidisciplinary projects more accessible. The hardware consists of a simple
open hardware board with an Atmel AVR processor. It has on-board analog and digital
input/output support. The software consists of a standard programming language compiler
and the boot loader that runs on the board. Knowledge of the Arduino gives a tangible
application of Embedded systems.
Lab Objective
The objective of this lab is to explore the basic capabilities of the Arduino
and its programming structure, and the Atmel AVR Atmeg328p details.
Figure 4: A part of Arduino Website’s download page. Arduino allows you to install
its IDE on several platforms (see encircled).
After downloading the compressed file, extract its contents to your preferred directory
(C:\Program Files, your Desktop or etc…). Note that the whole folder size is around 200MB
when completely extracted.
Figure 4: Screenshot of attempt to extract the zipped Arduino folder.
Make sure you have an archive utility such as 7zip or WinRAR.
Congratulations! Arduino IDE is installed on your computer. To use it, just navigate to
your main folder directory and run the Arduino application.
Figure 5: Screenshot of what’s inside the Arduino folder. The application icon looks like an infinity symbol.
Figure 7: Screenshot of the Device Manager. The Arduino Uno should have an exclamation point.
Choose to browse your computer for the driver by clicking Browse my computer for
driver software.
Figure 8: Screenshot of the browse option menu. Choose the first option which is to look manually for
the folder that contains the Arduino Uno board’s driver.
A Windows Security window sometimes pops up to confirm if you want to continue
the installation. Just click, Install this driver software anyway.
Figure 9: Screenshot of pop-up window. Windows can’t verify the publisher of the device software but
we know that the software’s publisher is Arduino.
Wait for Windows to finish installing the device driver. Upon completion, you should
see an installation successful message.
Figure 14: Screenshot of the Arduino IDE. The workspace is very simple and
frequently used buttons are easy to access
Type the following lines of code on the front panel.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn LED on (HIGH voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn LED off (making voltage LOW)
delay(1000); // wait for a second
}
Press Ctrl + S or Icon on the IDE to save your sketch (the term for a source code in
Arduino).
Click the Verify Button (A shown on Fig. below) to check if the sketch has no errors. At
the bottom of the screen you should see if the sketch was successfully scanned free of
problems (B on Fig. below). Moreover, the size of the sketch file (C on Fig. below) is also
indicated on the black screen at the bottom to shows that it fits the flash memory of the
Arduino Uno.
Figure 15: Screenshot of the Blink code after compilation. The verify button looks just like a play button and is
located at the upper left corner. Successful compiling will be indicated at the bottom. If an error or problem
occurred, it will be shown in the black screen.
1.5.2 Test your Program:
Connect an LED to a 470Ω resistor. Note: that the longer leg of the LED is the positive
(connected to one end of resistor and the shorter one is the negative (connected to the
ground). The other end of the resistor should then be connected to the specified pin
which is 13.
Figure 15: Schematic Diagram of blinking LED circuit
Check if the board selected in the IDE is the one you are using, the Arduino Uno board.
Figure 16: Screenshot showing Arduino Uno as selected board. If you have a different type of Arduino
Figure 17: Screenshot showing a successful upload. Sometimes an error occurs because the COM port
of the Arduino UNO was not properly specified.
1.6 In Lab Tasks to Perform:
Control the LED ON/OFF operation using a push button or a switch
Control the light bulb (LED) installed in Stairway using the following two buttons
(switches) combinations
Switch-1 Switch-2 LED Status
0 0 OFF
1 0 ON
0 1 ON
1 1 OFF
Digital input and output are the most fundamental physical connections for any
microcontroller. The pins to which you connect the digital circuits are called General Purpose
Input-Output, or GPIO, pins. The arudino has only analog inputs and there are no analog
outputs. In mostly microcontrollers, the analog inputs and outputs are unavailable such as the
8051 microcontroller.
Lab Objectives
The objective of this lab is to explore the analog-to-digital convertor (ADC),
various configurations of the built-in ADC of Arduino for various levels of
resolutions, interfacing analog sensors with Arduino, and interfacing digital
sensors with Arduino.
(a) (b)
Figure 2: Pictorial Overview Sampling Phenomena (a). Sample interval is 0.5 seconds (b). Sample interval is 0.1
seconds.
Quantization:
Quantization, in mathematics and digital signal processing, is the process of
mapping input values from a large set (often a continuous set) to output values in a
(countable) smaller set. Rounding and truncation are typical examples of quantization
processes. In our scenario, we define as the conversion of y-axis (Amplitude) real value
into a discrete (integer) value is called as quantization. Eq. 1 is used to convert the real
amplitude value into integer value.
𝑉−𝑉𝑚𝑖𝑛
𝑋 = ⌊(2𝑁 − 1) ⌋ (1)
𝑉𝑚𝑎𝑥−𝑉𝑚𝑖𝑛
Where N is number of bits used to store the digital value, V is the desired amplitude value
to change. However, using ADC the V_min value should be greater than or equal to zero.
(a) (b)
Figure 3: A portion of the sampled signal and its conversion to the discrete values (a). Sampled Signal (b). The
quantized signal using Eq. (1)
Figure 5: Schematic Diagram of Connecting Analog Circuit to Arduino and Blink an LED
1.2.1.2 Source Code of connecting analog circuit (voltage source with variable
resistor) to Arduino:
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
If (sensorValue >=500)
digitalWrite(ledPin, HIGH);
Serial.println(sensorValue);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
}
When your Arduino takes an analogue reading, it compares the voltage measured at the
analogue pin being used against what is known as the reference voltage. In normal analogRead
use, the reference voltage is the operating voltage of the board. For the more popular Arduino
boards such as the Uno, Mega, Duemilanove and Leonardo/Yún boards, the operating voltage
of 5V. So if you have a reference voltage of 5V, each unit returned by analogRead() is valued at
0.00488 V. (This is calculated by dividing 1024 into 5V). What if we want to measure voltages
between 0 and 2, or 0 and 4.6? our signal has very low range and we want a resolution of less
than 0.00488 V? How would the ADC know what is 100% of our voltage range?
And there in lies the reason for the AREF pin. AREF means Analogue REFerence. It allows us
to feed the Arduino a reference voltage from an external power supply. For example, if we
want to measure voltages with a maximum range of 3.3V, we would feed a nice smooth 3.3V
into the AREF pin – perhaps from a voltage regulator IC. Then the each step of the ADC would
represent around 3.22 millivolts (divide 1024 into 3.3).
Note that the lowest reference voltage you can have is 1.1V. There are two forms of AREF –
internal and external, so let’s check them out.
An external AREF is where you supply an external reference voltage to the Arduino board.
This can come from a regulated power supply, or if you need 3.3V you can get it from the
Arduino’s 3.3V pin. If you are using an external power supply, be sure to connect the GND to
the Arduino’s GND pin. Or if you’re using the Arduno’s 3.3V source – just run a jumper from
the 3.3V pin to the AREF pin.
This sets the reference voltage to whatever you have connected to the AREF pin – which of
course will have a voltage between 1.1V and the board’s operation voltage.
Very important note – when using an external voltage reference, you must set the analogue
reference to EXTERNAL before using analogRead(). This will prevent you from shorting the
active internal reference voltage and the AREF pin, which can damage the microcontroller on
the board.
If necessary for your application, you can revert back to the board’s operating voltage for AREF
(that is – back to normal) with the following:
analogReference(DEFAULT);
Fig. 6 shows the schematic diagram for interfacing the low-level analog circuit (0~3.3
Volt) with Arduino. For a signal less than 3.3 Volt and greater/equal to 1.1 volt, we have
to connect this AREF pin to an external source and the Arduino ground PIN to that
external source.
Figure 6: Schematic Diagram of Connecting Analog Circuit to Arduino Using AREF PIN as an External
Reference for measure signal (0~3.3 Volts)
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
analogReference(EXTERNAL);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
If (sensorValue >=500)
digitalWrite(ledPin, HIGH);
Serial.println(sensorValue);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
}
analogReference(INTERNAL);
and we don’t need to connect the AREF pins to any voltage source.
This lab will be focused on interfacing proximity sensors specifically the ultrasonic and infra-
red sensors with Arduino. A proximity sensor is a sensor able to detect the presence or
distance of nearby objects without any physical contact. It emits a beam of signal and looks
for return signal. The object being sensed is often referred to as the proximity sensor's target.
Different proximity sensor targets demand different sensors. For example, a capacitive
proximity sensor or photoelectric sensor might be suitable for a plastic target; an inductive
proximity sensor always requires a metal target. There are many application of proximity
sensors from domestic use to industrial use such as Obstacle avoidance robot, Robotics,
object detection, distance measurement, liquid level monitoring system, Height
measurement, Agriculture, and vehicle collision protection. In this lab, we are mainly
focusing on Ultrasonic sensor.
Lab Objectives
The objectives of this lab is to explore how the Ultrasonic sensor can be interfaced with
Arduino. The working principles of ultrasonic sensor, detection of an obstacle, and measuring
the distance of an obstacle from the transmitter. We will able to understand how we can
measure that the time when a pin of Arduino become high.
Lab Background and Getting Knowledge of:
1. Basic Understanding Proximity Sensor interfacing. Student will learn the
interfacing of proximity sensors with Arduino. How, we have to trigger the sensor
to transmit a signal and then listen for the echo.
2. Finding the obstacle Position from the Received Single. After this lab, you
will know the mathematical model to calculate the distance of an obstacle from
the transmitting source.
3. Interfacing an Ultrasonic Sensor with Arduino. Student will learn the
ultrasonic transmitter and receiver. Ultrasonic sensor working principle is similar to bats and
dolphins. Fig. 1 illustrates the working principles of an ultrasonic sensor.
Pin Description
No.
Vcc +5V
Trig Trigger(Input)
Echo Echo(Output)
Figure 2: HC-SR04 PINOUT Configuration
GND GND
Table 1: HC-SR04 Specifications
1.3 Mathematical Model of Calculating the Distance of Obstacle from the
Transmitter
The speed of sound is 340.29 m/s or 0.034 cm/µs.
Distance = Time * Speed
As we know the ultrasound signal travels to the object and bounce back so the travel path, as
well as time, will be double. So to get the exact calculation we use this formula:
Distance = Time * Speed / 2
Distance = Time * 340 / 2 (m)
1.4 Source Code for Interfacing Ultrasonic Senor with Arduino
6. void setup() {
7. }
8. void loop() {
-Use the ultrasonic sensor to detect the presence of a person, generate an alarm (turn buzzer
ON), and turn ON LED
This lab will be focused on interfacing different actuators. Actuators are hardware devices that
convert a controller command signal into a change in a physical parameter. An actuator is a
component of a machine that is responsible for moving or controlling a mechanism or system,
for example by actuating (opening or closing) a valve or (Turning ON or OFF) a light. In this
lab, we are focusing on interfacing a high voltage device (light) using Relay, and also the servo
motor.
Lab Objectives
The objectives of this lab is to explore how we can control the high voltage devices from the
microcontroller (Arduino). The Arduino has limitation of voltages i.e. 5volt and 40 mA is
available. However, the high voltage devices need high voltages and current. For high voltage
devices, we are focusing only on the ON/OFF actuation using a Relay. Movement of objects
can be controlled by controlling motion of motors. In this lab, we are going to interface the
servo motor with Arduion.
Lab Background and Getting Knowledge of:
1. Basic Understanding Actuator interfacing. Student will learn the various
actuators interfacing. More specifically, we are focusing on interfacing the high
voltages sources with Arduino and moving objects control using servo motor.
2. Interfacing High voltage sources. After this lab, Student should be able to
interface high voltage sources as an ON/OFF actuation control. The students will
able to use Relay for controlling devices.
3. Interfacing an Ultrasonic Sensor with Arudino. Student will learn how to
interface servo motors with Arduino. Students will be able to generate different
pulse width modulation (PWM) to control the movement of servo motor.
3. Lab Tasks:
In-Lab Tasks:
Interface relay with microcontroller: use a push button to actuate the relay and turn
on/off LED
Interface the servo motor and change its angle from 0-180 and vice versa.
Post-Lab Task:
Interface a 12v light bulb with microcontroller using the mobile charger adapter
Using servo motor design automatic door lock system
Lab-5: Serial Communication (Control LED Dimmer using
Serial, and Interfacing GPS Sensor as RS232)
This lab will be focused on interfacing various sensors with Arduino using various types of
serial communication. In order to make two devices communicate, whether they are desktop
computers, microcontrollers, or any other form of computer, you need a method of
communication and an agreed-upon language. Serial communication is one of the most
common forms of communication between computers. Communicating serially involves
sending a series of digital pulses back and forth between devices at a mutually agreed-upon
rate. The two types of serial communication are 1). Asynchronous Serial Communication, and
2). Synchronous Communication.
Lab Objectives
The objectives of this lab is to explore how we can communicate between two devices (PC-PC),
Sensor-Microcontroller (GPS Serial Out), and Microcontroller-PC. The communication can be
done in various ways. However, we are focusing on serial communication between sensors
and microcontroller.
Lab Background and Getting Knowledge of:
1. Basic Understanding of Communication. Student will learn the basic of
communication, serial and parallel communication.
2. Interfacing Asynchronous Serial Communication based Sensor with
Arduino. After this lab, Student should be able to understand the type of
Asynchronous serial communication. Student will be able to configure the
Asynchronous serial port, and we are focusing on GPS (Global Positioning
System) sensor as Asynchronous Serial Communication Sensor in this lab.
Laboratory Pre-Exercise Tasks Overview:
1.1 What is Communication and what are Principles of Communication?
The word communication arises from the Latin word “commūnicāre”, which
means “to share”. Communication is the basic step for the exchange of information. For
example, a baby in a cradle, communicates with a cry that she needs her mother. A cow
moos loudly when it is in danger. A person communicates with the help of a language.
Communication is the bridge to share. Communication can be defined as the process of
exchange of information through means such as words, actions, signs, etc., between two
or more individuals. Any system which provides communication, consists of the three
important and basic parts as shown in the Fig. 1.
Figure 5: Overview of Communication System and Parts of Communication System
The Sender is the person who sends a message. It could be a transmitting station from
where the signal is transmitted.
The Channel is the medium through which the message signals travel to reach the
destination.
The Receiver is the person who receives the message. It could be a receiving station
where the signal transmitted is received.
The communication between sender and receiver can be parallel or serial. In
telecommunication and data transmission, serial communication is the process of sending
data one bit at a time, sequentially, over a communication channel or computer bus. This is
in contrast to parallel communication, where several bits are sent as a whole, on a link with
several parallel channels.
2. Lab Tasks:
In-Lab Tasks:
Design LED dimmer control, and observe the brightness level
Acquire different sensors data on Arduino, and then using RS232 send the data to
another (remote) Arduino for display.
Post-Lab Task:
Interface a GPS receiver as shown in Figure.5 with Arduino and extract the latitude,
longitude, and altitude from the GPS string. If the receive is not available, the use
Hyper Terminal and send the GPS data file and receive it on Arduino.
Lab-6: RFID based Access Control System (Using RFID and
Servo Motor)
This lab will be focused on interfacing Radio Frequency Identification (RFID) and Servo
Motor to make an access control system. The Basic necessity of security can be attained by
designing various door locks such as mechanical locks or electrical locks. These kind of door
locks are designed with one or more keys, but for locking a large area and by a number of
people’s various locks are needed. Generally, traditional locks are heavy and that are not
strong as they can damage simply by using some tools. Electronic locks are better over
mechanical locks, to resolve the security problems that are connected with the mechanical
locks. In recent days every device uses digital technology. For example, identification of digital
device using token, door lock system using digital technology, automatic door opening and
closing, automatic door lock systems, etc. This kind of systems is used for controlling the
movement of a door without using a key.
1.3.3 Code for Interfacing RFID Reader with Arduino using SPI Synchronous Serial
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup()
{
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
RfidScan();
}
if ( ! mfrc522.PICC_ReadCardSerial())
return;
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
}
2. Lab Tasks:
In-Lab Tasks:
Design RFID reader system that store three RFID tags, and provide access if the tag
match otherwise display access not allowed.
Post-Lab Task:
Design an RFID and motors based door lock system that allows access to only
registered RFID tags and no access to authorized user Tags. You can use below
information about motors and Lab.4 about servo motor control.
o Familiarize yourself with the basics of permanent magnet DC motors
http://www.pcbheaven.com/wikipages/How_DC_Motors_Work/
http://en.wikipedia.org/wiki/Brushed_DC_electric_motor
o Familiarize yourself with the basics of Stepper Motors
http://homepage.cs.uiowa.edu/~jones/step/
http://www.pcbheaven.com/wikipages/How_Stepper_Motors_Work/
http://en.wikipedia.org/wiki/Stepper_motor
http://learn.adafruit.com/adafruit-motor-shield/faq
.
Lab-7: Interfacing Bluetooth with Arduino and Android
Bluetooth APP
This lab will be focused on interfacing Bluetooth module with the Arduino and an android
APP to control the LED lights connected with Arduino. Bluetooth was invented by a telecom
specialist Ericsson in1994. It is an alternate of the RS-232 cables. It created above mentioned
body which is supported by Intel and takes care of development and licensing. Any company
who want to use the standards or market products with the technology is required to become
the member of above committee. The name comes from an epithet of a tenth-century King of
Denmark and Norway named Harald “Bluetooth” Gormsson. In the local language, he was
called Blåtand or Blåtann, which translated in English, became ‘Bluetooth’.
Figure 7: Overview of LED control system using Smartphone Bluetooth Based App
Lab Objectives
The objectives of this lab is to explore how the Bluetooth works. How the information is
transferred from the Smartphone App to the Arduino using the smart phone Bluetooth and
the Bluetooth interfaced with the Arduino.
Bluetooth is essentially a protocol with a master-slave architecture, which means that one
master device can communicate with up to 7 devices. This was and is a huge advantage to
earlier wired communication protocols which could work only with a 1 to 1 configuration.
Essentially creating a new standard called Personal Area Networks (PANs),
Bluetooth brought about far more effective ad-hoc networks and allows communication
without traditional host based networking. For Master-Salve configuration you can follow:
http://howtomechatronics.com/tutorials/arduino/how-to-configure-pair-two-hc-05-bluetooth-module-master-slave-
commands/
Figure 3: Clustering (Master-Salve) Configuration for multiple Bluetooth connecting to Single Bluetooth
1.3 Pin Configuration of HC-05 Bluetooth module
There are 6 pins available at the output of module. Facing back side, from left to right these
are as follows:
1.5 Code for HC-05 Bluetooth module interfacing with Arduino and Control LED
using Mobile Bluetooth APP
1. #define ledPin 7
2. int state = 0;
3.
4. void setup() {
5. pinMode(ledPin, OUTPUT);
6. digitalWrite(ledPin, LOW);
7. Serial.begin(38400); // Default communication rate of the Bluetooth module
8. }
9.
10. void loop() {
11. if(Serial.available() > 0){ // Checks whether data is comming from the serial port
12. state = Serial.read(); // Reads the data from the serial port
13. }
14.
15. if (state == '0') {
16. digitalWrite(ledPin, LOW); // Turn LED OFF
17. Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
18. state = 0;
19. }
20. else if (state == '1') {
21. digitalWrite(ledPin, HIGH);
22. Serial.println("LED: ON");;
23. state = 0;
24. }
25. }
2. Lab Tasks:
In-Lab Tasks:
Design a system to control 3 lights (LEDs) from smartphone Bluetooth app and
display analog and digital sensors data on smartphone Bluetooth app
Post-Lab Task:
Design Bluetooth APP based smart home automation control system that remote
control of lights, display temperature and humidity level of a home
Lab-8: Arduino External Interrupts (An interrupts based
Devices Control)
This lab will be focused on how to use Arduino interrupts. Unlike timer interrupts, external
interrupts are triggered by external events. For example, when a button is pushed or you
receive a pulse from a rotary encoder. However, just like the timer interrupts, you don’t need
to keep polling the GPIO pins for a change.
Lab Objectives
The objectives of this lab is to explore how the interrupts work. First, we will see what are
Arduino interrupts? After that we will see the general concepts of interrupts. We will see how
to use interrupt service routine with Arduino. At the end of lab, we will take two examples to
demonstrate the effect and use of Arduino projects in real world embedded systems projects.
Lab Background and Getting Knowledge of:
1. Basic Understanding of Interrupts. Student will learn the basic of interrupts
working and interrupt service routines.
2. Interfacing of Actuator working with Interrupts. After this lab, Student
should be able to understand how link the interrupt service routine with external
PINs interrupts.
Laboratory Pre-Exercise Tasks Overview:
1.1 What is an Interrupts?
Interrupts are the section of hardware and software on microcontroller which is
capable of monitoring the external event on the input pin when any external event is
monitor then the program is stop execution at this point and jump into their ISR function
which is a interrupt handler then after executing the ISR function go back that point where
the external event is monitor than it complete there execution. Different types of Arduino
board have different numbers of interrupts pins e.g. Arduino UNO have two interrupt
ports and Arduino Mega2560 have six interrupt ports named as INT1,INT0. On the
Above is the example of execution so line by line the code is execute until interrupt is called
on Line3 then the function jumps down to the ISR and started executing the line5 and line
6 than after executing the lines within the ISR it jumps back to line4 and finishing the
execution as routine. If it is in loop than go back to line1.
1.3 How an Interrupt is triggered?
In Arduino interrupts, you can set how the interrupts are been triggered. There
are five types of triggering Arduino interrupts:
Change: When signal change even if signal rise or signal fall or if the signal is
in low state at 0 or if the signal is in high state trigger 5v.
Rising: On a rising edge the signal going from low to high means signal
triggering from 0v to 5v.
Falling: On a falling edge the signal going from high to low means signal is
triggering from 5v to 0v.
Low: Low is a continuous trigger whenever the signal is low in other words the
signal is on 0v.
High: High is a continuous trigger whenever the signal is high in other words
the signal is on 5v.
1.4 How to use an Arduino interrupts?
Now lets see how to use Arduino interrupts functions already available in Arduino
IDE to initialize Arduino interrupts and with which pin of Arduino you want to
initialize it. Attach interrupt function is used for this purpose. This function takes
two arguments as a input. one is a pin number to which pin you want to use for
external interrupt triggering. Second argument is function name to which you want
to call upon every interrupt. Last argument is the types of interrupt you are using.
we have explained five types above.
attachInterrupt ( digitalPinToInterrupt ( pin ), ISR, mode ) ;
e.g.
attachInterrupt ( digitalPinToInterrupt ( 2 ), InterruptFunction, Low ) ;
1.5 Schematic and Code for Blinking LED using Interrupts
2. Lab Tasks:
In-Lab Tasks:
Design a system to control smart home light using the PIN change interrupts
Post-Lab Task:
Design Rest-room exhaust fan and light control 1) using PIR sensors to detect the
entrance, exit and number of persons in the rest-room area 2) If no body in rest-room
area then switch OFF exhaust fan and lights otherwise turn it ON.
Lab-9: Arduino-Controlled Smart Home Internet-of-Things
Platform (Web-Controlled Smart Home Appliances)
This lab will be focused on to build a smart home device which can be used to control the home
appliances via internet. The home automation device that you build can be integrated with
almost all the home appliances and can be used to control them remotely from any part of the
world. To facilitate the wireless connectivity with the system, the Arduino Uno will be
embedded with a WiFi module. This establishes the internet connection to the system and all
the home appliances can in turn be connected and controlled by internet.
Lab Objectives
The objectives of this lab is to explore what is internet-of-things. First, we will see how the
home legacy devices can be connected to the internet to remotely access it. Second, we will see
how the local-IP can be port-forward in order to access the local home appliances that are
internet enabled now.
The technological trends of IoTs and WoTs show that the next‐generation smart home
environment will be ubiquitous, pervasive, and perceptual. The pervasive systems without
user interaction support will not exist, and the system which is difficult to use, obtrusive
and subject to risks, will not be used by users. Smart home embeds computing capabilities,
networking, and telecommunication interfaces in the home appliances in order to facilitate
everyday life. The smart home environment comprises sensors, actuators, interfaces, and
appliances networked together to provide localized and remote control of the environment.
Sensing and monitoring of environment include temperature, humidity, light, and motion.
Environment control such as heater and fan ON/OFF control is provided by the actuator
having dedicated hardware interfaces and computing capabilities.
Figure 3: Overview of the Port Forwarding at Switch (AP) for Remote Access
float Temperature;
float Humidity;
ESP8266WebServer server(8089);
int i = 0;
int j = 0;
int k = 0;
void setup() {
Serial.begin(9600);
delay(100);
dht.begin();
pinMode(FANpin, OUTPUT);
pinMode(LEDpin, OUTPUT);
// pinMode(DOORpin, OUTPUT);
pinMode(DHTPin, INPUT);
myservo.attach(DOORpin);
Serial.println("Connecting to ");
Serial.println(ssid);
server.on("/", handle_OnConnect);
server.on("/ledon", handle_ledon);
server.on("/ledoff", handle_ledoff);
server.onNotFound(handle_NotFound);
server.on("/fanon", handle_fanon);
server.on("/fanoff", handle_fanoff);
server.on("/dooropen", handle_dooropen);
server.on("/doorclose", handle_doorclose);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
if(LEDstatus)
digitalWrite(LEDpin, HIGH);
else
digitalWrite(LEDpin, LOW);
if(FANstatus)
digitalWrite(FANpin, HIGH);
else
digitalWrite(FANpin, LOW);
if(DOORstatus)
myservo.write(90);
//digitalWrite(DOORpin, HIGH);
else
myservo.write( 0 );
//digitalWrite(DOORpin, LOW);
}
void handle_OnConnect() {
LEDstatus = LOW;
FANstatus = LOW;
myservo.write(0);
//DOORstatus = LOW;
i = 0;
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
// Temperature = 20.34;
// Humidity = 17.01;
server.send(200, "text/html" ,SendHTML());
}
void handle_ledon() {
LEDstatus = HIGH;
i = 1;
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
// Temperature = 20.01;
// Humidity = 16.01;
server.send(200, "text/html",SendHTML());
}
void handle_ledoff() {
LEDstatus = LOW;
i = 0;
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
// Temperature = 10.34;
// Humidity = 13.01;
server.send(200, "text/html",SendHTML());
}
void handle_fanon() {
FANstatus = HIGH;
j = 1;
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
// Temperature = 22.34;
// Humidity = 13.01;
server.send(200, "text/html",SendHTML());
}
void handle_fanoff() {
FANstatus = LOW;
j = 0;
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
// Temperature = 12.34;
// Humidity = 11.01;
server.send(200, "text/html",SendHTML());
}
void handle_dooropen() {
//DOORstatus = HIGH;
myservo.write(90);
k = 1;
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
// Temperature = 18.34;
// Humidity = 7.01;
server.send(200, "text/html",SendHTML());
}
void handle_doorclose() {
//DOORstatus = LOW;
myservo.write(0);
k = 0;
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
//Temperature = 2.34;
//Humidity = 1.01;
server.send(200, "text/html",SendHTML());
}
void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}
String SendHTML(){
String ptr = "<!DOCTYPE html>";
ptr += "<html>";
ptr += "<head>";
ptr += "<title>Home_Automation_NodeMCU</title>";
ptr += "</head>";
ptr += "<body>";
ptr += "<h1 style='vertical-align: text-top;color:black;line-height:40px;font-
size:48px;font:EraslightITC;text-align:center;background-color:cyan'><img src='home.png'
alt='Home_Logo'> Home Automation</h2>";
if(i == 0)
ptr += "<h2 style='text-align:center;'><input type=\"button\" style='background-color:white;font-
size:37px;font:EraslightITC;'value=\"Bed Room Light OFF\" id=\"light\"></input></h2>";
else
ptr += "<h2 style='text-align:center;'><input type=\"button\" style='background-color:white;font-
size:37px;font:EraslightITC;'value=\"Bed Room Light ON\" id=\"light\"></input></h2>";
ptr += "<h2 style='text-align:center'>";
ptr += "<button onclick=\"window.location.href='/ledon'; light_on();\" style='color:black;line-
height:42px;font-size:39px;font:EraslightITC;button-align:center;background-color:cyan' > Light ON
</button>";
ptr += "<button onclick=\"window.location.href='/ledoff'; light_off();\" style='color:black;line-
height:42px;font-size:39px;font:EraslightITC;button-align:center;background-color:cyan' > Light OFF
</button>";
if(j == 0)
ptr += "<h2 style='text-align:center;'><input type=\"button\" style='background-color:white;font-
size:38px;font:EraslightITC;'value=\"Bed Room Fan OFF\" id=\"fan\"></input></h2>";
else
ptr += "<h2 style='text-align:center;'><input type=\"button\" style='background-color:white;font-
size:38px;font:EraslightITC;'value=\"Bed Room Fan ON\" id=\"fan\"></input></h2>";
if(k == 0)
ptr += "<h2 style='text-align:center;'><input type=\"button\" style='background-color:white;font-
size:68px;font:EraslightITC' value=\"Door Close\" id=\"door\"></input></h2>";
else
ptr += "<h2 style='text-align:center;'><input type=\"button\" style='background-color:white;font-
size:68px;font:EraslightITC' value=\"Door Open\" id=\"door\"></input></h2>";
ptr += "<h2 style='text-align:center'>";
ptr += "<button onclick=\"window.location.href='/dooropen'; door_open();\" style='color:black;line-
height:34px;font-size:33px;font:EraslightITC;button-align:center;background-color:cyan'> Door Open
</button>";
ptr += "<button onclick=\"window.location.href='/doorclose'; door_close();\" style='color:black;line-
height:34px;font-size:33px;font:EraslightITC;text-align:center;background-color:cyan'> Door Close
</button></h2>";
ptr += "<script>";
ptr += "function fan_off() {document.getElementById(\"fan\").value = \"Bed Room Fan OFF\"; }";
ptr += "</script>";
ptr += "<script>";
ptr += "function fan_on() {document.getElementById(\"fan\").value = \"Bed Room Fan ON\";}";
ptr += "</script>";
ptr += "<script>";
ptr += "function light_off() {document.getElementById(\"light\").value = \"Bed Room Light OFF\";}";
ptr += "</script>";
ptr += "<script>";
ptr += "function light_on() {document.getElementById(\"light\").value = \"Bed Room Light ON\";}";
ptr += "</script>";
ptr += "<script>";
ptr += "function door_open() {document.getElementById(\"door\").value = \"Door Open\";}";
ptr += "</script>";
ptr += "<script>";
ptr += "function door_close() {document.getElementById(\"door\").value = \"Door Close\";}";
ptr += "</script>";
ptr += "</body>";
ptr += "</html>";
return ptr;
}
2. Lab Tasks:
In-Lab Tasks:
Configure the NodeMCU (WiFi) and control 3-LEDs to turn them ON/OFF from
internet
Post-Lab Task:
Design Web-enabled Smart Home System to control remotely home lighting
system, FAN, Door, and show the temperature and humidity on webpage
Lab-10: Data Transfer of Arduino-Controlled Smart Home to
Thingspeak Cloud
This lab will be focused on cloud data storage and visualization. Thingspeak is an IoT analytics
cloud platform service that allows you to aggregate, visualize, and analyze live data streams
in the cloud. You can send data to Thingspeak from your devices, create instant visualizations
of live data, and send alerts using web services. Thingspeak enables engineers and scientists
to prototype and build IoT systems without setting up servers or developing web software.
Lab Objectives
The objectives of this lab is to explore Configure devices to send data to Thingspeak using a
REST API or MQTT. Aggregate data on-demand from devices and third-party sources. Get
instant visualizations of live or historical sensor data. Run your IoT analytics automatically
based on schedules or events. Act on your data and communicate using third-party services
like Twitter.
First, it will get connected to the WiFi Network. Then, immediately, it will try to read the data
from the DHT11 Humidity sensor and calculate the Temperature and Humidity values based
on that data. After this, the values of temperature and humidity will be uploaded to the
Thingspeak API. If you open your channel in the Thingspeak, you can see the chart associated
with the values from the DHT11 Sensor.
1.4 Flow Chart and Source for Smart Home Data to Cloud
Figure 2: Flow chart for connecting devices to the Cloud using NodeMCU
2. Lab Tasks:
In-Lab Tasks:
Configure the Thingspeak cloud and Design NodeMCU based to acquire the humidity
and temperature data and display on cloud
Post-Lab Task:
Design cloud-based Smart Home System to store and visualize home lighting
system, FAN, Door, temperature and humidity
Lab-11: Introduction of Raspberry PI, Installation of
RTOS/Raspbian Operating System, Database on System-on-
Chip (Raspberry Pi) MYSQL
These labs will be focused on concepts of System-on-Chip designing and specifically on
Raspberry-PI board. The Raspberry Pi is a series of small single-board computers developed
in the United Kingdom by the Raspberry Pi Foundation to promote teaching of basic computer
science in schools and in developing countries.
Lab Objectives
The objectives of these lab is to explore system-on-chip, Real Time operating, and databases
to store the embedded system.
Lab Objectives
The objectives of this lab are to explore system-on-chip, Real Time operating system and
basics of Python IDE.
Raspbian OS is official Operating System available for free to use. This OS is efficiently
optimized to use with Raspberry Pi. Raspbian have GUI which includes tools for
Browsing, Python programming, office, games, etc. We should use SD card (minimum 8
GB recommended) to store the OS (operating System).
Raspberry Pi is more than computer as it provides access to the on-chip hardware i.e.
GPIOs for developing an application. By accessing GPIO, we can connect devices like
LED, motors, sensors, etc and can control them too.
It has ARM based Broadcom Processor SoC along with on-chip GPU (Graphics
Processing Unit). The CPU speed of Raspberry Pi varies from 700 MHz to 1.2 GHz. Also,
it has on-board SDRAM that ranges from 256 MB to 1 GB. Raspberry Pi also provides on-
chip SPI, I2C, I2S and UART modules.
Hardware requirements:
Operating Systems:
Use NOOBS
Use NOOBS Lite
Download only Raspbian image file
NOOBS
http://www.raspberrypi.org/downloads/
Procedure:
An SD card is needed to store Raspbian. For this purpose connect micro SD card to SD
card reader.
Difference between using NOOBS and Downloading Raspbian Image.
Download the NOOBS or the Raspbian image file from the following links
http://www.raspberrypi.org/downloads/downloads/noobs/
http://www.raspberrypi.org/downloads/downloads/raspbian/
Writing image to Micro SD card
A specific software is required to write the Raspbian image on to the MicroSD card.
Win32 Disk Imager is the software that can be used for this purpose. It can be
downloaded from the following link
http://sourceforge.net/projects/win32diskimager/
Setup Win32 Disk Imager
Like most programming languages, Python works in tandem with an interpreter that
executes the finalized lines of codes. There are lots of free resources to learn the Python
coding language, which, with its basis in English syntax, is considered one of the least
fussy and most straightforward coding languages to learn and read.
Most distributions of Linux come with Python 3 already installed, but they might not
have IDLE, the default IDE (interactive development environment), installed.
Use apt to check whether they are installed and install them if they aren’t.
This will install Python 3 (and IDLE), and you should then be able to find it in your
Application menu.
1. Lab Tasks:
In-Lab Tasks:
Lab Objectives
The objectives of this lab is to implement the lab already performed on Arudino on
Raspberry-PI now. The student will be able to convert the Arudino C based programming
into Python.
Interfacing LDR:
LDR “light-dependent resistor to control an LED” light-emitting diode” can be interfaced with
Raspberry PI to measure intensity of light. The LED will be turned on and turned off depending
on the light intensity in the room. This project can also be used for day and night detection.
Components required:
Raspberry PI
Breadboard
LED
Resistor
Photoresistor 3 pin
Jumper cables
Schematic Diagram of connecting LDR with Raspberry Pi:
Interfacing Proximity Sensor with Raspberry Pi to measure distance:
Ultrasonic Sensors, particularly HC-SR04 Ultrasonic Sensor, are very popular among
electronic hobbyists and are frequently used in a variety of projects like Obstacle
Avoiding Robot, Distance Measurement, Proximity Detection and so forth. In this project,
we will learn about HC-SR04 Ultrasonic and see how to interface one with Raspberry Pi.
Ultrasonic Sensor:
An ultrasonic sensor is an electronic device that measures the distance of a target object
by emitting ultrasonic sound waves, and converts the reflected sound into an electrical
signal. Ultrasonic waves travel faster than the speed of audible sound (i.e., the sound that
humans can hear).
Components required:
Raspberry PI
Breadboard
LED
Resistor
Photoresistor 3 pin
Jumper cables
Schematic Diagram of connecting Ultrasonic sensor with Raspberry Pi:
Pi Camera Module Interface with Raspberry Pi using Python
Pi Camera module is a camera which can be used to take pictures and high-definition
video. Raspberry Pi Board has CSI (Camera Serial Interface) interface to which we can
attach PiCamera module directly.
This Pi Camera module can attach to the Raspberry Pi’s CSI port using 15-pin ribbon
cable.
Features of Pi Camera
Resolution – 5 MP
HD Video recording – 1080p @30fps, 720p @60fps, 960p @45fps and so on.
For enabling camera in Raspberry Pi, open raspberry pi configuration using following
command,
sudo raspi-config
then select Interfacing options in which select camera option to enable its functionality.
Now we can access camera on Raspberry Pi and can capture images and videos using Pi
Camera on Raspberry Pi.
1. Lab Tasks:
In-Lab Tasks:
Post-Lab Task:
Interfacing PI-camera with Raspberry PI, capturing images, and store it to a drive
Interface ultrasonic sensor with Raspberry Pi using Python coding (Complete the
Following Table)