You are on page 1of 83

MADANAPALLE INSTITUTE OF TECHNOLOGY &

SCIENCE
(UGC AUTONOMUS)

MADANAPALLE – 517325

18ECE209 – INTERNET OF THINGS


LABORATORY MANUAL

DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
(R18 BATCH)

1
MADANAPALLE INSTITUTE OF TECHNOLOGY &
SCIENCE
(UGC AUTONOMUS)

MADANAPALLE – 517325

LABORATORY MANUAL
FOR
INTERNET OF THINGS- 18ECE209
DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
(2020 -2021)
PREPEARED BY VERFIFED BY APPROVED BY
Name: Name:Dr.Sathesh.K Name: Dr.S.Rajeskaran
Dr.Satrughan Kumar
Dr.Bibhuti Bhusan Pradhan
Dr.Sharwan Ram
Dr.Velmani Ramasamy
Dr.Sambhudutta Nanda
Dr.Sumit Gupta
Designation: Designation: Assoc. Professor Designation: Professor &Head
Professor
Sr.Asst. Professor
Assoc. Professor
Asst. Professor

Signature: Signature: Signature:

2
MADANAPALLE INSTITUTE OF TECHMOLOGY & SCIENCE
(UCG-AUTONOMOUS)
Affiliated to JNTUA, Ananthapuramu & Approved by AICTE, New Delhi
Recognised Research Center, Accredited by NBA, NAAC for CSE, ECE, EEE, ME & MBA
World Bank Funded Institute, Recognised by UGC under the sections 2(f) and 12(B) of the UGC act 1956
Recognised as Scientific & Industrial Research Organization by DSIR of DST
Department of Electronics & Communication Engineering
---------------------------------------------------------------------------------------------------------------------

Name of the Lab Course : Internet of Things Laboratory-18ECE209

Code : 18ECE209 Programme: UG


Branch: ECE Version No: 1
Year : III Updated on:22/02/21
Semester : II No. of Pages:72

Classification Status(Unrestricted/restricted):Unrestricted
Distribution List : Department, Lab, Lab Incharge
PREPEARED BY VERFIFED BY APPROVED BY
Name: Name: Dr.Sathesh.K Name: Dr.S.Rajeskaran
Dr.Satrughan Kumar
Dr.Bibhuti Bhusan Pradhan
Dr.Sharwan Ram
Dr.Velmani Ramasamy
Dr.Sambhudutta Nanda
Dr.Sumit Gupta

Designation: Designation: Assoc. Professor Designation: Professor &Head


Professor
Sr.Asst. Professor
Assoc. Professor
Asst. Professor

Signature: Signature: Signature:

3
MADANAPALLE INSTITUTE OF TECHMOLOGY & SCIENCE
(UCG-AUTONOMOUS)
Affiliated to JNTUA, Ananthapuramu & Approved by AICTE, New Delhi
Recognised Research Center, Accredited by NBA, NAAC for CSE, ECE, EEE, ME & MBA
World Bank Funded Institute, Recognised by UGC under the sections 2(f) and 12(B) of the UGC act 1956
Recognised as Scientific & Industrial Research Organization by DSIR of DST
Department of Electronics & Communication Engineering
---------------------------------------------------------------------------------------------------------------------

VISION AND MISSION OF THE INSTITUTE


VISION
To become a globally recognized research and academic institution and thereby contribute to
technological and socio-economic development of the nation.

MISSION
To foster a culture of excellence in research, innovation, entrepreneurship, rational thinking
and civility by providing necessary resources for generation, dissemination and utilization of
knowledge and in the process create an ambience for practice-based learning to the youth for
success in their careers.

VISION AND MISSION OF THE DEPARTMENT

VISION
To excel in technical education and research in the area of Electronics and Communication
Engineering to produce skilled, trained and competent individuals with high motivation to
meet the present-day challenges of the society.

MISSION
M1 Impart high quality education to enable students to face the challenges in the
fields of Electronics and Communication Engineering.

M2 Provide facilities, infrastructure, environment to develop the spirit of


innovation, creativity, and research among students and faculty.

4
M3 Inculcate ethical, moral values and lifelong learning skills in students to address
the societal needs.

5
MADANAPALLE INSTITUTE OF TECHMOLOGY & SCIENCE
(UCG-AUTONOMOUS)
Affiliated to JNTUA, Ananthapuramu & Approved by AICTE, New Delhi
Recognised Research Center, Accredited by NBA, NAAC for CSE, ECE, EEE, ME & MBA
World Bank Funded Institute, Recognised by UGC under the sections 2(f) and 12(B) of the UGC act 1956
Recognised as Scientific & Industrial Research Organization by DSIR of DST
Department of Electronics & Communication Engineering
---------------------------------------------------------------------------------------------------------------------

PROGRAM EDUCATIONAL OBJECTIVES (PEOs)

PEO1 For successful employment in Electronics and Communication Engineering


To design, test and develop the state-of-the-art hardware and software in
PEO2
Electronics and Communication Engineering
PEO3 For lifelong learning skills, societal ethics and higher education.

PROGRAM OUTCOMES (POs)

Engineering knowledge: Apply the knowledge of mathematics, science,


PO1 engineering fundamentals, and an engineering specialization to the solution
of complex engineering problems.
Problem analysis: Identify, formulate, review research literature, and
analyze complex engineering problems reaching substantiated conclusions
PO2
using first principles of mathematics, natural sciences, and engineering
sciences.
Design/development of solutions: Design solutions for complex
engineering problems and design system components or processes that meet
PO3
the specified needs with appropriate consideration for the public health and
safety, and the cultural, societal, and environmental considerations.
Conduct investigations of complex problems: Use research-based
knowledge and research methods including design of experiments, analysis
PO4
and interpretation of data, and synthesis of the information to provide valid
conclusions.
Modern tool usage: Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including prediction and
PO5
modeling to complex engineering activities with an understanding of the
limitations.
The engineer and society: Apply reasoning informed by the contextual
PO6 knowledge to assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to the professional engineering practice.

6
Environment and sustainability: Understand the impact of the professional
PO7 engineering solutions in societal and environmental contexts, and
demonstrate the knowledge of, and need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and
PO8
responsibilities and norms of the engineering practice.
Individual and team work: Function effectively as an individual, and as a member or
PO9
leader in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering
activities with the engineering community and with society at large, such as,
PO10 being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear
instructions.
Project management and finance: Demonstrate knowledge and
understanding of the engineering and management principles and apply
PO11
these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
Life-long learning: Recognize the need for, and have the preparation and
PO12 ability to engage in independent and life-long learning in the broadest
context of technological change.

PROGRAM SPECIFIC OUTCOMES (PSOs)

Design and analyze systems in the field of Electronics and Communication


PSO1
Engineering.
Apply the concepts to design and develop solutions in the field of VLSI & Embedded
PSO2
System.
Analyse and develop hardware/software applications in the field of Signal & System
PSO3
Engineering.

7
MADANAPALLE INSTITUTE OF TECHMOLOGY & SCIENCE
(UCG-AUTONOMOUS)
Affiliated to JNTUA, Ananthapuramu & Approved by AICTE, New Delhi
Recognised Research Center, Accredited by NBA, NAAC for CSE, ECE, EEE, ME & MBA
World Bank Funded Institute, Recognised by UGC under the sections 2(f) and 12(B) of the UGC act 1956
Recognised as Scientific & Industrial Research Organization by DSIR of DST
Department of Electronics & Communication Engineering
---------------------------------------------------------------------------------------------------------------------

ATTAINMENT OF PROGRAM OUTCOMES


&
PROGRAM SPECIFIC OUTCOMES
S. No Experiment Program Program Specific
Outcomes Outcomes Attained
Attained Obtained
1. Study on IoT Platform(Getting information 1, 5 1, 2
and study of IOT microcontrollers)
2. Study on IoT Platform 1, 5 1, 2
a)Getting information about Sensors (IR,
temperature, pressure, gas sensor)
b) Getting information about actuators
(Piezoelectric actuator, pneumatic actuator).
3. . Programming with Arduino platform 1, 3, 5 1, 2
a)Installation of Arduino in computer and
verifying any errors in connection.
b) Control LED using Arduino
c) Traffic Light Control
4. Programming with Arduino platform and 1, 3, 5 1, 2
Reading from Sensors
a) interfacing sensors to Arduino board and
getting information from them (any two
sensors).
b) Experiment with both analog and digital
sensors.
5. Programming with Resperrypi 1, 3, 5 1, 2
a) Displaying Date on Serial Monitor
b) Automated Door Opening System
6. Connecting Android Phone with Arduino 1, 3, 5 1, 2
a) Connecting Arduino with Mobile Device
Using the Bluetooth Module.
b) Control any two actuators connected to the
development board using Bluetooth.
7. Integrating Ethernet Shield. 1, 3, 5 1, 2
Read data from sensor and send it to a
requesting client using socket communication.
Note: The client and server should be connected

8
to same local area network
8. Creating Mobile App 1, 3, 5 1, 2
a) Create a mobile app to control an actuator.
b) Control Electronic Devices from anywhere
across the world using Internet & Mobile
App.
9. Interfacing Cloud 1, 3, 5 1, 2
a) Push sensor data to cloud - Use Arduino to
Upload data from Environmental Sensors to
Cloud Server.
b) Control an actuator through cloud
10. Data analysis and Visualization 1, 2, 3, 5 1, 2
Access the data pushed from sensor to cloud
and apply any data analytics or visualization
services.
11. Social media with IoT 1, 3, 5 1, 2
Creating Program for Local host Web Server
for controlling devices and update status on
Twitter through Arduino.
Content beyond Syllabus
12. Identify a problem in your local area or college 1, 2, 3, 5, 1, 2
which can be solved by integrating the things 9, 11
you learned so far and create a prototype to
solve it.

9
MADANAPALLE INSTITUTE OF TECHMOLOGY & SCIENCE
(UCG-AUTONOMOUS)
Affiliated to JNTUA, Ananthapuramu & Approved by AICTE, New Delhi
Recognised Research Center, Accredited by NBA, NAAC for CSE, ECE, EEE, ME & MBA
World Bank Funded Institute, Recognised by UGC under the sections 2(f) and 12(B) of the UGC act 1956
Recognised as Scientific & Industrial Research Organization by DSIR of DST

