0% found this document useful (0 votes)
2 views29 pages

3 UNIT_IOT FINAL

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 29

UNIT III

IOT PHYSICAL DEVICES AND ENDPOINTS

Introduction to Arduino and Raspberry Pi- Installation, Interfaces (serial, SPI, I2C), Programming –
Python program with Raspberry PI with focus on interfacing external gadgets, controlling output, and
reading input from pins.

INTRODUCTION TO ARDUINO AND RASPBERRY PI

Arduino and Raspberry Pi are used as a tool for creating electronic projects.

ARDUINO

Arduino is a software as well as hardware platform that helps in making electronic projects. It is
an open source platform and has a variety of controllers and microprocessors. There are various types of
Arduino boards used for various purposes.

The Arduino is a single circuit board, which consists of different interfaces or parts. The board consists of
the set of digital and analog pins that are used to connect various devices and components, which we want
to use for the functioning of the electronic devices.

Most of the Arduino consists of 14 digital I/O pins.

The analog pins in Arduino are mostly useful for fine-grained control. The pins in the Arduino board are
arranged in a specific pattern. The other devices on the Arduino board are USB port, small components
(voltage regulator or oscillator), microcontroller, power connector, etc.

The features of Arduino are listed below:

❖ Arduino programming is a simplified version of C++, which makes the learning process easy.

❖ The Arduino IDE is used to control the functions of boards. It further sends the set of
specifications to the microcontroller.
❖ Arduino does not need an extra board or piece to load new code.

❖ Arduino can read analog and digital input signals.

❖ The hardware and software platform is easy to use and implement.

MICROCONTROLLER

The most essential part of the Arduino is the Microcontroller, which is shown below:

Microcontroller is small and low power computer. Most of the microcontrollers have a RAM (Random
Access Memory), CPU (Central Processing Unit), and memory storage like other computer systems.

It has very small memory of 2KB (two Kilobytes). Due to less memory, some microcontrollers are
capable of running only one program at a time.

It is a single chip that includes memory, Input/Output (I/O) peripherals, and a processor.
The GPIO (General Purpose Input Output) pins present on the chip help us to control other electronics or
circuitry from the program.
ARDUINO KITS
We can easily start with our electronics projects using the complete kit. It also helps us to create hand-on
and engaging projects.

Some of the popular Arduino kits are listed below:

❖ Arduino Starter kit


❖ Robot Linking UNO kit for learning
❖ Arduino UNO 3 Ultimate starter kit
❖ UNO Super starter kit
❖ Mega 2560 Starter Kit
Arduino IDE

The IDE makes the traditional projects even easier and simpler. The USB cable is used to load the
program or sketch on the specific Arduino board.

The IDE application is suitable for Windows, Mac OS X, and Linux


