How Is Arduino Uno Different From Other Available Microcontrollers?
How Is Arduino Uno Different From Other Available Microcontrollers?
MODULE 5
Module5 Page 1
INTERNET OF THINGS TECHNOLOGY 15CS81
LED attached to digital pin 13: This is useful for easy debugging of arduino
sketches.
Analog Pins: The analog pins are labelled A0 to A5. They are used to read analog
sensors.
Module5 Page 2
INTERNET OF THINGS TECHNOLOGY 15CS81
party cores, other vendor development boards.
How to get started?
Download and Install the open source Arduino IDE
Connect the board to PC
Launch the Arduino IDE
Select your board and serial port
Write and compile the code
Upload the program into the Microcontroller
Step 1
First you must have your Arduino board (you can choose your favourite 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.
In case you use Arduino Nano, you will need an A to Mini-B cable instead as shown in the
following image.
Module5 Page 3
INTERNET OF THINGS TECHNOLOGY 15CS81
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.
Module5 Page 4
INTERNET OF THINGS TECHNOLOGY 15CS81
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.
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. 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.
Module5 Page 5
INTERNET OF THINGS TECHNOLOGY 15CS81
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 sketches.
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.
Note − If you have an Arduino Mini, NG, or other board, you need to press the reset
button physically on the board, immediately before clicking the upload button on the
Arduino Software.
Essentially this is a complete code, it complies and can be uploaded to the Arduino but
there is nothing in this code. It is important to understand this code structure because
every Arduino sketch will contain a void setup() and a void loop() functions even if they are
empty. The sketch will not compile without either one.
The void setup() is the first function to be executed in the sketch and it is executed only
once. It usually contains statements that set the pin modes on the Arduino to OUTPUT
and INPUT, example:
pinMode (12, OUTPUT);
pinMode(11, INPUT);
Or to start the serial monitor example: serial.begin(9600);
The void loop() is a function that executes indefinitely until you power off the Arduino.
Step 2: PinMode(), DigitalWrite() and Delay()
We already established that the void setup() is a function that runs only once at the
beginning of the sketch. Within this function there is a statement called pinMode().
The job of the pinMode statement is to set the Arduino pins to OUTPUT or INPUT.
OUTPUT means that this pin will produce a result like turning on or off an LED.
INPUT is used to prepare the pin to receive information from a connected device like
a sensor.
pinMode(Pin, Mode): The Pin can be any physical pin on the Arduino, you can use
Module5 Page 6
INTERNET OF THINGS TECHNOLOGY 15CS81
Pin number like 1, 2, 3 etc… or you can use the variable name assigned to this pin,
example LED1, pinLed, etc… The Mode is OUTPUT or INPUT in capital letters.
Example:
pinMode(11,OUTPUT);
pinMode(echo, INPUT);
Curly braces{}: Are used to define the beginning and the end of functions and certain
statements. The braces are not only used with the void setup(), they are used
throughout the sketch including the void loop, if statements, user defined functions,
etc… every opening { should be followed by a closing } otherwise the code will
produce an error when compiling.
Semicolon ;: Are used to define the end of a statement. Missing a semicolon will also
produce an error while compiling the code. They are also be found separating
elements in a for loop.
Line comment //: Anything written after the // is not used by the program and they are
optional. However it is usually good practice to add comments so that other people can
understand the code also later on when the code gets bigger and more complicated, it will
help the programmer not to lose track of the code.
Within the curly braces of the void loop there are two new statements: digitalWrite()
and delay().
digitalWrite() changes the status of a pin by either writing a 5V or 0V using the
following syntax:
digitalWrite(13, HIGH); this will write 5V to pin 13 on the Arduino digitalWrite
(LEDpin, LOW); this will write a 0V to the variable LEDpin
essentially if you have an LED on PIN 13 on the Arduino, using digitalWrite(13,
HIGH); will turn on the LED and using digitalWrite(13,LOW); will turn off the LED.
delay() is straight forward, it is used to delay the execution of the next statement by the
amount of milliseconds within the (). Example:
delay(1000) means delay the execution of the next statement by 1000 milliseconds or 1
second.
Step 3: Variables
A variable is the bread and butter of all programming. It is used to store information to
be used later in the code. In this case we are declaring that a variable called pushButton of
the type int(integer) is assigned to digital pin number 2 on the Arduino.
Variables that are declared before the void setup() are called global variables because
they can be used by any function within the code.
Since we declared pushButton before the void setup(), this variable can be used in the
void setup() and the void loop(). On the other hand variables that are declared within a
function can only be used by that function and they are called local variables.
Variables have different types used to store different types of data.
Once a global variable is declared, it can be called upon by any function using the name
selected by the programmer (case sensitive).
Module5 Page 7
INTERNET OF THINGS TECHNOLOGY 15CS81
Step 4: AnalogRead() and AnalogWrite()
analogWrite(): using this statement we can write a new value into a pin,
Serial.println(): this will print the value of voltage on the serial monitor.
Step 5: If Statement
Every time we are using an if statement, we are looking to meet a certain condition,
example if "a" is bigger than "b". And if the result is true then we can execute whatever
is in between the curly brackets. If the result is not true then do nothing.
Now if you are using an if/else statement, and the result is not true, then whatever is
under "else" will execute.
The best way to set a condition is to use comparison and logical operators.
Comparison operators: They are used to compare variables and constants against each
other to verify if a certain condition is met.
Step 6: For Statement
The for loop is used to repeat the statement(s) enclosed within the curly brackets a
number of times defined by the increment and the condition.
Syntax:
for (initialization; condition; increment)
{ statement(s);
}
Step 7: While Loop
The While loop will keep on working until the statement within the brackets is no
longer true.
Syntax:
while(condit
ion){
statement1
statement2
etc..
}
Module5 Page 8
INTERNET OF THINGS TECHNOLOGY 15CS81
Zero W's inbuilt wireless.
Connectivity, or a USB wirelessdongle.
Module5 Page 9
INTERNET OF THINGS TECHNOLOGY 15CS81
6. Explain Raspberry pi OS.
Raspberry comes with all the software we require for basic computing. But if we want to
extend the functionalities to some extent, we can install an OS on the device.
It performs as a bridge between the user and Raspberry hardware. OS is the most
crucial program that enables the hardware to communicate with the software for
generating meaningful interactions.
Although Raspbian is the official Raspberry Pi OS, there are other alternative operating
systems also available to run Raspberry Pi projects.
Different types of Raspberry pi OS are:
1. Raspbian
This is the official OS, and it can be used on all models of Raspberry. This free operating
system is known as the modified version of the popular OS Debian. It can serve all the
general purposes for the Raspberry users. One can indulge in any project development
or prototype building and can expect any kind of support from this OS.
2. OSMC
This is the best Raspberry Pi OS if for working or managing media content. It is an open
source software that renders a beautiful interface and easy to use features. This software
is based on Kodi OS, which is capable of providing support for virtually any media
content.
3. RISC OS
There are many single-board computers that are using ARM processors. RISC OS is the
best Raspberry OS as it is intended to serve ARM processors .Enhances the performance
and efficiency of the system as well.
4. Windows IoT Core
This is a powerful Raspberry Pi OS. Specially designed for writing sophisticated programs
and making prototypes.
// variables
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
int DELAY_GREEN = 5000;
int DELAY_YELLOW = 2000;
int DELAY_RED = 5000;
Module5 Page 10
INTERNET OF THINGS TECHNOLOGY 15CS81
Now we need to setup the pins so they act as an output and not as an input.
The pinMode function accepts two parameters the pin number and the mode. (output or
input)
// basic functions
void setup()
{ pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT); }
The loop function creates a loop that the program will run through, so every time we call a
function, it will turn a light on and then we can set a delay, so it doesn’t change until that
time is up.
void loop()
{ green_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED); }
Now for each LED, we will need to create a function. As you can see
the green_light() function will turn the green LED on while turning the yellow and red
LEDs off.
void green_light()
{ digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW); }
void yellow_light()
{ digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW); }
void red_light()
{ digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH); }
);
Module5 Page 11
INTERNET OF THINGS TECHNOLOGY 15CS81
Once you are done writing the code, you will need to upload it to the Arduino
using the USB cable that should have come with your kit. The lights should start to
blink in the pattern that we have defined using the function calls and the delays.
You should always test your code before uploading it to the Arduino, you can do
this by clicking the verify button (Tick). This will let you know if there are any
errors in your code and allows you to make changes so that it is correct.
# make a directory:
mkdir newdirname
# change directory:
cd whatdir
ls
nano filename
# Root dir symbol, you can use this to cd to the root dir quickly with something like:
cd ~~
You can either interact with the terminal remotely with the Raspberry Pi using something
like XRDP (remote desktop), which still gives you the GUI, or you can also use SSH. A
popular program for SSH is called Putty. You use this to connect remotely to the
Raspberry Pi.
To do it, you will just need the IP address for your Raspberry Pi, usually this is just the
local IP Address. Something like 192.168.X.X is what it will look like. You can find your
Raspberry Pi's IP address by typing "ifconfig" in the terminal. You will be asked for a
username and password to connect. Default username: pi, default password: raspberry.
Module5 Page 12
INTERNET OF THINGS TECHNOLOGY 15CS81
First, to use GPIO, you will need to make sure you have the packages necessary on your
Raspberry Pi. Via the Pi terminal, type:
sudo apt-get install python-rpi.gpio
Once you have that, you're ready to code with GPIO.
Now, open up a Python script from the desktop.
Our first program is going to act like a door with a password. The idea is that, if the LED
light is "on," then the door is locked. In order to get the light to turn off and the "lock" to
unlock, we need to enter a correct password.
importRPi.GPIO as gpioimport time
First, we just import RPi.GPIO as gpio for some short-hand, then we import time so we
can make the program sleep for a moment.
gpio.setmode(gpio.BCM)
gpio.setup(18, gpio.OUT)
Here we are setting the mode to BCM, which is the naming convention for the GPIO
pins. You can either address the pins by their actual physical pin number, or their "name"
assigned to them. In order to be as careful as possible, it's best to explicitly check which
you are doing.
whileTrue:
gpio.output(18, gpio.HIGH)
while True is an infinite loop that will just always run, we are setting the output in to
high, and then asking the user to input the password.
if passcode =="Awesome":
gpio.output(18, gpio.LOW)
time.sleep(4)
We're assuming here the password is "Awesome." If that is what the user enters, then we
set the output pin to low, which will turn off the LED light for 4 seconds.
else:
Module5 Page 13
INTERNET OF THINGS TECHNOLOGY 15CS81
gpio.output(18, gpio.HIGH)
print("Wrong Password!")
If the password is not "Awesome," then the console will output that the password is
wrong and continue the high signal.
Module5 Page 14
INTERNET OF THINGS TECHNOLOGY 15CS81
Smart buildings have the potential to save $100 billion by lowering operating costs by
reducing energy consumption through the efficient integration of heating, ventilation, and
air-conditioning (HVAC) and other building infrastructure systems. Note that the financial
gain applies to city budgets only when a building is city owned. However, the reduced
emissions benefit the city regardless of who owns the buildings.
Gas monitoring:
Monitoring gas could save $69 billion by reducing meter-reading costs and increasing the
accuracy of readings for citizens and municipal utility agencies. The financial benefit is
obvious for users and utility companies when the utility is managed by the city. There are
also very important advantages in terms of safety, regardless of who operates the utility.
In cases of sudden consumption increase, a timely alert could lead to emergency response
teams being dispatched sooner, thus increasing the safety of the urban environment.
Smart parking:
Smart parking could create $41 billion by providing real-time visibility into parking
space availability across a city. Residents can identify and reserve the closest available
space, traffic wardens can identify noncompliant usage, and municipalities can introduce
demand-based pricing.
Water management:
Smart water management could save $39 billion by connecting household water meters
over an IP network to provide remote usage and status information. The benefit is
obvious, with features such as real-time consumption visibility and leak detection. In
addition, smart meters can be used to coordinate and automate private and public lawn
watering, initiating the watering programs at times when water consumption is lower or
in accordance with water restrictions imposed by civic authorities. At a city scale, IoT
can be
Road pricing:
Cities could create $18 billion in new revenues by implementing automatic payments as
vehicles enter busy city zones while improving overall traffic conditions. Real-time
traffic condition data is very valuable and actionable information that can also be used to
proactively reroute public transportation services or private users.
Module5 Page 15
INTERNET OF THINGS TECHNOLOGY 15CS81
To maximize the return on investment (ROI) on their energy and environmental
investments
Smart cities can employ strategies that combine water management, smart grid, waste
management and gas monitoring, which in turn leads to higher economic impact and
improves the potential for future investments.
Global vs. Siloed Strategies:
• The main obstacle in implementing smart solutions in today’s traditional infrastructure is
the complexity of how cities are operated, financed, regulated, and planned.
• Even cities using IoT technology break up city assets and service management into silos
that are typically unable to communicate or rely on each other.
• They require collection of large amounts of diverse data sets in real time.
• This means that data from traffic sensors, traffic cameras, parking sensors, and more has
to be collected and analyzed in real time.
• So that decision making can be optimized around signal timing, rerouting, and so on.
All these requirements pose technological challenges, including the following:
• How do you collect the data? What are the various sources of data,
• including hardware endpoints and software?
• How do you make sure that any data collection devices, such as sensors,
• can be maintained without high costs?
• Where do you analyze the data? What data do you carry back to the cloud,
• and what data do you analyze locally?
• How do you aggregate data from different sources to create a unified view?
• How do you publish the data and make it available for applications to consume?
• How do you present the long-term analysis to city planners?
10. With a neat diagram, explain wireless temperature monitoring system using
Raspberry Pi.
Raspberry Pi which having inbuilt wi-fi, which makes Raspberry Pi to suitable for IoT
applications, so that by using IoT technology this monitoring system works by uploading the
temperature value to the Things peak cloud by this project you can able to learn to how to
handle cloud-based application using API keys.
In this monitoring system, we used Thingspeak cloud, the cloud which is suitable to view
the sensor logs in the form of graph plots. Here we created one field to monitor the
temperature value, that can be reconfigurable to monitor a number of sensor values in various
fields.
This basic will teach you to how to work with a cloud by using LM35 as a temperature
sensor, to detect the temperature and to upload those values into the cloud.
DS18B20 Temperature Sensor
The DS18B20 is a 1-wire programmable Temperature sensor from maxim integrated. It is
widely used to measure temperature in hard environments like in chemical solutions, mines
or soil etc.The constriction of the sensor is rugged and also can be purchased with a water
Module5 Page 16
INTERNET OF THINGS TECHNOLOGY 15CS81
proof option making the mounting process easy. It can measure a wide range of temperature
from -55°C to +125° with a decent accuracy of ±5°C.
Each sensor has a unique address and requires only one pin of the MCU to transfer data so
it a very good choice for measuring temperature at multiple points without compromising
much of your digital pins on the microcontroller. Figure 5.4illustrates DS18B20 Temperature
Sensor Pin out and DS18B20 Temperature Sensor.
Figure 5.4: DS18B20 Temperature Sensor Pin out DS18B20 Temperature Sensor
HARDWARE REQUIRED
• Raspberry Pi
• SD card
• Power supply
• VGA to HDMI converter (Optional)
• MCP3008 (ADC IC)
• A temperature sensor(LM35)
SOFTWARE REQUIRED
• Raspbian Stretch OS
• SD card Formatter
• Win32DiskImager (or) Etcher
PYTHON LIBRARIES USED
• RPi. GPIO as GPIO (To access the GPIO Pins of Raspberry Pi)
• Time library (For Time delay)
• Urllib2 to handle URL using Python programming.
DS18B20 Temperature Sensor
Applications:
Measuring temperature at hard environments
Liquid temperature measurement
Applications where temperature has to be measured at multiple points
Pin Configuration:
No Pin Name Description
3 Data This pin gives output the temperature value which can be read using 1-wire method.
Module5 Page 17
INTERNET OF THINGS TECHNOLOGY 15CS81
11. Write a short note on Smart Traffic Control.
Traffic is one of the most well-understood pain points for any city. It is the leading cause
of accidental death globally, causes immense frustration, and heavily contributes to
pollution around the globe.
A smart city traffic solution would combine crowd counts, transit information, vehicle
counts, and so on and send events regarding incidents on the road so that other controllers
on the street could take action.
Figure 5.5 illustrates a Smart Traffic Architecture which helps to understand better.
Module5 Page 18
INTERNET OF THINGS TECHNOLOGY 15CS81
A common traffic pain point is stop-and-go, where traffic flow suddenly comes to a
halt and then flows again. This wavelike traffic pattern is a natural result of the
unpredictability of the traffic speed ahead and has long been studied by public and
private organizations.
A well-known remedy for stop-and-go traffic is to regulate the standard flow speed
based on car density. As density increases, car speed is forced down to avoid the wave
effect.
Information can also be shared with drivers. Countless applications leverage crowd
sourcing or sensor-sourced information to provide real-time travel time estimates,
suggest rerouting options to avoid congestion spots, or simply find the best way between
two points, while taking into account traffic, road work and many more.
By doing the following we can expect at the city level to regulate traffic flows and at a
citizen level to have a better driving experience.
Module5 Page 19
INTERNET OF THINGS TECHNOLOGY 15CS81
At the street layer there are a variety of multivendor sensor offerings, using a variety
of communication protocols.
Connected environment sensors might measure different gases, depending on a city’s
particular air quality issues, and may include weather and noise sensors. These sensors
may be located in a variety of urban fixtures, such as in street lights. They may also be
embedded in the ground or in other structures or smart city infrastructure.
Module5 Page 20
INTERNET OF THINGS TECHNOLOGY 15CS81
This information can be visualized in applications that include heat maps of
particulates, concentrates, and specific information on the dangers of such gaseous
anomalies. Different pollution levels can be communicated, and gases can be tracked as
they move throughout the city, either because of the wind or because of the movement of
gas sources.
From this pollution and environmental data and the analytics applied to it, the city can
track problem areas and take action in long-term urban planning to reduce the effects of
air quality disturbances. This action can take many forms, from increasing public transit
availability along the more polluted routes to encouraging the displacement of businesses
toward living areas to limit the need to commute daily.
With this pollution information, citizens can also take short term actions, such as
turning on their air purifiers at a given moment or simply stepping inside if pollutant
concentrations are becoming serious.
Strategic coordinated joint actions are also possible, such as restricting traffic along
certain routes or on certain days, and encouraging citizens to share vehicles or use the
public transportation system.
Module5 Page 21
INTERNET OF THINGS TECHNOLOGY 15CS81
A cellular modem could also be added for backhaul communications to the central
management software platform. However, this proprietary infrastructure was expensive
and had limited utility.
With the development of the Internet of Things (IoT), there’s now a much better way.
Point-to-point (P2P) cellular technology eliminates the need for proprietary gateways and
segment controllers.
A wireless cellular modem on each light pole can be configured to support low or high
data throughput, depending on the application.
A small antenna mounted on the pole enables direct communication to a central
management software platform, creating a single network and paving the way for the use
of advanced sensors and actuators that enable the deployment of other smart city
applications in the future.
Once light poles are connected to a central management software platform, regional and
municipal governments can use this new intelligent infrastructure as the foundation for
other smart city initiatives – all made more efficient and cost effective by taking advantage
of these existing assets.
For example, smart city public safety applications can use video surveillance cameras,
emergency call stations, and environmental monitoring stations (with sensors to detect
earthquakes, air quality, noise, etc.) strategically placed on light poles. Digital signage on
select street light poles can provide real-time information to drivers, pedestrians and
residents related to traffic, emergencies and local events, or be used to generate
advertising revenue for the city.
Connected street lighting also enables governments to use their street lights for Wi-Fi
access.
These access points can be used by city personnel to lower their cellular data usage,
reducing city expenses.
Wi-Fi access points can also be used to provide Internet access to local businesses and
residents, providing the city with a new sources of leasing or adverting revenues.
In addition, cities can use these Wi-Fi access points to help bridge the digital divide by
providing poorer city residents with free or low-cost Internet access.
Smart parking meters or pay stations attached or connected to light poles can eliminate
the costs associated with trenching for standalone meters and pay stations.
Electric vehicle (EV) charging stations can be equipped with payment processing that is
integrated with connected lighting in parking lots and near entertainment venues,
increasing access for EV drivers, encouraging more use of EVs, and generating additional
revenue for regional and municipal governments.
Alone, connected street lights using P2P cellular technology offer cities the opportunity
to make their city’s lighting more useful, less expensive, and smarter.
However, connected street lights can also accelerate deployment of Wi-Fi access
points, digital signage, connected parking meters, EV charging stations and other smart
city initiatives that allow cities to deliver their citizens a higher quality of life, while also
improving city finances.
Module5 Page 22
INTERNET OF THINGS TECHNOLOGY 15CS81
As they move forward in seeking to digitally transform themselves, regional and
municipal governments should first look at how the IoT enables a seemingly simple
technology – the street light – to serve as the foundation for their smart city initiatives.
Module5 Page 23
INTERNET OF THINGS TECHNOLOGY 15CS81
Efficient citywide parking space utilization — automated parking planners can
collect occupancy data for all parking venues thanks to a network of connected sensors.
To disperse the number of parked cars equally throughout the city, municipal
communities can adjust meter rates and allowed parking times using the data provided by
IoT platforms in the decision-making process.
Here are the features a smart platform in the parking industry should leverage
upon:
Interface showing free and occupied parking spaces — an IoT platform (ideally, a
cloud-based one) should aggregate sensor data and transform it into concise legible
insights regarding the occupancy of parking spaces in the facility.
Real-time monitoring of parking occupancy situation from any PC or
smartphone. A driver should be able to see how many free slots all parking facilities
around town offer in real time. An interactive occupancy map is a must-have for an
efficient, connected parking management tool.
API for end-user and management applications. Since the impact of parking
management tools is vital to the well-being of community members, program developers
need to ensure the tool offers third-party integrations and can be implemented into other
management and parking lot monitoring tools.
User-friendly interface, access permissions for different user groups. Not every
driver is tech-savvy and experienced in navigating complex platforms. To make the
process of finding or checking the availability of a parking lot as effortless as possible,
app developers should stick to a minimalist interface.
Module5 Page 24
INTERNET OF THINGS TECHNOLOGY 15CS81
Module5 Page 25