Department of Electronics & Communication Engineering


---------------------------------------------------------------------------------------------------------------------
SYLLABUS
18ECE209 INTERNET OF THINGS PRACTICALS
Course Prerequisite: 18ECE209

Course Description
This course provide hands-on practices on IoT using Arduino & Raspberry microcontrollers with
various interfaces such as sensors, actuators, mobile app, cloud, social media.
Course Objectives
1. To understand working principles of IoT devices
2. To get exposure towards the IoT internals.
3. To understand the concepts of real world designs, industrial automation and commercial
needs for designing IOT enabled solution

LIST OF EXPERIMENTS:
1. Study on IoT Platform
a) Getting information and study of IOT microcontrollers (Arduino, Resperrypi)
2. Study on IoT Platform
a) Getting information about Sensors (IR, temperature, pressure, gas sensor)
b) Getting information about actuators. (Piezoelectric actuator, pneumatic actuator)
3. Programming with Arduino platform
a) Installation of Arduino in computer and verifying any errors in connection.
b) Control LED using Arduino
c) Traffic Light Control
4.Programming with Arduino platform and Reading from Sensors
a) interfacing sensors to Arduino board and getting information from them (any two sensors).
b) Experiment with both analog and digital sensors.
5.Programming with Resperrypi
a) Displaying Date on Serial Monitor
b) Automated Door Opening System
6.Connecting Android Phone with Arduino
a) Connecting Arduino with Mobile Device Using the Bluetooth Module.
b) Control any two actuators connected to the development board using Bluetooth.
7. Integrating Ethernet Shield. Read data from sensor and send it to a requesting client using
socket communication.
8. Creating Mobile App
a) Create a mobile app to control an actuator.
b) Control Electronic Devices from anywhere across the world using Internet & Mobile App.
10
9. Interfacing Cloud
a) Push sensor data to cloud - Use Arduino to Upload data from Environmental Sensors to
Cloud Server.
b) Control an actuator through cloud
10. Data analysis and Visualization
Access the data pushed from sensor to cloud and apply any data analytics or visualization
services.
11. Social media with IoT
Creating Program for Local host Web Server for controlling devices and update status on
Twitter through Arduino.
12. Mini Project Identify a problem in your local area or college which can be solved by
integrating the things you learned so far and create a prototype to solve it.

Course Outcomes
Upon successful completion of the course, students will be able to
1. Choose the sensors and actuators for an IoT application
2. Select protocols for a specific IoT application.
3. Utilize the cloud platform and APIs for IoT application .
4. Experiment with embedded boards for creating IoT prototypes.
5. Design and develop a solution for a given IoT application.

11
LIST OF EXPERIMENTS

S. No. Experiment Page No.

1 Study on IoT Platform(Getting information and study of IOT 14-32


microcontrollers)
Study on IoT Platform
2 a)Getting information about Sensors (IR, temperature, pressure, 33-41
gas sensor)
b) Getting information about actuators(Piezoelectric actuator,
pneumatic actuator).
Programming with Arduino platform
3 a)Installation of Arduino in computer and verifying any errors in 42-52
connection.
b) Control LED using Arduino
c) Traffic Light Control
Programming with Arduino platform and Reading from Sensors
4 a) interfacing sensors to Arduino board and getting information from 53-55
them (any two sensors).
b) Experiment with both analog and digital sensors.
Programming with Resperrypi
5 a) Displaying Date on Serial Monitor 56-60
b) Automated Door Opening System
Connecting Android Phone with Arduino
6 a) Connecting Arduino with Mobile Device Using the Bluetooth 61-66
Module.
b) Control any two actuators connected to the development board
using Bluetooth.
Integrating Ethernet Shield.
7 Read data from sensor and send it to a requesting client using socket
communication. Note: The client and server should be connected to
same local area network
Creating Mobile App
8 a) Create a mobile app to control an actuator. 67-70
b) Control Electronic Devices from anywhere
across the world using Internet & Mobile App.
Interfacing Cloud
9 a) Push sensor data to cloud - Use Arduino to Upload data from 71-
Environmental Sensors to Cloud Server.
b) Control an actuator through cloud
Data analysis and Visualization
10 Access the data pushed from sensor to cloud and apply any data 72-
analytics or visualization services.

12
Social media with IoT
11 Creating Program for Local host Web Server for controlling devices
and update status on Twitter through Arduino.

13
GENERAL GUIDELINES AND SAFETY INSTRUCTIONS
1. Sign in the log register as soon as you enter the lab and strictly observe your lab
timings.
2. Strictly follow the written and verbal instructions given by the teacher / Lab
Instructor. If you do not understand the instructions, the handouts and the procedures,
ask the instructor or teacher.
3. Never work alone! You should be accompanied by your laboratory partner and / or
the instructors / teaching assistants all the time.
4. It is mandatory to come to lab in a formal dress and wear your ID cards.
5. Do not wear loose-fitting clothing or jewelry in the lab. Rings and necklaces are usual
excellent conductors of electricity.
6. Mobile phones should be switched off in the lab. Keep bags in the bag rack.
7. Keep the labs clean at all times, no food and drinks allowed inside the lab.
8. Intentional misconduct will lead to expulsion from the lab.
9. Do not handle any equipment without reading the safety instructions. Read the
handout and procedures in the Lab Manual before starting the experiments.
10. Do your wiring, setup, and a careful circuit checkout before applying power. Do not
make circuit changes or perform any wiring when power is on.
11. Avoid contact with energized electrical circuits.
12. Do not insert connectors forcefully into the sockets.
13. NEVER try to experiment with the power from the wall plug.
14. Immediately report dangerous or exceptional conditions to the Lab instructor /
teacher: Equipment that is not working as expected, wires or connectors are broken,
the equipment that smells or “smokes”. If you are not sure what the problem is or
what's going on, switch off the Emergency shutdown.
15. Never use damaged instruments, wires or connectors. Hand over these parts to the
Lab instructor/Teacher.
16. Never use damaged instruments, wires or connectors. Hand over these parts to the
Lab instructor/Teacher.
17. Observation book and lab record should be carried to each lab. Readings of current
lab experiment are to be entered in Observation book and previous lab experiment
should be written in Lab record book. Both the books should be corrected by the
faculty in each lab.

14
EXPERIMENT 1
AIM: Getting information and study of IOT microcontrollers (Arduino and Raspberry Pi)

1. THEORY
PART A: STUDY ON ARDUINO BOARD

1.1 Introduction to Arduino Uno Board


Arduino Uno is a microcontroller board based on the 8-bit ATmega328P microcontroller as
shown in Figure 1. Along with ATmega328P, it also contains other components, such as crystal
oscillator, serial communication, voltage regulator, etc. to support the microcontroller. Arduino
Uno has 14 digital input/output pins (6 of which can be used as PWM outputs), 6 analog input
pins, USB connection, power barrel jack, ICSP connector and reset button. It is an open-source
platform, means the boards and software are readily available and anyone can modify and
optimize the boards for better functionality.

Figure 1.1 Arduino UNO Board (ATmega328p)

The software used for Arduino devices is called IDE (Integrated Development Environment)
which is free to use and required some basic skills to learn it. It can be programmed using C and

15
C++ language. Some people get confused between Microcontroller and Arduino. While former is
just an on system 40 pin chip that comes with a built-in microprocessor and later is a board that
comes with the microcontroller in the base of the board, bootloader and allows easy access to
input-output pins and makes uploading or burning of the program very easy.

1.2 The pin category, pin names and its functionality

Table 1.1 shows the pin category, pin names and its functionality
Pin Category Pin Name Details
I. Power Vin, 3.3V, 5V, Vin: Input voltage to Arduino when using
GND an external power source.
5V: Regulated power supply used to power
microcontroller and other components on
the board.
3.3V: 3.3V supply generated by on-board
voltage regulator. Maximum current draw is
50mA.
GND: ground pins.
ii Reset Reset Resets the microcontroller.
iii Analog Pins A0 – A5 Used to provide analog input in the range of
0-5V
iv Input/Output Digital Pins 0 - 13 Can be used as input or output pins.
Pins
v Serial 0(Rx), 1(Tx) Used to receive and transmit TTL serial
data.
vi External 2, 3 To trigger an interrupt.
Interrupts
vii PWM 3, 5, 6, 9, 11 Provides 8-bit PWM output.
viii SPI 10 (SS), 11 Used for SPI communication.
(MOSI), 12
(MISO) and 13
(SCK)
ix Inbuilt LED 13 To turn on the inbuilt LED.
x TWI A4 (SDA), A5 Used for TWI communication.
(SCA)
xi AREF AREF To provide reference voltage for input
voltage.

16
1.3 Technical Specifications of Arduino Uno Board
Table 1.2: Technical Specifications of Arduino Uno Board
S. NO Components Specifications
1. Microcontroller ATmega328P – 8 bit AVR family
microcontroller
2. Operating Voltage 5V
3. Recommended Input Voltage 7-12V
4. Input Voltage Limits 6-20V
5. Analog Input Pins 6 (A0 – A5)
6. Digital I/O Pins 14 (Out of which 6 provide PWM
output)
7. DC Current on I/O Pins 40 mA
8. DC Current on 3.3V Pin 50 mA
9. Flash Memory 32 KB (0.5 KB is used for Bootloader)
10. SRAM 2 KB
11. EEPROM 1 KB
12. Frequency (Clock Speed) 16 MHz

1.4 Arduino Uno to ATmega328 Pin Mapping

When ATmega328 chip is used in place of Arduino Uno, or vice versa, the image below
shows the pin mapping between the two.

Figure 1.2 ATmega328 Pin Mapping

17
1.5 How to use Arduino Board

1.5.1 Digital Pins


The 14 digital input/output pins can be used as input or output pins by using pinMode(),
digitalRead() and digitalWrite() functions in arduino programming. Each pin operates at 5V and
can provide or receive a maximum of 40mA current, and has an internal pull-up resistor of 20-50
KOhms which are disconnected by default. Out of these 14 pins, some pins have specific
functions as listed below:

1. Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. On
the Arduino Diecimila, these pins are connected to the corresponding pins of the FTDI USB-
to-TTL Serial chip. On the Arduino BT, they are connected to the corresponding pins of
the WT11 Bluetooth module. On the Arduino Mini and LilyPad Arduino, they are intended for
use with an external TTL serial module (e.g. the Mini-USB Adapter).