❖ It supports the programming language C and C++
❖ We need to connect the Genuine and Arduino board with the IDE to upload the sketch written
in the Arduino IDE software.
ARDUINO BOARDS
There are variety of Arduino board used for different purposes. The board varies in I/O pins, size, etc.
The various components present on the Arduino boards are Microcontroller, Digital Input/Output pins,
USB Interface and Connector, Analog Pins, Reset Button, Power button, LED's, Crystal Oscillator, and
Voltage Regulator. Some components may differ depending on the type of board.
Let's discuss some of the popular Arduino boards.
❖ Arduino UNO
❖ Arduino Nano
❖ Arduino Mega
❖ Arduino Due
❖ Arduino Bluetooth
ARDUINO DOWNLOAD
The Arduino software (IDE) is open-source software. We are required to write the code and upload the
code to the board to perform some task.
The Arduino IDE software can be used with any type of Arduino boards. The software is available for
various operating system such as, Windows, Linux, and Mac OS X.
The steps to download the Arduino software are listed below:
1. Go to the official website of Arduino (https://www.arduino.cc/) > Click on SOFTWARE < click on
DOWNLOADS, as shown below:

2. A page will appear, as shown below:

3. Scroll the screen a little, as shown below:


4. Click on the 'Windows Installer' as we are operating with the Windows. We can select the
Linux or Mac OS X, accordingly.

5. A contribution window will appear. We can contribute according to our choice and click on
the 'CONTRIBUTE &DOWNLOAD' option. Otherwise, click on the 'JUST DOWNLOAD'
option, as shown below:

6. The downloading process will start. The downloading file will look like the below image:

7. Wait for few seconds for the downloading process to complete.


8. Open the downloaded file.

9. Grant permission to the Arduino Software on your computer.

10. Accept the license by clicking on 'I Agree' button, as shown below:

11. Click on the 'Next' button. It is shown below:


12. The window specifying the location of the installed folder will appear. Click on the 'Install'
button. It is shown below:

If you want to change the location, click on the 'Browse' button.

13. The installing process of Arduino will start, as shown below:

Wait for the installation process to complete.


14. Now, we have to accept the security for the installation. We are required to accept the
security Installation three times.

Click on the 'Install' button. The image is shown below:


15. Again, click on the 'Install' button. It is shown below:

16. Again, click on the 'Install' button. It is shown below:

17. The installation process is now completed. The window will now appear as:
18. Click on the 'Close' button at the bottom.

The Arduino IDE software will appear on your desktop, as shown below:

19. Now, open the Arduino software.

20. The Arduino IDE environment is written in the programming language named as Java. So,
we need to allow access to the Java Platform.

As soon we open the Arduino software, a license window will appear, as shown below:

Accept the license by clicking on the 'Allow access' button.

21. The Arduino window will appear as:


Visibility of the connected Hardware port
We can view the port of the attached hardware Arduino IDE to our computer. The steps are listed below:
Go to the File Manager and right-click on the This PC option, as shown below:

Click on the Manage


First, we need to connect the Arduino board to our computer. A window will appear, as shown below:

Click on the Device Manager


Under the PORT option, we can see the ports of the connected hardware. Arduino IDE
The Arduino IDE is an open-source software, which is used to write and upload code to the Arduino
boards. The IDE application is suitable for different operating systems such as Windows, Mac OS X, and
Linux. It supports the programming languages C and C++. Here, IDE stands for Integrated Development
Environment.
The program or code written in the Arduino IDE is often called as sketching. We need to connect the
Genuino and Arduino board with the IDE to upload the sketch written in the Arduino IDE software. The
sketch is saved with the extension '.ino.'

The Arduino IDE will appear as:


Let's discuss each section of the Arduino IDE display in detail. Toolbar Button
The icons displayed on the toolbar are New, Open, Save, Upload, and Verify.

It is shown below:

Upload
The Upload button compiles and runs our code written on the screen. It further uploads the code to the
connected board. Before uploading the sketch, we need to make sure that the correct board and ports are
selected.

We also need a USB connection to connect the board and the computer. Once all the above measures are
done, click on the Upload button present on the toolbar.

The latest Arduino boards can be reset automatically before beginning with Upload. In the older boards,
we need to press the Reset button present on it. As soon as the uploading is done successfully, we can
notice the blink of the Tx and Rx LED.
If the uploading is failed, it will display the message in the error window.

We do not require any additional hardware to upload our sketch using the Arduino Bootloader. A
Bootloader is defined as a small program, which is loaded in the microcontroller present on the board.
The LED will blink on PIN 13.

Open
The Open button is used to open the already created file. The selected file will be opened in the current
window.
Save
The save button is used to save the current sketch or code.

New
It is used to create a new sketch or opens a new window.

Verify
The Verify button is used to check the compilation error of the sketch or the written code.

Serial Monitor
The serial monitor button is present on the right corner of the toolbar. It opens the serial monitor.

It deis shown below:


When we connect the serial monitor, the board will reset on the operating system Windows, Linux, and
Mac OS X. If we want to process the control characters in our sketch, we need to use an external terminal
program. The terminal program should be connected to the COM port, which will be assigned when we
connect the board to the computer.

Menu Bar File


When we click on the File button on the Menu bar, a drop-down list will appear. It is
shown below:

Close

The Close button closes the window from which the button is clicked.

Save

The save button is used to save the current sketch. It also saves the changes made to the current sketch. If
we have not specified the name of the file, it will open the 'Save As...' window.
Save As...

We can save the sketch with a different name using the 'Save As...' button. We can also change the name
accordingly.
Page Setup

It allows setting the page margins, orientation, and size for printing. The 'Page Setup' window will appear
as:

5.1 Building IOT with Arduino

Internet of Things

The Internet of Things (IoT) is a scenario in which objects, animals or people are provided
with single identifiers and the capability to automatically transfer and the capability to
automatically transfer data more to a network without requiring human-to-human or human-
to-computer communication.

Arduino Board:
 An Arduino is actually a microcontroller based kit.
 It is basically used in communications and in controlling or operating many devices.
 Arduino UNO board is the most popular board in the Arduino board family.
 In addition, it is the best board to get started with electronics and coding.
 Some boards look a bit different from the one given below, but most Arduino’s
have majority of these components in common.
 It consists of two memories- Program memory and the data memory.
 The code is stored in the flash program memory, whereas the data is stored in the data
memory.
 Arduino Uno consists of 14 digital input/output pins (of which 6 can be used as PWM
outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power
jack, an ICSP header, and a reset button
16.ARE
17.Arduino 15.Digital I/O
F
Reset
14.TX and RX
LEDs

1.Power
USB 4.Crystal Oscillator
3.Powe
r LED
1 indicator

12.ICSP pin
3.Voltage
Regulator
11.Main
microcontroll
2.Power er
(Barrel Jack)
5.Arduino
Reset
6,7,8,9.Pins 10.Analog pins
(3.3,
5, GND, Vin)
III Unit

1. Power USB
Arduino board can be powered by using the USB cable from your computer. All you
need to do is connect the USB cable to the USB connection (1).
2. Power (Barrel Jack)
Arduino boards can be powered directly from the AC mains power supply by connecting
it to the Barrel Jack (2).
3. Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino board
and stabilize the DC voltages used by the processor and other elements.
4. Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino
calculate time? The answer is, by using the crystal oscillator. The number printed on top of the
Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16 MHz.
5,17.Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning. You can
reset the UNO board in two ways. First, by using the reset button (17) on the board. Second, you
can connect an external reset button to the Arduino pin labelled RESET (5).
6,7,8,9.Pins (3.3, 5, GND, Vin)
• 3.3V (6) − Supply 3.3 output volt
• 5V (7) − Supply 5 output volt
• Most of the components used with Arduino board works fine with 3.3 volt and 5 volt.
• GND (8)(Ground) − There are several GND pins on the Arduino, any of which can be
used to ground your circuit.
• Vin (9) − This pin also can be used to power the Arduino board from an external power
source, like AC mains power supply.

13
III Unit

10. Analog pins

The Arduino UNO board has six analog input pins A0 through A5. These pins can read
the signal from an analog sensor like the humidity sensor or temperature sensor and
convert it into a digital value that can be read by the microprocessor.

11. Main microcontroller

Each Arduino board has its own microcontroller (11). You can assume it as the brain of
your board. The main IC (integrated circuit) on the Arduino is slightly different from board to
board. The microcontrollers are usually of the ATMEL Company. You must know what IC your
board has before loading up a new program from the Arduino IDE. This information is available
on the top of the IC. For more details about the IC construction and functions, you can refer to
the data sheet.

12. ICSP pin

Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting of
MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial
Peripheral Interface), which could be considered as an "expansion" of the output.
Actually, you are slaving the output device to the master of the SPI bus.

13. Power LED indicator

This LED should light up when you plug your Arduino into a power source to indicate
that your board is powered up correctly. If this light does not turn on, then there is
something wrong with the connection.

14. TX and RX LEDs

On your board, you will find two labels: TX (transmit) and RX (receive). They appear in
two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the
pins responsible for serial communication. Second, the TX and RX led (13). The TX led
flashes with different speed while sending the serial data. The speed of flashing depends
on the baud rate used by the board. RX flashes during the receiving process.

15. Digital I/O

• The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse
Width Modulation) output. These pins can be configured to work as input digital pins to
read logic values (0 or 1) or as digital output pins to drive different modules like LEDs,
relays, etc. The pins labeled “~” can be used to generate PWM.

