3 UNIT_IOT FINAL
3 UNIT_IOT FINAL
3 UNIT_IOT FINAL
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.
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.
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.
❖ 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.
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.
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.
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:
10. Accept the license by clicking on 'I Agree' button, as 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:
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:
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.
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:
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
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.
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.
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.
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.
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.
• 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.
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.
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.
15
III Unit
serial.begin(baud rate): Sets the beginning of serial communication by setting the bit
rate.
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.
Mount the female headers onto the board and connect them to the respective
pins on the chip.
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.
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.
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
18
III Unit
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.
Raspberry PI Interfaces:
20
III Unit
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.
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