2. External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a


low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for
details.

3. PWM: 3, 5, 6, 9, 10, and 11. provide 8-bit PWM output with the analogWrite() function.
On boards with an ATmega8, PWM output is available only on pins 9, 10, and 11.

4. BT Reset: 7. (Arduino BT-only) Connected to the reset line of the Bluetooth module.

5. SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication,
which, although provided by the underlying hardware, is not currently included in the
Arduino language.

6. LED: 13. On the Diecimila and LilyPad, there is a built-in LED connected to digital pin 13.
When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.

1.5.2 Analog Pins


In addition to the specific functions listed below, the analog input pins support 10-bit analog-to-
digital conversion (ADC) using the analogRead() function. Most of the analog inputs can also be

18
used as digital pins: analog input 0 as digital pin 14 through analog input 5 as digital pin 19.
Analog inputs 6 and 7 (present on the Mini and BT) cannot be used as digital pins.

 I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire
library (documentation on the Wiring website).

1.5.3 Power Pins

 VIN: (sometimes labelled "9V"). The input voltage to the Arduino board when it's using
an external power source (as opposed to 5 volts from the USB connection or other
regulated power source). You can supply voltage through this pin, or, if supplying
voltage via the power jack, access it through this pin. Note that different boards accept
different input voltages ranges, please see the documentation for your board. Also note
that the LilyPad has no VIN pin and accepts only a regulated input.
 5V: The regulated power supply used to power the microcontroller and other components
on the board. This can come either from VIN via an on-board regulator, or be supplied by
USB or another regulated 5V supply.
 3V3: (Diecimila-only) A 3.3 volt supply generated by the on-board FTDI chip.
 GND: Ground pins.

1.5.4 Other Pins

1. AREF. Reference voltage for the analog inputs. Used with analogReference().
2. Reset. (Diecimila-only) Bring this line LOW to reset the microcontroller. Typically used
to add a reset button to shields which block the one on the board.

1.6 ARCHITECTURE AND BASIC WORKING OF CPU OF ATMEGA328


a) The data is uploaded in serial via the port (being uploaded from the computer’s Arduino
IDE). The data is decoded and then the instructions are sent to instruction register and it
decodes the instructions on the same clock pulse.
b) On the next clock pulse the next set of instructions are loaded in instruction register.
In general purpose registers the registers are of 8-bit but there are 3 16-bit registers also.

19
c) 16-bit registers are used to store data of timer counter in 2 different register. Eg. X-low &
X-high. They are fast, and are used to store specific hardware functions. 8-bit registers
are used to store data for normal calculations and results.

Figure 1.3 Architecture of Arduino Uno (ATmega328 IC)

4. EEPROM stores data permanently even if the power is cut out. Programming inside a
EEPROM is slow.

5. Interrupt Unit checks whether there is an interrupt for the execution of instruction to be
executed in ISR (Interrupt Service Routine).

20
6. Serial Peripheral Interface (SPI) is an interface bus commonly used to send data between
microcontrollers and small peripherals such as Camera, Display, SD cards, etc. It uses
separate clock and data lines, along with a select line to choose the device you wish to talk to.

7.Watchdog Timer is used to detect and recover from MCU malfunctioning.

8. Analog comparator compares the input values on the positive and negative pin, when the
value of positive pin is higher the output is set.

9. Status and control is used to control the flow of execution of commands by checking other
blocks inside the CPU at regular intervals

10. ALU The high performance AVR ALU operates in direct connection with all the 32
general purpose working registers. Within a single clock cycle, arithmetic operations b/w
general purpose registers are executed. The ALU operations are divided into 3 main
categories – arithmetic, logical and bit-function.

11. I/O pins The digital inputs and outputs (digital I/O) on the Arduino are what allow you to
connect the Arduino sensors, actuators, and other ICs. Learning how to use them will allow
you to use the Arduino to do some really useful things, such as reading switch inputs, lighting
indicators, and controlling relay outputs.

1.7 Communication in Arduino board


Arduino can be used to communicate with a computer, another Arduino board or other
microcontrollers. The ATmega328P microcontroller provides UART TTL (5V) serial
communication which can be done using digital pin 0 (Rx) and digital pin 1 (Tx). An
ATmega16U2 on the board channels this serial communication over USB and appears as a
virtual com port to software on the computer. The ATmega16U2 firmware uses the standard
USB COM drivers, and no external driver is needed. However, on Windows, a .inf file is
required. The Arduino software includes a serial monitor which allows simple textual data to be
sent to and from the Arduino board. There are two RX and TX LEDs on the Arduino board
which will flash when data is being transmitted via the USB-to-serial chip and USB connection
to the computer (not for serial communication on pins 0 and 1). A SoftwareSerial library allows
for serial communication on any of the Uno's digital pins. The ATmega328P also supports I2C

21
(TWI) and SPI communication. The Arduino software includes a Wire library to simplify use of
the I2C bus.

1.8 SOFTWARE AND PROGRAMING ON ARDUINO BOARD

1.8.1 Software

Arduino IDE (Integrated Development Environment) is required to program the Arduino Uno
board https://www.arduino.cc/en/software.

1.8.2 Programming Arduino

Once Arduino IDE is installed on the computer, connect the board with computer using
USB cable. Now open the Arduino IDE and choose the correct board by selecting
Tools>Boards>Arduino/Genuino Uno, and choose the correct Port by selecting Tools > Port.
Arduino Uno is programmed using Arduino programming language based on Wiring. To get it
started with Arduino Uno board and blink the built-in LED, load the example code by selecting
Files >Examples > Basics > Blink. Once the example code (also shown below) is loaded into
your IDE, click on the ‘upload’ button given on the top bar. Once the upload is finished, you
should see the Arduino’s built-in LED blinking. Below is the example code for blinking:

// 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 the LED on (HIGH is
the voltage level)
delay(1000); // wait for a second

22
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by
making the voltage LOW
delay(1000); // wait for a second
}

1.9 APPLICATION ON ARDUINO BOARD


1. Prototyping of Electronics Products and Systems
2. Multiple DIY Projects.
3. Easy to use for beginner level DIYers and makers.
3. Projects requiring Multiple I/O interfaces and communications.

PART B: STUDY ON RASPBERRY PI

2.1 INTRODUCTION TO RASPBERRY PI

Raspberry Pi is a series of small single-board computers developed in the United


Kingdom by the Raspberry Pi Foundation in association with Broadcom. The Raspberry Pi
project originally leaned towards the promotion of teaching basic computer science in schools
and in developing countries. Created by the Raspberry Pi Foundation, the Raspberry Pi is an
open-source, Linux based, credit card sized computer board. The Pi is an exciting and accessible
means of improving computing and programming skills for people of all ages. By connecting to
your TV or monitor and a keyboard, and with the right programming, the Pi can do many things
that a desktop computer can do such as surf the internet and play video. The Pi is also great for
those innovative projects that you want to try out - newer models are ideal for Internet of Things
projects due to their processing power. With Pi 3, Wireless LAN and Bluetooth Low Energy are
on-board too. The original model became more popular than anticipated, selling outside its target
market for uses such as robotics. It is widely used in many areas, such as for weather
monitoring because of its low cost, modularity, and open design. It is typically used by computer
and electronic hobbyists, due to its adoption of HDMI and USB devices.

2.1.1 Generations of Raspberry Pi


Several generations of Raspberry Pi have been released.

23
1. The first generation (Raspberry Pi Model B) was released in February 2012, followed by
the simpler and cheaper Model A. These first generation boards feature ARM11 processors,
are approximately credit-card sized and represent the standard mainline form-factor.
2. The Raspberry Pi 2 was released in February 2015 and initially featured a 900 MHz 32-
bit quad-core ARM Cortex-A7 processor with 1 GiB RAM. Later versions featured a
1.2 GHz 64-bit quad-core ARM Cortex-A53 processor.
3. Raspberry Pi 3 Model B was released in February 2016 with a 1.2 GHz 64-bit quad
core ARM Cortex-A53 processor, on-board 802.11n Wi-Fi, Bluetooth and USB boot
capabilities. On Pi Day 2018, the Raspberry Pi 3 Model B+ was launched with a faster
1.4 GHz processor, a three-times faster gigabit Ethernet (throughput limited to ca.
300 Mbit/s by the internal USB 2.0 connection), and 2.4 / 5 GHz dual-band 802.11ac Wi-Fi
(100 Mbit/s).
4. Raspberry Pi 4 Model B was released in June 2019 with a 1.5 GHz 64-bit quad
core ARM Cortex-A72 processor, on-board 802.11ac Wi-Fi, Bluetooth 5, full gigabit
Ethernet (throughput not limited), two USB 2.0 ports, two USB 3.0 ports, and dual-monitor
support via a pair of micro HDMI (HDMI Type D) ports for up to 4K resolution. The Pi 4 is
also powered via a USB-C port, enabling additional power to be provided to downstream
peripherals, when used with an appropriate PSU.
5. Raspberry Pi 400 was released in November 2020. It features a custom board that is
derived from the existing Raspberry Pi 4, specifically remodelled with a keyboard attached.
A robust cooling solution similar to the one found in a Commodore 64 allows the Raspberry
Pi 400's Broadcom BCM2711C0 processor to be clocked at 1.8 GHz, which is slightly higher
than the Raspberry Pi 4. The keyboard-computer features 4 GiB of LPDDR4 RAM.

6. Raspberry Pi Pico was released in January 2021 with a retail price of $4. It was
Raspberry Pi's first board based upon a single microcontroller chip; the RP2040, which was
designed by Raspberry Pi in the UK. The Pico has 264 KiB of RAM and 2 MiB of flash
memory. It is programmable in MicroPython, Circuit Python, and C.

24
2.2 THE RASPBERRY PI 3 MODEL B

The Raspberry Pi 3 Model B builds upon the features of its predecessors with a new, faster
processor on board to increase its speed. It also features WiFi and Bluetooth Low Energy
capabilities to enhance the functionality and the ability to power more powerful devices over the
USB ports.

1. Quad Core 1.2GHz Broadcom BCM2837 64bit CPU,1GB RAM