16. AREF

14
III Unit

• AREF stands for Analog Reference. It is sometimes, used to set an external reference
voltage (between 0 and 5 Volts) as the upper limit for the analog input pins.

Program an Arduino
 The most important advantage with Arduino is the programs can be directly loaded to the
device without requiring any hardware programmer to burn the program.
 This is done because of the presence of the 0.5KB of Bootloader which allows the
program to be burned into the circuit.
 All we have to do is to download the Arduino software and writing the code.
 The Arduino tool window consists of the toolbar with the buttons like verify, upload,
new, open, save, serial monitor.
 It also consists of a text editor to write the code, a message area which displays the
feedback like showing the errors, the text console which displays the output and a series
of menus like the File, Edit, Tools menu.

Steps to program an Arduino


 Programs written in Arduino are known as sketches. A basic sketch consists of 3 parts

1. Declaration of Variables
2. Initialization: It is written in the setup () function.
3. Control code: It is written in the loop () function.

 The sketch is saved with .ino extension. Any operations like verifying, opening a sketch,
saving a sketch can be done using the buttons on the toolbar or using the tool menu.

 The sketch should be stored in the sketchbook directory.

 Chose the proper board from the tools menu and the serial port numbers.

 Click on the upload button or chose upload from the tools menu. Thus the code is
