Unit IV IOT
Unit IV IOT
The Arduino board can be programmed to do anything by simply programming the microcontroller on
board using a set of instructions for which, the Arduino board consists of a USB plug to communicate
with your computer and a bunch of connection sockets that can be wired to external devices like motors,
LEDs etc. The aim of Arduino is to introduce the world of electronics to people who have small to no
experience in electronics like hobbyists, designers, artists etc.
Arduino is based on open source electronics project i.e. all the design specifications, schematics, software
are available openly to all the users. Hence, Arduino boards can bought from vendors as they are
commercially available or else you can make your own board by if you wish i.e. you can download the
schematic from Arduino’s official website, buy all the components as per the design specification, assemble
all the components, and make your own board.
Some people think of the entire Arduino board as a microcontroller, but this is inaccurate. The Arduino
board actually is a specially designed circuit board for programming and prototyping with Atmel
microcontrollers.
The nice thing about the Arduino board is that it is relatively cheap, plugs straight into a computer's USB
port, and it is dead-simple to setup and use (compared to other development boards).
Some of the key features of the Arduino Uno include:
An open source design. The advantage of it being open source is that it has a large community
of people using and troubleshooting it This makes it easy to find someone to help you debug your projects.
An easy USB interface . The chip on the board plugs straight into your USB port and registers on your
computer as a virtual serial port. This allows you to interface with it as through it were a serial device. The
benefit of this setup is that serial communication is an extremely easy (and time-tested) protocol, and USB
makes connecting it to modern computers really convenient.
Very convenient power management and built-in voltage regulation. You can connect an external
power source of up to 12v and it will regulate it to both 5v and 3.3v. It also can be powered
directly off of a USB port without any external power.
A 16mhz clock. This makes it not the speediest microcontroller around, but fast enough for most
applications.
32 KB of flash memory for storing your code.
13 digital pins and 6 analog pins. These pins allow you to connect external hardware to your
Arduino. These pins are key for extending the computing capability of the Arduino into the real
world. Simply plug your devices and sensors into the sockets that correspond to each of these pins
and you are good to go.
An ICSP connector for bypassing the USB port and interfacing the Arduino directly as a serial
device. This port is necessary to re-bootload your chip if it corrupts and can no longer talk to your
computer.
An on-board LED attached to digital pin 13 for fast an easy debugging of code.
Step 3: Arduino IDE
Before you can start doing anything with the Arduino, you need to download and install the Arduino
IDE (integrated development environment). From this point on we will be referring to the Arduino IDE
as the Arduino Programmer.
The Arduino Programmer is based on the Processing IDE and uses a variation of the C and C++
programming languages.
You can find the most recent version of the Arduino Programmer on this page.
Step 4: Plug It In
It is also good to know that every single Arduino has a unique virtual serial port address. This means that
every time you plug in a different Arduino board into your computer, you will need toreconfigure the serial
port that is in use.
Step 5: Settings
Before you can start doing anything in the Arduino programmer, you must set the board-type
andserial port.
To set the board, go to the following:
Tools --> Boards
Select the version of board that you are using. Since I have an Arduino Uno plugged
in, Iobviously selected "Arduino Uno."
To set the serial port, go to the following:Tools --> Serial Port
Select the serial port that looks like:
/dev/tty.usbmodem [random numbers]
Step 6: Run a Sketch
Arduino programs are called sketches. The Arduino programmer comes with a ton of example sketches
preloaded. This is great because even if you have never programmed anything in your life, you can load
one of these sketches and get the Arduino to do something.
To get the LED tied to digital pin 13 to blink on and off, let's load the blink example.
The blink example can be found here:
Files --> Examples --> Basics --> Blink
The blink example basically sets pin D13 as an output and then blinks the test LED on theArduino
board on and off every second.
Once the blink example is open, it can be installed onto the ATMEGA328 chip by pressing theupload
button, which looks like an arrow pointing to the right.
Notice that the surface mount status LED connected to pin 13 on the Arduino will start to blink. You can
change the rate of the blinking by changing the length of the delay and pressing the upload button again.
Step 7: Serial Monitor
The serial monitor allows your computer to connect serially with the Arduino. This is important because
it takes data that your Arduino is receiving from sensors and other devices and displaysit in real-time on
your computer. Having this ability is invaluable to debug your code and understand what number values
the chip is actually receiving.
For instance, connect center sweep (middle pin) of a potentiometer to A0, and the outer pins, respectively,
to 5v and ground. Next upload the sketch shown below:
File --> Examples --> 1.Basics --> AnalogReadSerial Click the button to engage the serial monitor which
looks like a magnifying glass. You can now see the numbers being read by the analog pin in the serial
monitor. When you turn the knob the numbers will increase and decrease.
The numbers will be between the range of 0 and 1023. The reason for this is that the analog pinis
converting a voltage between 0 and 5V to a discreet number.
Step 8: Digital In
The Arduino has two different types of input pins, those being analog and digital.To begin with, lets look
at the digital input pins
Digital input pins only have two possible states, which are on or off. These two on and off states are also
referred to as:
• HIGH or LOW
• 1 or 0
• 5V or 0V.
This input is commonly used to sense the presence of voltage when a switch is opened or closed. Digital
inputs can also be used as the basis for countless digital communication protocols. By creating a 5V
(HIGH) pulse or 0V (LOW) pulse, you can create a binary signal, the basis of all computing. This is useful
for talking to digital sensors like a PING ultrasonic sensor, or communicating with other devices.
Step 9: Analog In
Aside from the digital input pins, the Arduino also boasts a number of analog input pins.
Analog input pins take an analog signal and perform a 10-bit analog-to-digital (ADC) conversionto turn
it into a number between 0 and 1023 (4.9mV steps).
This type of input is good for reading resistive sensors. These are basically sensors whichprovide
resistance to the circuit. They are also good for reading a varying voltage signal between 0 and 5V. This is
useful when interfacing with various types of analog circuitry.
If you followed the example in Step 7 for engaging the serial monitor, you have already tried using an
analog input pin.
As mentioned earlier, the Arduino has a number of built in special functions. One of thesespecial
functions is pulse width modulation, which is the way an Arduino is able to create an analog-like
output.
Pulse width modulation - or PWM for short - works by rapidly turning the PWM pin high (5V) and low
(0V) to simulate an analog signal. For instance, if you were to blink an LED on and off rapidly enough
(about five milliseconds each), it would seem to average the brightness and only appear to be receiving
half the power. Alternately, if it were to blink on for 1 millisecond and then blink off for 9 millisecond,
the LED would appear to be 1/10 as bright and only be receiving1/10 the voltage.
PWM is key for a number of applications including making sound, controlling the brightness of lights,
and controlling the speed of motors.
To try out PWM yourself, connect an LED and 220 ohm resistor to digital pin 9, in series toground.
Run the following example code:
File --> Examples --> 3.Analog --> Fading
4.1.2 Raspberry Pi
Raspberry Pi is a low-cost pocket computer that is very economical to own. It is about the size of
an ATM Card and can work as a fully functional computer in certain normal use cases, like working with
simple applications, playing low-end games, etc. It was first released in 2012 by the Raspberry Pi
foundation with the aim to provide easy access to computing education to everyone. It can cost as less as
5$ to a maximum price of 100$ (which is rare).
Scope
we will be understanding Operating systems that can be installed on a Raspberry Pi.
• We'll learn about What an operating system in general is.
• We'll go through a Variety of Operating Systems that a Raspberry Pi can run.
Introduction
As read above, Raspberry Pi is a very low-cost computer that comes along with the advantage of
portability. However, being in such a small form factor, it gets bounded by the type of hardwareto use in
making it; hence, it will be significantly tough to run regular operating systems on it.
Due to this, specific operating systems were designed to power a Raspberry Pi; some of them were entirely
new, while some originated from existing popular operating systems. Most of the Raspberry Pi OS is Linux
based, but it also has windows 10-based Raspberry Pi OS (Windows 10 IoT core) built explicitly for low-
powered devices like this.
Meaning an operating system is a software program that helps us to use and to connect with the
computer hardware. For example, if we want to use our mouse or keyboard, only with the help ofan OS we
can do that; if we want to install some program on our computer, we would be needing an OS; if we want
to create a file, we need an OS; we want to delete a file, we would again be
needing an OS, i.e., without an operating system we cannot use the computer hardware, wewould be
needing some underlying software, i.e., some operating system, using which we would do so.
The above image is a picture of a Raspberry Pi; we can see that there are various ports available in it on
which different devices can be mounted and used.
It was first launched in 2012, and from then onwards, various variations of it have been launched. The
original Raspberry Pi had a single-core 700mhz CPU and a 256MB of RAM, butit has evolved a lot since
then; today, we have a quad-core Raspberry Pi with a clock speed of around 1.5Ghz and up to 4GB of RAM.
Surprisingly the cost of Raspberry Pi has always been less than 100 USD. In fact, the Raspberry Pi Zero (an
even low-cost version of regular RaspberryPi) costs as less as 5 USD. A full-fledged general-purpose CPU
under 5$, that's what theorganization's mission is "Aiming to provide people easier and low-cost access to
the computers."
Raspberry Pi is used by people all around the world in learning how to program, build hardware projects,
do home automation, and implement Kubernetes clusters, and it is even getting used in some industrial
applications. Raspberry Pi is a very economical computer that runs LinuxOperating System.
Now, let's talk about which specific distribution of Linux Raspberry Pi uses. Raspberry Pi officially
recommends the use of the Raspbian Operating System. It is a Debian-based OS, explicitly made for
Raspberry Pi and hence its name Raspbian.
Raspbian
Raspbian or Raspberry Pi OS is a Linux-based operating system built specifically for Raspberry Pi. It
is packed with all the necessary tools and features that are required for day-to-day use. It will possibly
run on every kind of Raspberry Pi board with a few exceptions, like the Raspberry Pi's pico edition,
because of its far smaller form factor and computing power.
NOOBS
New Out Of the Box Software, or simply NOOBS is an operating system installer for
Raspberry Pi, delivered primarily on an SD card, which contains a variety of operating
systems, out of which we can choose which one we want to install on our Raspberry Pi. It
is made for people who are absolutely new to the Raspberry Pi and do not want to deal with
the complex setting up process of burning an OS image on an SD card. NOOBS is provided
along with every new Raspberry Pi at the time of its purchase.
With NOOBS, the user only needs to connect their Raspberry Pi to a display screen and a
keyboard and then power it up; the NOOBs will boot. There we can select which operating
system we want to install, and NOOBS will install the respective OS on the same SD card
withina few minutes.