2. BCM43438 WiFi and Bluetooth Low Energy (BLE) on board
3. 40-pin Extended GPIO
4. 4x USB 2 ports
5. 4 Pole stereo output and composite video port, Full size HDMI
6. CSI camera port for connecting a Raspberry Pi camera
7. DSI display port for connecting a Raspberry Pi touchscreen display
8. Micro SD port for loading your operating system and storing data
9. Upgraded switched Micro USB power source up to 2.5A.

2.3 The IC of Raspberry Pi 3 Model B

Figure 1.4 Raspberry Pi 3 Model B

25

Figure 1.5 Raspberry Pi 3 Model B-Pin configuration

2.3.1 Raspberry Pi 3 pin names and its functionality

Table 1.3 pin category of Raspberry Pi 3 pin names and its functionality

PIN GROUP PIN NAME DESCRIPTION

POWER SOURCE +5V, +3.3V, GND and Vin +5V -power output
+3.3V -power output
GND – GROUND pin
COMMUNICATION UART Interface(RXD, UART (Universal Asynchronous Receiver
INTERFACE TXD) [(GPIO15,GPIO14)] Transmitter) used for interfacing sensors and
other devices.
SPI Interface (MOSI, MISO, CLK, CE) x 2 SPI (Serial Peripheral Interface) used for
[SPI0-(GPIO10, GPIO9, GPIO11, communicating with other boards or
GPIO8)] peripherals.
[SPI1--(GPIO20,GPIO19, GPIO21,
GPIO7)]
TWI Interface (SDA, SCL) x 2 [(GPIO2, GPIO3)] TWI (Two Wire Interface) Interface can be
[(ID_SD,ID_SC)] used to connect peripherals.
INPUT OUTPUT PINS 26 I/O Although these some pins have multiple
functions they can be considered as I/O pins.
PWM Hardware PWM available on GPIO12, These 4 channels can provide PWM (Pulse
GPIO13, GPIO18, GPIO19 Width Modulation) outputs.
*Software PWM available on all pins
EXTERNAL All I/O In the board all I/O pins can be used as
INTERRUPTS Interrupts.

26
2.3.2: Technical Specifications Raspberry Pi 3
Table 1.4: shows Technical Specifications Raspberry Pi 3
Name Description
Microprocessor Broadcom BCM2837 64bit Quad Core Processor
Processor Operating 3.3V
Voltage
Raw Voltage input 5V, 2A power source
Maximum current through 16mA
each I/O pin
Maximum total current 54mA
drawn from all I/O pins
Flash Memory (Operating 16Gbytes SSD memory card
System)
Internal RAM 1Gbytes DDR2
Clock Frequency 1.2GHz
GPU Dual Core Video Core IV® Multimedia Co-Processor. Provides
Open GLES 2.0, hardware-accelerated Open VG, and 1080p30
H.264 high- profile decode.
Capable of 1Gpixel/s, 1.5Gtexel/s or 24GFLOPs with texture
filtering and DMA infrastructure.
Ethernet 10/100 Ethernet
Wireless Connectivity BCM43143 (802.11 b/g/n Wireless LAN and Bluetooth 4.1)
Operating Temperature -40ºC to +85ºC

2.3.3: Board Connectors of Raspberry Pi 3


Table 1.5: Board Connectors of Raspberry Pi 3
Name Description
Ethernet Base T Ethernet Socket
USB 2.0 (Four sockets)
Audio Output 3.5mm Jack and HDMI
Video output HDMI
Camera 15-pin MIPI Camera Serial Interface (CSI-2)
Connector
Display Display Serial Interface (DSI) 15 way flat flex cable connector with two data
Connector lanes and a clock lane.
Memory Card Push/Pull Micro SDIO
Slot

27
2.4 HOW TO USE RASPBERRY PI 3

As mentioned earlier PI is simply a COMPUTER ON A SINGLE BOARD so it cannot


be used like ARDUINO development boards. For the PI to start working we need to first install
OPERATING SYSTEM. This feature is similar to our PC. The PI has dedicated OS for it; any
other OS will not work.We will discuss the programming of PI in step by step below.