uploaded by the bootloader onto the microcontroller.

Basic Adruino functions are:

 digitalRead(pin): Reads the digital value at the given pin.

 digitalWrite(pin, value): Writes the digital value to the given pin.

 pinMode(pin, mode): Sets the pin to input or output mode.

 analogRead(pin): Reads and returns the value.

 analogWrite(pin, value): Writes the value to that pin.

15
III Unit

 serial.begin(baud rate): Sets the beginning of serial communication by setting the bit
rate.

Design your own Arduino


 The following components are needed to design Arduino Board- A breadboard, a led, a
power jack, a IC socket, a microcontroller, few resistors, 2 regulators, 2 capacitors.

 The IC socket and the power jack are mounted on the board.

 Add the 5v and 3.3v regulator circuits using the combinations of regulators
and capacitors.

 Add proper power connections to the microcontroller pins.

 Connect the reset pin of the IC socket to a 10K resistor.

 Connect the crystal oscillators to pins 9 and 10

 Connect the led to the appropriate pin.

 Mount the female headers onto the board and connect them to the respective
pins on the chip.

 Mount the row of 6 male headers, which can be used as an alternative to


upload programs.

 Upload the program on the Microcontroller of the readymade Adruino and


then pry it off and place back on the user kit.

Advantages of Arduino Board

1. It is inexpensive

2. It comes with an open source hardware feature which enables users to develop their own
kit using already available one as a reference source.

3. The Arduino software is compatible with all types of operating systems like Windows,
Linux, and Macintosh etc.

4. It also comes with open source software feature which enables experienced software
developers to use the Arduino code to merge with the existing programming language
libraries and can be extended and modified.

5. It is easy to use for beginners.

16
III Unit

6. We can develop an Arduino based project which can be completely stand alone or
projects which involve direct communication with the software loaded in the computer.

7. It comes with an easy provision of connecting with the CPU of the computer using serial
communication over USB as it contains built in power and reset circuitry.

Interfaces

UART Peripheral:
 A UART (Universal Asynchronous Receiver/Transmitter) is a serial interface.
 It has only one UART module.
 The pins (RX, TX) of the UART are connected to a USB-to-UART converter circuit and