1. Take the 16GB micro SD card and dedicate it specifically for PI OS.
2. Choose and Download OS software. [https://www.raspberrypi.org/downloads/]
(‘NOOBS’ recommended for beginners )
3. Format the SD card and install OS on to the SD memory card using convenient methods.
4. Take the SD card after OS installation and insert it in PI board.
5. Connect monitor, keyboard and mouse
6. Power the board with micro USB connector
7. Once the power is tuned ON the PI will run on the OS installed in the memory card and
will start from boot.
8. Once all drivers are checked the PI will ask for authorization, this is set by default and
can be changed.
9. After authorization you will reach desktop where all application program development
starts.

On the PI you can download application programs required for your use and can directly install
as you do for your PC. After that you can work on developing required program and get the PI
run the developed programs.

2.5 Programming Languages on RASPBERRY PI 3

Python is the recommended programming language — particularly if you are new to


programming or want to refresh your programming knowledge. Scratch is a great interactive
programming language for children who want to learn to code through creating games, stories
and animations. Other programming languages you can get on your Pi include C, C++, Java and
Ruby.

28
2.6 Application on RASPBERRY PI 3

1. Hobby projects.
2. Low cost PC/tablet/laptop
3. IoT applications
4. Media center
5. Robotics
6. Industrial/Home automation
7. Server/cloud server
8. Print server
9. Security monitoring
10. Web camera
11. Gaming
12. Wireless access point
13. Environmental sensing/monitoring (e.g. WEATHER STATION)

2.7 DETAILED DESCRIPTION OF COMPONENTS:


2.7.1 System Timer: The System Timer peripheral provides four 32-bit timer channels and a
single 64-bit free running counter. Each channel has an output compare register, which is
compared against the 32 least significant bits of the free running counter values.

2.7.2 The Processor: At the heart of the Raspberry Pi is the same processor you would have
found in the iPhone 3G and the Kindle 2, so you can think of the capabilities of the Raspberry Pi
as comparable to those powerful little devices. This chip is a 32 bit, 700 MHz System on a Chip,
which is built on the ARM11 architecture. ARM chips come in a variety of architectures with
different cores configured to provide different capabilities at different price points. The Model B
has 512MB of RAM and the Model A has 256 MB. (The first batch of Model Bs had only
256MB of RAM.).

2.7.3 Interrupt controller: The interrupt controller can be programmed to interrupt the
processor when any of the status bits are set. The GPIO peripheral has three dedicated interrupt
lines. Each GPIO bank can generate an independent interrupt. The third line generates a single
interrupt whenever any bit is set.

29
2.7.4 General Purpose Input/Output (GPIO): 3.3 volt logic via 26 pin header (NOT 5 volt or
short tolerant) Pins can be configured to be input/output. General Purpose Input/Output (GPIO)
is a generic pin on a chip whose behavior can be controlled by the user at run time. True GPIO
(General Purpose Input Output) pins that you can use to turn LEDs on and off etc. I2C interface
pins that allow you to connect hardware modules with just two control pins. SPI interface with
SPI devices, a similar concept to I2C but uses a different standard.

2.7.5 PCM / I2S Audio: The PCM audio interface is an APB peripheral providing input and
output of telephony or high quality serial audio streams. It supports many classic PCM formats
including I2S. The PCM audio interface has 4 interface signals; PCM_CLK - bit clock. PCM_FS
- frame sync signal. PCM_DIN - serial data input. PCM_DOUT - serial data output. PCM is a
serial format with a single bit data_in and out.

2.7.6 DMA Controller: The BCM2835 DMA Controller provides a total of 16 DMA channels.
Each channel operates independently from the others and is internally arbitrated onto one of the
3 system busses.

2.7.7 UART: The BCM2835 device has two UARTS. On mini UART and PL011 UART. The
PL011 UART is a Universal Asynchronous Receiver/Transmitter. This is the ARM UART
(PL011) implementation. The UART performs serial-to-parallel conversion on data characters
received from an external peripheral device or modem, and parallel-to-serial conversion on data
characters received from the Advanced Peripheral Bus (APB).

2.7.8 Pulse Width Modulator: PWM controller incorporates the following features:
1. Two independent output bit-streams, clocked at a fixed frequency.
2. Bit-streams configured individually to output either PWM or a serialized version of a 32-
bit word.
3. PWM outputs have variable input and output resolutions.
4. Serialize mode configured to load data to and/or read data from a FIFO storage block that
can store up to eight 32-bit words.
5. Both modes clocked by clk_pwm which is nominally 100MHz, but can be varied by
clock manager.

30
2.7.9 CPU
 ARM 1176JZF-S (armv6k) 700MHz
 RISC Architecture and low power draw.

2.7.10 MEMORY

 RAM:- 512MB (Model B rev.2), 256 MB (Model A, Model B rev.1)


 SD Card:- At least 4GB SD card is needed, and it should be a Class 4 card. Class 4 cards
are capable of transferring at least 4MB/sec. Some of the earlier Raspberry Pi boards had
problems with Class 6 or higher cards, which are capable of faster speeds but are less
stable. One can also use micro SD card using adapter. As there is no hard drive on the Pi;
everything is stored on an SD Card. A protective case is needed as the solder joints on the
SD socket may fail if the SD card is accidentally bent.

2.7.11 Two USB 2.0 ports in RPi: Dual USB sockets on RPi model B, single on model A.It can
be expandable via regular or powered hubs. On the Model B there are two USB 2.0 ports, but
only one on the Model A. Some of the early Raspberry Pi boards were limited in the amount of
current that they could provide. Some USB devices can draw up 500mA. The original Pi board
supported 100mA or so, but the newer revisions are up to the full USB 2.0 spec.

2.7.12 Ethernet port: The model B has a standard RJ45 Ethernet port. The Model A does not,
but can be connected to a wired network by a USB Ethernet adapter (the port on the Model B is
actually an onboard USB to Ethernet adapter). WiFi connectivity via a USB dongle is another
option.

2.7.13 HDMI connector: The HDMI port provides digital video and audio output. 14 different
video resolutions are supported, and the HDMI signal can be converted to DVI (used by many
monitors), composite (analog video signal usually carried over a yellow RCA connector), or
SCART (a European standard for connecting audio-visual equipment) with external adapters.

2.7.14 Video: HDMI or (digital) DVI via cheap adaptor/cable, Composite NTSC/PAL via RCA
,Wide range of resolutions , NO VGA without an add-on, nontrivial converter (Adafruit).

2.7.15 Audio: Via HDMI or from stereo jack , Support Maturity appears to be lagging

2.7.16 Networking : 10/100mbps via RJ45 on model B , Wireless via USB add-on supported.

31
2.7.17 Power: There is no power switch on the Pi. Micro-USB connector is used to supply
power (this isn‟t an additional USB port; it‟s only for power). Micro-USB was selected because
cheap USB power supplies are easy to find.

Primary power via microUSB plug: a 1Amp cell charger works well, but to use a USB hard
drive, 2 Amp power is needed.

2.8 CONCLUSION

Target board of such types can be used in low cost system designs using very less amount of
components and can be used for many user defined applications or customizations

2.9 REMARKS

The stiff cables microcontroller on all sides make it hard to keep flat, and some of the
components like the SD card slot can be mechanically damaged even through normal use. The Pi
contains six layers of conductive traces connecting various components, unlike a lot of simple
microcontroller PCBs that just have traces on the top and the bottom. There are four layers of
thin traces sandwiched in between the top and bottom; if the board gets flexed too much you can
break some of those traces in a manner that is impossible to debug

32
Experiment 2
AIM:
Study of the sensor (IR, temperature, pressure, gas) and the actuator (Piezoelectric actuator,
Pneumatic actuator) using Arduino and understanding their connectivity with the Arduino Uno
board.

2.1 APPARATUS:

 IR transmitter & receiver

 LM 35 temperature sensor

 BMP 280-Atmospheric Pressure Sensor

 Gas sensor MQ 135

 Piezoelectric actuator

 Pneumatic actuator.

2.2 THEORY:

Sensors: An electronic sensor detects and measures a physical phenomenon, such as


temperature, pressure, force, acceleration and provides corresponding output which is in the form
of electrical signals.

2.2.1 IR sensor:

1. An infrared sensor is an electronic instrument which is used to sense certain


characteristics of its surroundings by their emitting and/or detecting infrared radiation.

2. Infrared sensors are also capable of measuring the heat being emitted by an object as well
as detecting the motion.

3. Infrared waves are not visible to the human eye. In the electromagnetic spectrum,
infrared radiation can be found between the visible and microwave regions.
4. The infrared waves typically have wavelengths between 0.75 and 1000 µm.

33
Figure 2.1 IR sensor structure

Figure 2.2 IR sensor functionality

2.2.2 LM 35 Temperature sensor:


1. The LM 35 temperature sensor is a little module that can provide the digital
temperature. It is really easy to set up as one wire is sufficient to control the data
signal.
2. The sensor is frequently used in remote weather stations, home environment control
systems and the controlling the signal can be easily programmable.

34
Figure 2.3 Temperature Sensor

2.2.3 BMP 280-Atmospheric Pressure Sensor:


1. BMP 280 pressure sensor module is an Arduino compatible tool which is used for
atmospheric pressure measurement in environments. Such measurements mainly allow
for forecasting of short term changes in the weather.
2. The GY-BMP 280 module comes with BMP 280 sensor, which is an environmental
sensor with barometric pressure that is the next generation upgrade to the
BMP085/BMP180/BMP183.
3. The sensor is great for all sorts of weather sensing and can even be used in both type of
serial communication such as 12C and SPI.
4. The sensor is economic, precision sensing solution for measuring barometric pressure
with ± 1hPa absolute accuracy, and temperature with ± 1.0°C accuracy. Pressure changes
with altitude and its measurement can take place with the altimeter with ± 1-meter
accuracy.
5. The sensor has pin pitch with 2.54 mm.

Table 2.1 Pin description


Pin No. Pin Name Pin description
1. VCC Power source of 3.3 VDC
2. GND Ground
3. SCL Serial clock
4. SDA Serial Data

35
Figure 2.4 BMP 280 Pressure sensor

Figure 2.5 Interfacing circuit between Arduino and BMP 280 Pressure sensor

Applications:
 Enhancement of GPS navigation capability
 Indoor navigation such as floor detection, elevator detection can possible
 Outdoor navigation such as leisure and sports application takes place
 Weather forecast as well as home weather stations
 Heath care application such as Sirometry

36
 Vertical velocity indication such as risk/sink speed
 Handsets such as mobile phones, tablets PCs, GPS devices
 Flying toys
 Watches

2.2.4 Gas sensor MQ 135:


1. MQ-135 gas sensor applies mostly on SnO2 gas which has a lower conductivity in the
clean air as a gas-sensing material.

2. In an atmosphere, there may be polluting gas as well as the conductivity of the gas sensor
raises along with the concentration of the polluting gas increases.

3. MQ-135 performs a good detection in smoke and other harmful gases, especially
sensitive to ammonia, sulfide and benzene steam.

4. It has an ability to detect various harmful gases and MQ-135 is an ideal choice of
different applications of harmful gas detection in a minimal cost.

5. The MQ-135 sensor module comes with a digital pin (fig. 2.6) which makes the sensor to
operate even without a microcontroller. As a result, it is very suitable to detect one
particular gas.

6. The analog pins are required to measure the gases in PPM. The analog pins are basically
TTL driven sensor. It works on + 5 V power supply and as an advantages, it can be used
with most common microcontrollers.

7. The module is powered with 5V and it is important to notice the status of the LED power
module as the LED power will remain turned off meaning the digital output pin will be 0
V as well as gas will not detect.

8. The sensors have to be kept on for pre-heating time before we can actually work with it.

9. Every time, when the sensor gets introduced to this gas at this particular concentration the
digital pin will go high (5 V) else will remain low (0V).

37
Figure 2.6 Gas sensor MQ 135

Applications:

The module can be applied to detect harmful gases to control pollution in metropolitan cities.

Actuators:

Actuators convert an electrical signal to the corresponding physical quantity such as movement,
force, sound, display etc. The actuator is a part of any machine which is responsible for
mechanical or controlling. Example: Microphone (coverts sound to electrical signal), Speaker
(converts rotation electrical signal to sound), antenna (converts electromagnetic energy into
electricity and vice versa). The actuators which induce the movement that can be classified based
on their operation, is categorized into three ways, namely electric, hydraulic and pneumatic
actuators.

Hydraulic actuators facilitate mechanical movement with the application of hydraulic


power. Pneumatic actuators use compressed air pressure and electrical actuators use electric
power. A sophisticated example of an actuator that used in the IoT is “digital fingers”. It is used
to switch on/off the switches (or anything that requires a small movement) and can be controlled
wirelessly.

38
2.2.5 Piezoelectric actuators:
Piezoelectric actuators are devices that can produce a small displacement with a high force
capability when voltage is applied. There are many applications where a piezoelectric actuator
may be used, such as ultra-precise positioning and in the generation and handling of high forces
or pressures in static or dynamic situations. Actuator configuration can vary frequently which is
basically depending on application areas. Piezoelectric stack or multilayer actuators are
manufactured by stacking up piezoelectric disks or plates. The axis of the stack being the axis of
linear motion that occurs when a voltage is applied. Tube actuators are monolithic devices that
contract laterally and longitudinally when a voltage is applied between the inner and outer
electrodes.

A disk actuator is a device in the shape of a planar disk. Ring actuators are also disk
actuators with a center bore which make the actuator axis accessible for optical, mechanical, or
electrical purposes. Other less common configurations include block, disk, bender and bimorph
styles. These devices can also be ultrasonic. Ultrasonic actuators are specifically designed to
produce strokes of several micrometers at ultrasonic (>20 kHz) frequencies. They are especially
useful for controlling vibration, positioning applications, and quick switching. In addition,
piezoelectric actuators can be either direct or amplified. The effect of amplification is not only
larger displacement, but it can also result in slower response times. The critical specifications for
piezoelectric actuators are displacement, force and operating voltage of the actuator. Other
factors are there to consider such as stiffness, resonant frequency, and capacitance. Stiffness is a
term which is used to describe the force required to achieve a certain deformation of a structure.
For piezoelectric actuators, it is the force needed to elongate the device by a certain amount
which is normally specified in terms of Newton per micrometer. Resonance is the frequency at
which the actuators respond with maximum output amplitude. The capacitance is a function of
the excitation voltage frequency.

39
Figure 2.7 Interfacing between Piezoelectric actuators and Arduino

2.2.6 Pneumatic actuators:

A pneumatic actuator uses energy that is formed by vacuum or compressed air at high pressure to
convert into either linear or rotary motion. Pneumatic actuators are notable in their applications
such as the opening and closing of valves takes place. For the reason, they hold value within
applications fields where fire or ignition risk possibility takes place. Pneumatic actuators are also
known in the industry by several different monitors including: pneumatic cylinders, air cylinders
and air actuators.

Pneumatic rack and pinion actuators are used for valve controls of water pipes.
Pneumatic energy quickly responds for starting and stopping signals. The power source does not
need to be stored in reverse for operation. Pneumatic actuators enable for large forces to be
produced from relatively small pressure changes (i.e., Pneumatic brakes are very responsive to
small changes in pressure applied by the driver). It is responsible for converting pressure into
forces.

As an example, it is used in robotics in the form of sensors that work like human fingers
by using compressed air. Some advantages take place in pneumatic actuators such as cost
efficient and are applied at extreme temperatures such as the place where air is the safer option

40
than chemicals other than that, low maintenance, highly durable, have a long operational life, and
it has a very quick starting and stopping motion.

Figure 2.8 Interfacing between Pneumatic actuators and Arduino

CONCLUSIONS
We have accessed the data from sensors and actuators and also have applied on Arduino Uno
board. Further, data is collected, analyzed and visualized of the IR, temperature, pressure, gas
sensors as well as piezoelectric and pneumatic actuators.

41
EXPERIMENT 3

AIM:

Installation of Arduino in computer and verifying any errors in connection.

3.1.1 APPARATUS:
 Arduino UNO
 PC
 Proteus Software IDE
 Connecting wires
 LEDs

3.1.2 THEORY:
To install and test the Arduino software with a Windows operating system (Windows 8,
Windows 7, Vista, and XP).

Step 1 − First you must have your Arduino board (you can choose your favorite board) and a
USB cable. In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560,
or Diecimila, you will need a standard USB cable (A plug to B plug), the kind you would
connect to a USB printer as shown in the following image.

Figure 3.1 USB Cable

In case you use Arduino Nano, you will need an A to Mini-B cable instead as shown in the Fig.
3.1.

42
Step 2 − Download Arduino IDE Software.

You can get different versions of Arduino IDE from the Download page on the Arduino Official
website. You must select your software, which is compatible with your operating system
(Windows, IOS, or Linux). After your file download is complete, unzip the file. See Fig. 3.2.

Figure 3.2

Step 3 − Power up your board.

The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power from
either, the USB connection to the computer or an external power supply. If you are using an
Arduino Diecimila, you have to make sure that the board is configured to draw power from the
USB connection. The power source is selected with a jumper, a small piece of plastic that fits
onto two of the three pins between the USB and power jacks. Check that it is on the two pins
closest to the USB port. Connect the Arduino board to your computer using the USB cable. The
green power LED (labeled PWR) should glow.

Step 4 − Launch Arduino IDE.

After your Arduino IDE software is downloaded, you need to unzip the folder. Inside the folder,
you can find the application icon with an infinity label (application.exe). Double-click the icon
to start the IDE. Refer Fig. 3.3.

43
Figure 3.3

Step 5 − Open your first project.


Once the software starts, you have two options −

 Create a new project.


 Open an existing project example.
To create a new project, select File → New as described in Fig. 3.4.

Figure 3.4

To open an existing project example, select File → Example → Basics → Blink. See Fig 3.5.

44
Figure 3.5

Here, we are selecting just one of the examples with the name Blink. It turns the LED on and
off with some time delay. You can select any other example from the list.

Step 6 − Select your Arduino board.

To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer.

Go to Tools → Board and select your board as shown in Fig. 3.6.

Figure 3.6
45
Here, we have selected Arduino Uno board according to our tutorial, but you must select the
name matching the board that you are using.

Step 7 − Select your serial port.

Select the serial device of the Arduino board. Go to Tools → Serial Port menu shown in Fig.
3.7. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware
serial ports). To find out, you can disconnect your Arduino board and re-open the menu, the
entry that disappears should be of the Arduino board. Reconnect the board and select that serial
port.

Figure 3.7

Step 8 − Upload the program to your board.


Before explaining how we can upload our program to the board, we must demonstrate the
function of each symbol appearing in the Arduino IDE toolbar as shown in Fig. 3.8.

46
Figure 3.8

A − Used to check if there is any compilation error.

B − Used to upload a program to the Arduino board.

C − Shortcut used to create a new sketch.

D − Used to directly open one of the example sketch.

E − Used to save your sketch.

F − Serial monitor used to receive serial data from the board and send the serial data to the
board.

Now, simply click the "Upload" button in the environment. Wait a few seconds; you will see the
RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done
uploading" will appear in the status bar.

RESULTS
Arduino is successfully installed in computer and any errors in connection are verified.

47
EXPERIMENT 4
AIM - Programming with Arduino platform and Reading data from Temperature Sensors.

4.1. Apparatus: Arduino, LM35 sensor, Breadboard, Connecting wires

4.2. Theory
The Temperature Sensor LM35 series are precision integrated-circuit temperature devices with
an output voltage linearly proportional to the Centigrade temperature. The LM35 device has an
advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to
subtract a large constant voltage from the output to obtain convenient Centigrade scaling. The
LM35 device does not require any external calibration or trimming to provide typical accuracies
of ±¼°C at room temperature and ±¾°C over a full −55°C to 150°C temperature range.

4.3 Hardware Integration (Circuit Diagram)

Figure 4.1
LM35 sensor has three terminals - Vs, Vout and GND. We will connect the sensor as follows

 Connect the +Vs to +5v on your Arduino board.

 Connect Vout to Analog0 or A0 on Arduino board.

Connect GND with GND on Arduino.

48
The Analog to Digital Converter (ADC) converts analog values into a digital approximation
based on the formula ADC Value = sample * 1024 / reference voltage (+5v).

Open the Arduino IDE software on your computer. Coding in the Arduino language will control
your circuit. Open a new sketch File by clicking New

Figure 4.2
4.4. Coding

float temp;
int tempPin = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
temp = analogRead(tempPin);
// read analog volt from sensor and save to variable temp
temp = temp * 0.48828125;
// convert the analog volt to its temperature equivalent
Serial.print("TEMPERATURE = ");
Serial.print(temp); // display temperature value
Serial.print("*C");
Serial.println();

49
delay (1000); // update sensor reading each one second
}

5. Conclusion:

In this experiment LM 35 temperature sensor is used to measure and identify for temperature
variation and temperature will display on the serial port monitor which is updated every second.

50
EXPERIMENT 5

AIM: To display the date on serial monitor using Raspberry Pi

5.1 APPARATUS: Raspberry Pi, USB Connector, LAN connector, Memory Card (SD Card)

5.2 THEORY:
The Raspberry Pi does not have a similar feature to the Arduino's Serial Monitor present
in integrated development environment (IDE). We can communicate with an Arduino over both
the GPIO serial and USB serial and use the Serial monitor. However, by using a LAN
connection, the data can be viewed on any other display device.
A date in Python is not a data type of its own, but we can import a module named
datetime to work with dates as date objects.

datetime.datetime.now()

The date contains year, month, day, hour, minute, second, and microsecond. The datetime
module has many methods to return information about the date object. For instance, the
strftime() function formats a local time and/or date according to locale settings.
datetime.datetime.now().strftime('%m-%d-%Y_%H.%M.%S').

5.3 PROGRAM:
from datetime import *
import time
from time import time
today = datetime.now()
print (today.strftime(' %a %d-%m-%Y @ %H:%M:%S'))

51
EXPERIMENT 5B

AIM: To create an automatic door opening system using Raspberry Pi

5.1 APPARATUS: Raspberry Pi, PIR Motion sensor, LED, Resistors, Breadboard, Jumper wire

5.2 THEORY:
The PIR sensor acts as a motion detector and detects the presence of human beings within
the field of its vision. When it detects the human presence, it notifies the Raspberry Pi controller.
The DC motor connected to the output of the Raspberry Pi controller is used to open and close
the gate automatically. In this experiment, LED light is used to indicate the presence of intruder.
The actuator can be incorporated by using a DC motor and a motor driver module.

5.2.1 Raspberry Pi:


The Raspberry Pi GPIO can be accessed through a Python program. Each pin on the Raspberry
Pi is named based on its order (1,2,3, ...) as shown in the diagram below:

Figure 5.1: Raspberry Pi GPIO pins

5.2.2 PIR motion sensor:


PIR stands for passive infrared. This motion sensor consists of a Fresnel lens, an infrared
detector, and supporting detection circuitry. The lens on the sensor focuses any infrared radiation

52
present around it toward the infrared detector. Our bodies generate infrared heat, and as a result,
this heat is picked up by the motion sensor. The sensor outputs a 5V signal for a period of one
minute as soon as it detects the presence of a person. It offers a tentative range of detection of
about 6–7 meters and is highly sensitive. When the PIR motion sensor detects a person, it outputs
a 5V signal to the Raspberry Pi through its GPIO and we define what the Raspberry Pi should do
as it detects an intruder through the Python coding. Here we are just printing "Intruder detected".

Figure 5.2 PIR motion sensor pin diagram

5.3 PROCEDURE:

5.3.1 Blinking an LED Using the Raspberry Pi GPIO-Output GPIO Control:

In this experiment, the LED is used as an indicator of the presence of any intruder using a
Python script. Copy and paste the following code into the Raspberry Pi. This can be done by
opening the text editor "leafpad" on the Raspberry Pi and copying this code into it, and saving
this as a Python file: ledblink.py:

 Open the text editor "leafpad" on Raspberry Pi


 Type the program
 Save as a Python file: ledblink.py
 Execute the Python program using this command: sudo python ledblink.py

5.4.1 PROGRAM:
import RPi.GPIO as GPIO
import time

53
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3,GPIO.OUT) #Define pin 3 as an output pin
while True:
GPIO.output(3,1) #Outputs digital HIGH signal (5V) on pin 3
time.sleep(1) #Time delay of 1 second
GPIO.output(3,0) #Outputs digital LOW signal (0V) on pin 3
time.sleep(1) #Time delay of 1 second

Connect the LED to pin 3 on the Raspberry Pi GPIO. The LED blinks because it receives a
HIGH (5V) signal and a LOW (0V) signal from the Raspberry Pi GPIO at a delay of one
second.

5.4.2 Interfacing the PIR Motion Sensor to the Raspberry Pi's Input GPIO:

The sensor outputs a digital HIGH (5V) signal when it detects a person. Type the program and
save as a Python file: pirtest.py

5.4.2.1 PROGRAM:
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN) #Read output from PIR motion sensor
GPIO.setup(3, GPIO.OUT) #LED output pin
while True:
i=GPIO.input(11)
if i==0: #When output from motion sensor is LOW
print "No intruders",i
GPIO.output(3, 0) #Turn OFF LED
time.sleep(0.1)
elif i==1: #When output from motion sensor is HIGH

54
print "Intruder detected",i
GPIO.output(3, 1) #Turn ON LED
time.sleep(0.1)

Connect the Raspberry Pi GPIO to the PIR motion sensor and run the code.

It can be noted that this code prints "Intruder detected" when the hand is placed over the sensor.
After removing the hand and waiting some time, it prints: "No intruders".

CONCLUSION

The experiment on door opening system using Raspberry Pi is successfully performed, where
PIR motion sensor is used to detect the intruder and an LED is used as actuator of the system.

55
EXPERIMENT 6
AIM: Connecting android phone with Arduino

(a) Connecting Arduino with Mobile device using the Bluetooth module.
(b) Control any two actuators connected to the development board using Bluetooth.

6.1 APPARATUS:

Arduino, HC-05 module, 5V relay module, 12 V DC Adopter, USB A to B for programming


the Arduino, Mobile phone, LED, Servo motor and Relay.

6.2 THEORY:

Arduino is an open-source electronics platform based on easy-to-use hardware and


software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a
Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online. You can tell your board what to do by sending a set of
instructions. The Arduino programming language and Arduino Software (IDE) are also part of
experiment.