also connected to pin0 and pin1 in the digital header.

SPI Peripheral:
 The SPI (Serial Peripheral Interface) is another serial interface. It has only one SPI
module.
TWI:
 The I2C or Two Wire Interface is an interface consisting of only two wires, serial data,
and a serial clock: SDA, SCL.
 You can reach these pins from the last two pins in the digital header or pin4 and pin5 in
the analog header.

5.2 Building IOT with RASPERRY


PI Internet of Things

The Internet of Things (IoT) is a scenario in which objects, animals or people are provided with
single identifiers and the capability to automatically transfer and the capability to automatically
transfer data more to a network without requiring human-to-human or human-to-computer
communication.

Raspberry Pi

 The Raspberry Pi is a very cheap computer that runs Linux, but it also provides a set of
GPIO (general purpose input/output) pins that allow you to control electronic
components for physical computing and explore the Internet of Things (IoT).
 Raspberry Pi was basically introduced in 2006.
 It is particularly designed for educational use and intended for Python.
 A Raspberry Pi is of small size i.e., of a credit card sized single board computer, which is
developed in the United Kingdom(U.K) by a foundation called Raspberry Pi.

17
III Unit

 There have been three generations of Raspberry Pis: Pi 1, Pi 2, and Pi 3


 The first generation of Raspberry (Pi 1) was released in the year 2012, that has two types
of models namely model A and model B.
 Raspberry Pi can be plugged into a TV, computer monitor, and it uses a standard
keyboard and mouse.
 It is user friendly as can be handled by all the age groups.
 It does everything you would expect a desktop computer to do like word-processing,
browsing the internet spreadsheets, playing games to playing high definition videos.
 All models feature on a broadcom system on a chip (SOC), which includes chip graphics
processing unit GPU(a Video Core IV), an ARM compatible and CPU.
 The CPU speed ranges from 700 MHz to 1.2 GHz for the Pi 3 and on board memory
range from 256 MB to 1 GB RAM.
 An operating system is stored in the secured digital SD cards and program memory in
either the MicroSDHC or SDHC sizes.
 Most boards have one to four USB slots, composite video output, HDMI and a 3.5 mm
phone jack for audio. Some models have WiFi and Bluetooth.
 Several generations of Raspberry Pis have been released.
 All models feature a Broadcom system on a chip (SoC) with an integrated ARM-
compatible central processing unit (CPU) and on-chip graphics processing unit (GPU).
 Processor speed ranges from 700 MHz to 1.4 GHz for the Pi 3 Model B+ or 1.5 GHz for
the Pi 4; on-board memory ranges from 256 MB to 1 GB with up to 4 GB available on
the Pi 4 random-access memory (RAM).
 Secure Digital (SD) cards in MicroSDHC form factor (SDHC on early models) are used
to store the operating system and program memory.
 The boards have one to five USB ports. For video output, HDMI and composite video are
supported, with a standard 3.5 mm tip-ring-sleeve jack for audio output.
 Lower-level output is provided by a number of GPIO pins, which support common
protocols like I²C. The B-models have an 8P8C Ethernet port and the Pi 3 and Pi Zero W
have on-board Wi-Fi and Bluetooth.

18
III Unit

Components and Peripherals

 Voltages: Two 5V pins and two 3V3 pins are present on the board, as well as a number
of ground pins (0V). The remaining pins are all general purpose 3V3 pins
 A GPIO pin designated as an output pin can be set to high (3V3) or low (0V). A GPIO
pin designated as an input pin can be read as high (3V3) or low (0V).
 Processor & RAM: Raspberry based on ARM11 processor. Latest version supports
700MHz processor and 512MB SDRAM. The Central processing unit is the brain of the
raspberry pi board and that is responsible for carrying out the instructions of the computer
through logical and mathematical operations.
 Ethernet: The Ethernet port of the raspberry pi is the main gateway for communicating