Bluetooth is a wireless technology standard used for exchanging data between fixed
and mobile devices over short distances using short-wavelength UHF radio waves in
the industrial, scientific and medical radio bands, from 2.402 GHz to 2.480 GHz, and
building personal area networks (PANs). It was originally conceived as a wireless alternative
to RS-232 data cables.

6.2.1 HC-05 module Information


HC-05 has red LED which indicates connection status, whether the Bluetooth is
connected or not. Before connecting to HC-05 module this red LED blinks continuously in a
periodic manner. When it gets connected to any other Bluetooth device, its blinking slows
down to two seconds.
This module works on 3.3 V. We can connect 5V supply voltage as well since the
module has on board 5 to 3.3 V regulator as shown in figure 8.1.

56
As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect
3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the
transmit voltage level from microcontroller to RX of HC-05 module.

6.2.2 Servo meter


A servo motor is a rotary actuator or motor that allows for a precise control in terms of
angular position, acceleration and velocity, capabilities that a regular motor does not have. It
makes use of a regular motor and pairs it with a sensor for position feedback. The controller is
the most sophisticated part of the servo motor, as it is specifically designed for this purpose.

The servo motor is a closed-loop servomechanism that uses position feedback in order
to control its rotational speed and position. The control signal is the input, either analog or
digital, which represents the final position command for the shaft.

Figure 6.1 HC-05 Blue tooth module

Figure 6.2 Basic connection of Arduino with Bluetooth HC-05

57
6.3 PROCEDURE:

6.3.1 LED blink

1. To use the HC05 module, simply connect the VCC to the 5V output on the Arduino,
GND to Ground, RX to TX pin of the Arduino, and vice versa.
2. This is done because the RX pin on the Arduino is Pin 0 and the TX pin is Pin 1. In place
of pin 0 and Pin 1, any other pin can be used but it should be mentioned in the coding
section of Arduino.
3. LED is connected between the ground and any one pin as mentioned in coding section.
4. Download the Arduino Bluetooth controller in mobile and connect with HC-05 then you
can use digital ON-OFF option to control the LED. System connection is shown in figure
8.2.
5. In Proteus software with the help of virtual serial port driver, virtual Bluetooth can be
connected to system Bluetooth and further system Bluetooth is connected to the mobile
Bluetooth. if mobile phone is not using in experiment so we need on more Bluetooth in
proteus software setup as mobile phone and with virtual serial port driver connection can
be formed. Setup of proteus software shown in figure 8.3.
Note: Same steps we can follow in proteus software where virtual Bluetooth is used HC-05 and
with port selection of system or laptop mobile Bluetooth can be connected with system blue
tooth.

Code

char data = 0; //Variable for storing received data


void setup()
{
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data
transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:

58
{
data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n"); //New line
if(data == '1') //Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
else if(data == '0') //Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
}
}

code for proteus software


void setup () {
peripheral_setup();
// TODO: put your setup code here, to run once:
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop() {
peripheral_loop();
// TODO: put your main code here, to run repeatedly:
while (Serial.available())
{
char x=Serial.read();
//check==
//Serial.print(x);
if(x=='O')
{digitalWrite(4, HIGH); //Turn On
Serial.print("ON");}
if(x=='F')

59
{digitalWrite(4, LOW); //Turn Off
Serial.print("OFF");} } }

Figure 6.3 Setup of Proteus software for LED blink using Bluetooth

6.3.2 Servo motor using Bluetooth code


1. The android app sends data packets to the Bluetooth module. The Bluetooth modules
sends this data packet to Arduino Uno through Serial Communication.
2. Arduino Uno is programmed to generate control signal for the servo motor
depending upon the value of the data packet. The circuits and connection is
connected as shown in figure 8.4

Figure 6.4 Bluetooth based servo meter connection

60
Code
#include <Servo.h>
#include<SoftwareSerial.h>
#include<Servo.h>
Servo x;
intbttx=9; //tx of bluetooth module is connected to pin 9 of arduino
intbtrx=10; //rx of bluetooth module is connected to pin 10 of Arduino
Software Serialbluetooth (bttx,btrx);
void setup()
{
x.attach(11); // servo is connected to pin 11 of Arduino
Serial.begin(9600);
bluetooth.begin(9600);
}
void loop()
{
if(bluetooth.available()>0) //if Bluetooth module is transmitting data
{
intpos=bluetooth.read(); // store the data in pos variable
Serial.println(pos);
x.write(pos); //move servo head to the given position
}
}

6.3.3 Bluetooth based relay control


1. Since this project is based on serial communication, no sensors have been used here
thereby keeping the production cost low. The Bluetooth HC-05 module used here

61
communicate with both Arduino through wired connection and the smartphone
wirelessly.

Figure 6.5 Bluetooth based relay system

3. The smartphone provides the input to the Bluetooth module and the module in turn
provides an input to the Arduino. Thus it can be said the Bluetooth acts as a mediator
between the Arduino and the smartphone. The circuits and connection is connected
as shown in figure.6.5.
2. The relay works as the actuator here and is connected to a socket such that it can ON
and OFF any device which is connected to the socket making it very robust.
3. Smartphone app that can control HC-05 Bluetooth module such as ‘Bluetooth
Terminal HC-05’.
Code
int relay = 12;//variable for assigning the relay module
int state = 0;//variable for assigning the value communicated by Bluetooth module
int flag = 0; //variable for assigning flag to for a desirable operation
void setup()
{
pinMode(relay, OUTPUT);//setting relay as output
digitalWrite(relay, LOW);// initializing the output as off
Serial.begin(9600); // default connection rate for the BT module

62
}
void loop()
{
if (Serial.available() > 0) //checking if connection available with bluetooth module
{
state = Serial.read();//assigning the value communicated by Bluetooth module
flag = 0;//initial value set for flag
}
if (state == '0') // LOW value communicated by Bluetooth module
{
digitalWrite(relay , LOW);//relay is switched OFF
if (flag == 0) //initial flag
{
Serial.println("POWER: Off");//display on the smartphone app
flag = 1;//flag toggled
}
}
else if (state == '1') //HIGH value communicated by Bluetooth module
{
digitalWrite(relay, HIGH);// relay is turned ON
if (flag == 0)//initial flag
{
Serial.println("POWER: On");//display on the smartphone app
flag = 1;//flag toggled
}}}

RESULT:
Outputs are observed in case of LED, servo motor and relay, as mention in aim of this
experiments.
63
EXPERIMENT 7
AIM:
Client and server communication with socket connection.

7.1 Apparatus requirement


Windows OS (32/64 Bit), Python 3 (x32/x64 Bit) or PyCharm 2021.1.2 (x32/x64 Bit).

7.2 Theory
7.2.1 Python: Network Programming
Python provides two levels of access to network services. At a low level, you can access the
basic socket support in the underlying operating system, which allows you to implement clients
and servers for both connection-oriented and connectionless protocols. Python also has libraries
that provide higher-level access to specific application-level network protocols, such as FTP,
HTTP, and so on. This experiment explains the client and server communication with socket
connection in networking.

7.2.2 What are Sockets?


Sockets are the endpoints of a bidirectional communications channel. Sockets may communicate
within a process, between processes on the same machine, or between processes on different
continents. Sockets may be implemented over a number of different channel types: Unix domain
sockets, TCP, UDP, and so on. The socket library provides specific classes for handling the
common transports as well as a generic interface for handling the rest.

7.2.3 Socket Programming - Terms


7.2.3.1 Domain
Domain is the family of protocols that is used as the transport mechanism. These values are
constants such as AF_INET, PF_INET, PF_UNIX, PF_X25, and so on.
7.2.3.2 Type
The type of communications between the two endpoints, typically SOCK_STREAM for
connection-oriented protocols and SOCK_DGRAM for connectionless protocols.
7.2.3.3 Protocol: Typically zero value, this may be used to identify a variant of a protocol within
a domain and type.

64
7.2.3.4 Hostname: Hostname is the identifier of a network interface. A hostname might be a
string, a dotted-quad address, or an IPV6 address in colon (and possibly dot) notation.
Port: Each server listens for clients calling on one or more ports. A port may be a Fixnum port
number, a string containing a port number, or the name of a service.

7.2.4 Socket Module for Socket Programming


To create a socket, use the socket.socket() function available in socket module, which has the
general syntax
s = socket.socket (socket_family, socket_type, protocol=0)
The description of the above syntax parameters are
 socket_family: This is either AF_UNIX or AF_INET, as explained earlier.
 socket_type: This is either SOCK_STREAM or SOCK_DGRAM.
 protocol: This is usually left out, defaulting to 0.
After the socket object creation, we can define the client and server functions to create socket
communication. The list of functions/methods to describe the client and server socket connection
as:
7.2.4.1 Server side
 s.bind() This method binds address (hostname, port number pair) to socket.
 s.listen() This method sets up and start TCP listener.
 s.accept() This passively accept TCP client connection, waiting until connection arrives
(blocking).
 clt.send()This send the data in bytes.
 while loop: This allows accepting connections forever.
 clt: This represents client object.
 adr: This represents address.
 print(): The print statement just prints out the address and the port number of the client
socket.
7.2.4.2 Client side
 s.connect() This method actively initiates TCP server connection.
 s.recv() This method receives TCP message.
 s.send() This method transmits TCP message.

65
 s.recvfrom() This method receives UDP message.
 s.sendto() This method transmits UDP message.
 s.close() This method closes socket.
 socket.gethostname() Returns the hostname.

7.3 Program
7.3.1 Programming in "PyCharm"
The "PyCharm" Home page is shown in Figure 7.1. To write a Python program file in
"PyCharm", click on the "File" tab and select "New" (Alt+Insert) and select python file. Now,
"New Python File" popup window will be opened immediately. Then, type "server1" to create
"server1.py" python program file, and "client1" to create "client1.py" python program file. Now,
"server1.py" and "client1.py", two separate files are ready two write the client and server socket
program in "PyCharm". Use "Save All" in "File" menu (Ctrl+S) to save the program file. The
client and server socket programs are shown in Figure 7.1 and Figure 7.2.

Figure 7.1 Home Page of the PyCharm

7.3.2 Server-side Program

"Socket Program for the Server"

import socket
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 40024))
s.listen(5)
while True:
clt, adr=s.accept()
print(f"Connection to {adr} established")
clt.send(bytes("Socket Programming in Python is running", "utf-8"))

66
Figure 7.2 Socket program for the server
7.3.3 Client-side Program

"Socket Program for the Client"

import socket
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((socket.gethostname(), 40024))
msg=s.recv(1024)
print(msg.decode("utf-8"))

Figure 7.3 Socket program for the client


7.3.4 Run the client and server socket program in Python
The written client and server socket communication python program can be executed in "cmd"
window.
To execute the Python program in "PyCharm" do the following procedures:
 Click on the "Open Files" Tab in "pythonProject" window.
 Copy that client and server program files located path (for example :
C:\Users\user\PycharmProjects\pythonProject).
 Press "Windows+E" key to open windows explorer.
 Paste that already copied path (C:\Users\user\PycharmProjects\pythonProject) in
windows explorer folder path, which is copied from "pythonProject".
 Click the cursor windows explorer folder path and type "cmd" to open the command
window to execute the client and server program.
 Type the syntax "py <FileName>.py" on command window, and press enter to execute
the client and server program simultaneously.

7.4 Output

While executing the client and server program in command window, the client and server
program will bind and connect with each other. Therefore, the socket connection will be
established between them. Corresponding local IP address with port number will be displayed in
server side command window.

67
7.4.1 Server-side output

Figure 7.4 Output window of the socket Program for the server
7.4.2 Client-side output

Figure 7.5 Output window of the socket program for the server
7.5 Conclusion
The client and server socket connection is established. The local IP address and port number of
that machine is noted.

68
EXPERIMENT 8

AIM a) Create a mobile app to control an actuator.

b) Control Electronic Devices from anywhere across the world using Internet & Mobile App.

8.1 APPARATUS/TOOLS Firebase, Android Studio, Python and Proteus software.

8.2 THEORY

Firebase evolved from Envolve, a prior start up founded by James Tamplin and Andrew Lee in
2011. Envolve provided developers an API that enables the integration of online chat
functionality into their websites. After releasing the chat service, Tamplin and Lee found that it
was being used to pass application data that were not chat messages. Developers were using
Envolve to sync application data such as game state in real time across their users.

Android Studio is the official integrated development environment (IDE) for Google's
Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically
for Android development.

The Proteus Design Suite is a proprietary software tool suite used primarily for electronic
design automation. The software is used mainly by electronic design engineers and technicians to
create schematics and electronic prints for manufacturing printed circuit boards.

8.3 IMPLEMENTATION STEPS

The implementation phase has been divided into three stages i) Development of App, ii)
Integrate App with Proteus and iii) Develop circuit and control actuators in Proteus

8.3.1 Phase-1 Development of App

Step 1 Open android studio and create new project

Step 2 Create Firebase account

69
Step 3 Create a project on Firebase (give the same name as your app name for example ‘xyzt’ as
shown in Figure 8.1)

Step 4 After sync/connect your firebase account with android app that you are going to develop

4. a) Select android app

Figure 8.1 Created Project in Firebase with name xyzt.

4. b) Fill following information’s (collect from android project from that you have been created
‘xyzt’ as shown in Figure 8.2) and registered your app

Figure 8.2 Required information’s to register app.

Step 5 Create a Firebase real-time database and fill following information’s as shown in Figure 8.3.

70
Figure 8.3

Step 6 Connect Firebase database with anroid studio – for that you have to add the dependacies at project
level and app level gradle. After sync your app with firebase.

Step 7 Add the libraries as per your project requirements, in this project we will add two libraries are
Analytics and Storage

Step 8 Next, we have to creates two buttons in android studio to control the device.

8. a) For that open activity_main.xml file and use this code to create button (or you can use drag
and drop method to create button)

<Button
android:id="@+id/sendOFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.817"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.139" />

71
Step 9 Open MainActivity.java file and references the buttons that you have been created and
update the database by using onClick method.

Step 10 Build the App and install in your mobile phone.

8.3.2 Phase-2 Interfacing Proteus with Firebase


To interface firebase with available platform, we will use python libraries, our objective is make
available firebase data on virtual com port of system.

8.3.3 Phase-3 Create a project to control actuator in Proteus


In project we will control a dc motor by making use Arduino UNO board as shown in Figure 8.4.

Figure 8.4 Control dc motor through Arduino UNO.


8.4 CODING

char x_p=0,cnt=1;
void setup () {
peripheral_setup();
// TODO: put your setup code here, to run once:
Serial.begin(9600);

72
pinMode(4,OUTPUT);
}

void loop() {
peripheral_loop();
// TODO: put your main code here, to run repeatedly:
if(Serial.available())
{ char x=Serial.read();
if(x==’1’)
{digitalWrite(4,HIGH);}
else if(x==’0’)
{digitalWrite(4,LOW);} } }

8.5 RESULT AND DISCUSSION


We have been successfully created a mobile App and interfaced it with Proteus software to
control the dc motor.

73
EXPERIMENT 9 & 10
AIM:
AIM- Interfacing Cloud (Experiment-9)
a) Push sensor data to cloud - Use Arduino to upload data from Environmental Sensors to Cloud
Server.
b) Control an actuator through cloud (Refer Experiment -8)

AIM-Data analysis and Visualization (Experiment-10)


Access the data pushed from sensor to cloud and apply any data analytics or visualization
services.

9.1 APPARATUS:
Arduino, NodeMCU, DHT sensor, API key from ThingSpeak, Mobile Wi-Fi, Account on the
website https://thingspeak.com/

9.2 THEORY:
Cloud is the on-demand availability of computer system resources, especially data storage (cloud
storage) and computing power, without direct active management by the user. The term is
generally used to describe data centers available to many users over the Internet. Large clouds,
predominant today, often have functions distributed over multiple locations from central servers.
If the connection to the user is relatively close, it may be designated an edge server. Clouds may
be limited to a single organization (enterprise clouds), or be available to multiple organizations
(public cloud).
Advocates of public and hybrid clouds note that cloud allows companies to avoid or
minimize up-front IT infrastructure costs. Proponents also claim that cloud allows enterprises to
get their applications up and running faster, with improved manageability and less maintenance,
and that it enables IT teams to more rapidly adjust resources to meet fluctuating and
unpredictable demand, providing the burst computing capability: high computing power at
certain periods of peak demand.
The main enabling technology for cloud is virtualization. Virtualization separates a physical
computing device into one or more “virtual” devices, each of which can be easily used and

74
managed to perform computing tasks. With operating system–level virtualization essentially
creating a scalable system of multiple independent computing devices, idle computing resources
can be allocated and used more efficiently. Virtualization provides the agility required to speed
up IT operations and reduces cost by increasing infrastructure utilization. Autonomic computing
automates the process through which the user can provision resources on-demand. By
minimizing user involvement, automation speeds up the process, reduces labor costs and reduces
the possibility of human errors. Cloud computing uses concepts from utility computing to
provide metrics for the services used. Cloud attempts to address quality of service (QoS) and
reliability problems of other grid computing models.
Data analysis is a process of inspecting, cleansing, transforming, and modeling data with
the goal of discovering useful information, informing conclusions, and supporting decision-
making. Data analysis has multiple facets and approaches, encompassing diverse techniques
under a variety of names, and is used in different business, science, and social science domains.

Figure 9.1

9.3 HARDWARE AND WEBSITE:


Schematic diagram of the hardware is shown in figure 9.2. Figure 9.3 shows the interface of the
ThingSpeak Website.

Figure 9.2

75
Figure 9.3

9.4 PROCESS TO GET API KEY FROM IOT WEBSITE:

1. Go to the website https://thingspeak.com/ . Open account Using your existing


MathWork (MatLab) account or create a new one.
2. Then Go the My Channels as shown in below figure 9.4.

9
.
4

Figure 9.4

3. Create a new channel by clicking on the new channel button as shown in figure 9.5

Figure 9.5

76
4. In the next Page fill all the details (Figure 9.6), Where Field 1 is for sensor one and so on.

Figure 9.6

5. Save the created channel and go to API keys tab as shown in figure 9.7. Note Down the
API Key and the cannel id to used further.

Figure 9.7

77
9.5 HARDWARE CONNECTION AND CODING

Connect the NodeMCU with the system via usb cable and open the Arduino software (Refer
Figure 9.13). Use the given code and do the required modification

// Simple code upload the temperature and humidity data using thingspeak.com
// Hardware: NodeMCU,DHT11

#include <DHT.h> // Including library for dht

#include <ESP8266WiFi.h>

String apiKey = "T60RNPZ6RLGT2JX5"; // Enter your Write API key from ThingSpeak

const char *ssid = "MITECE"; // replace with your wifi ssid and wpa2 key
const char *pass = "password123"; // replace with your wifi password of your device
const char* server = "api.thingspeak.com";

#define DHTPIN 0 //pin where the dht11 is connected

DHT dht(DHTPIN, DHT11);

WiFiClient client;
void setup()
{
pinMode(relay, OUTPUT);
Serial.begin(115200);
delay(10);
dht.begin();

Serial.println("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)


{

78
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

void loop()
{
float h =dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}

if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com


{

String postStr = apiKey;


postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");


client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");

79
client.print(postStr);

Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");

// thingspeak needs minimum 15 sec delay between updates


delay(10000);
}

9.6 DATA ANALYSIS AND VISUALIZATION

We have pushed data from NodeMCU to Cloud. The pushed data can be seen in figure 9.8.

Figure 9.8

Sensor data will be updated on the cloud automatically at interval of 30 secs. After receiving the
data on the cloud, add different visualization types from the NATLAB visualization Tab. Refer

80
Figure 9.9 for example of two types of visualization (Histogram and Graph).

The updated data on the cloud can be accessed and downloaded from the Import / Export Tab on
the website as shown in figure 9.10. Download the data by clicking the download button below
xport tab. A .csv file will be downloaded to be used for further analysis.

Figure 9.10

Data analysis can also be done online by the given MATLAB Analysis button the website. Click
the button MATLAB Analysis button as shown in figure 9.11. Some Predefined analysis process
can be applied as shown in figure 9.12.

81
Figure 9.11

Figure 9.12

82
Figure 9.13
Conclusion
In this experiment we have successfully sent the sensor data to the cloud using Node MCU. The
data is visualized and analyzed.

83

You might also like