with additional devices. The raspberry pi Ethernet port is used to plug your home router
to access the internet.

19
III Unit

 USB Ports: It has 2 USB ports. USB port provide current upto 100mA. For connecting
devices that draw current more than 100mA, an external USB powered hub is required.
 Ethernet Port: It has standard RJ45 Ethernet port. Connect Ethernet cable or USB wifi
adapter to provide internet connectivity.
 HDMI Output: It supports both audio and video output. Connect raspberry Pi to monitor
using HDMI cable.
 Composite video Output: Raspberry comes with a composite video output with an RCA
jack that supports both PAL and NTSC video output.
 Audio Output: It has 3.5mm audio output jack. This audio jack is used for providing
audio output to old television along with RCA jack for video.
 GPIO Pins: It has a number of general purpose input/output pins. These pins are used to
connect other electronic components. For example, you can connect it to the temperature
sensor to transmit digital data.
 Display Serial Interface (DSI): DSI interface are used to connect an LCD panel to
Raspberry PI.
 Cameral Serial Interface(CSI): CSI interface are used to connect a camera module to
Raspberry PI.
 SD Card slot: Raspberry does not have built in OS and storage. Plug in an SD card
loaded with Linux to SD card slot.
 Power Input: Raspberry has a micro USP connector for power input.
 Memory: The raspberry pi model A board is designed with 256MB of SDRAM and
model B is designed with 51MB.Raspberry pi is a small size PC compare with other PCs.
The normal PCs RAM memory is available in gigabytes. But in raspberry pi board, the
RAM memory is available more than 256MB or 512MB
 Status LEDs: Raspberry has 5 status LEDs.

Status LED Function


ACT SD card Access
PWR 3.3V power is present
FDX Full duplex LAN Connected
LNK Link/Network Activity
100 100 Mbit LAN connected

Raspberry PI Interfaces:

 It supports SPI, serial and I2C interfaces for data transfer.


 Serial : Serial Interface on Raspberry has receive(Rx) and Transmit(Tx) pins for
communication with serial peripherals.
 SPI: Serial Peripheral Interface (SPI) is a synchronous serial data protocol used for
communicating with one or more peripheral devices. In an SPI connection, there is one
master device and one or more peripheral devices. There are 5 pins Raspberry for SPI
interface.
o MISO(Master In Slave Out): Master line for sending data to the peripherals.
o MOSI(Master Out Slave In): Slave Line for sending data to the master.
o SCK(Serial Clock): Clock generated by master to synchronize data transmission.
o CE0(Chip Enable 0): To enable or disable devices.

20
III Unit

o CE1(Chip Enable 1): To enable or disable devices.


 I2C: I2C Interface pins are used to connect hardware modules. I2C interface allows
synchronous data transfer with two pins: SDA(data line) and SCL (Clock Line)

Features of Raspberry PPI

1. Where the system processing is huge. They can process high end programs for applications
like Weather Station, Cloud server, gaming console etc. With 1.2GHz clock speed and 1 GB
RAM RASPBERRY PI can perform all those advanced functions.

2. RASPBERRY PI 3 has wireless LAN and Bluetooth facility by which you can setup WIFI
HOTSPOT for internet connectivity.

3. RASPBERRY PI had dedicated port for connecting touch LCD display which is a feature that
completely omits the need of monitor.

4. RASPBERRY PI also has dedicated camera port so one can connect camera without any
hassle to the PI board.

5. RASPBERRY PI also has PWM outputs for application use.

6. It supports HD steaming

Applications

 Hobby projects.
 Low cost PC/tablet/laptop
 IoT applications
 Media center
 Robotics
 Industrial/Home automation
 Server/cloud server
 Print server
 Security monitoring
 Web camera
 Gaming
 Wireless access point

21
III Unit

22
III Unit

23
III Unit

24
III Unit

25
III Unit

26
III Unit

27
III Unit

28
III Unit

29

You might also like