0% found this document useful (0 votes)
45 views36 pages

CSE 3009 Internet of Things FALL 20-21: Dr. M.Sudha Associate Professor School of Information Technology & Engineering

This document provides an overview of the content that will be covered in Module 3 of the CSE 3009 Internet of Things course at [University name redacted]. The module will focus on Arduino programming terminology, digital and analog input/output, variables, functions, control structures, and built-in functions. It lists required textbooks and provides examples of Arduino code and explanations of concepts like pin modes, timing functions, and variable data types.

Uploaded by

ayushthegreat123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views36 pages

CSE 3009 Internet of Things FALL 20-21: Dr. M.Sudha Associate Professor School of Information Technology & Engineering

This document provides an overview of the content that will be covered in Module 3 of the CSE 3009 Internet of Things course at [University name redacted]. The module will focus on Arduino programming terminology, digital and analog input/output, variables, functions, control structures, and built-in functions. It lists required textbooks and provides examples of Arduino code and explanations of concepts like pin modes, timing functions, and variable data types.

Uploaded by

ayushthegreat123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

CSE 3009 Internet of Things

FALL 20-21

Module 3

Dr. M.Sudha
Associate Professor
School of Information technology & Engineering

Content Source : Arshdeep Bahga and Vijay Madisetti, Internet of Things A Hand-on Approach, Universities press, 2015
Text Books :
1. Dieter Uckelmann et.al, Architecting the Internet of Things, Springer, 2011
2. Arshdeep Bahga and Vijay Madisetti, Internet of Things A Hand-on Approach, Universities press, 2015
Arduino programming -Terminology
• Sketch
– A program you write to run on an Arduino board
• Pin
– An input or output connected to something
• Eg: output to an LED, input from a knob
• Digital
– Value is either HIGH or LOW
• Aka on/off, one/zero
• Eg: switch state
• Analog
– Values ranges, usually from 0-255
• Eg: LED brightness, motor speed, etc.,
Digital I/0
• pinMode(pin, mode)
– Sets pin to either INPUT or OUTPUT
• digitalRead(pin)
– Reads HIGH or LOW from a pin
• digitalWrite(pin, value)
– Writes HIGH or LOW to a pin
• Electronic stuff
– Output pins can provide 40 mA of current
– Writing HIGH to an input pin installs a 20KΩ pullup
Arduino Timing
• delay(ms)
– Pauses for a few milliseconds
• delayMicroseconds(us)
– Pauses for a few microseconds
• More commands:
arduino.cc/en/Reference/HomePage
Digital? Analog?
• Digital has two values: on and off
• Analog has many (infinite) values
• Computers don’t really do analog, they quantize
• Remember the 6 analog input pins---here’s how
they work
Variables
Putting It Together
• Complete the sketch
(program) below.
• What output will be
generated by this program?
• What if the schematic were
changed? 
Structure
– Variables
• setup()
• loop()
– User Defined functions
setup()
• The setup() function is called when a sketch starts.
• Use it to
– initialize variables,
– pin modes, \
– start using libraries, etc.
• The setup function will only run once, after each
powerup or reset of the Arduino board.
loop()
• After creating a setup() function, which initializes
and sets the initial values,
• the loop() function loops consecutively
• Use it to actively control the Arduino board.
Control Structures
• if
• if...else
• for
• switch case
• while
• do... while
• break
• continue
• return
• goto
Further Syntax
• ; (semicolon)
• {} (curly braces)
• // (single line comment)
• /* */ (multi-line comment)
• #define
• #include
Operators
• Arithmetic Operators
= (assignment operator), + (addition), - (subtraction), *
(multiplication), / (division), % (modulo)
• Comparison Operators
== (equal to), != (not equal to), < (less than), > (greater
than), <= (less than or equal to), >= (greater than or equal
to)
• Boolean Operators
– && (and), || (or), ! (not)
• Pointer Access Operators
• Bitwise Operators
• Compound Operators
Operators
• Pointer Access Operators
* dereference operator, & reference operator
• Bitwise Operators
& (bitwise and), | (bitwise or), ^ (bitwise xor), ~ (bitwise
not), << (bitshift left), >> (bitshift right)
• Compound Operators
++ (increment), -- (decrement), += (compound addition)
-= (compound subtraction), *= (compound multiplication)
/= (compound division), %= (compound modulo), &=
(compound bitwise and), |= (compound bitwise or)
Variables
• Constants
• Data Types
• Conversion
• Variable Scope & Qualifiers
• Utilities
Variables: Constants
• HIGH | LOW
• INPUT | OUTPUT | INPUT_PULLUP
• LED_BUILTIN
• true | false
• integer constants
• floating point constants
Variables: Constants: High/Low
• In reference to a pin , whether a pin is set to
an INPUT or OUTPUT.
– When a pin is configured as an
• INPUT with pinMode(), and read with digitalRead(),
the Arduino will report HIGH/Low if:
– 5V boards
» greater than 3.0V is present at the pin; (High)
» less than 1.5V is present at the pin (Low)
– 3.3 V boards
» greater than 2.0V is present at the pin; High
» less than 1.0V (Approx) Low
Variables: Constants: High/Low
• In reference to a pin , whether a pin is set to
an INPUT or OUTPUT.
– When a pin is configured as an
• OUTPUT with pinMode(), and set to HIGH with
digitalWrite(), the pin is at:
– 5 volts (5V boards);, 3.3 volts (3.3V boards)
• OUTPUT with pinMode(), and set to Low with
digitalWrite(), the pin is at:
– the pin is at 0 volts (both 5V and 3.3V boards).
– In this state it can sink current,
– e.g. light an LED that is connected through a series resistor
to +5 volts (or +3.3 volts).
Functions
• Segmenting code into functions allows a
programmer to create modular pieces of code that
perform a defined task
• Standardizing code fragments into functions has
several advantages
– Help the programmer stay organized.
– only has to be thought out and debugged once.
– reduces chances for errors in modification, if the code
needs to be changed.
– sections of code are reused many times. And by making
it more modular, and as a nice side effect, using
functions also often makes the code more readable.
Anatomy of a C function
Sample Program
Builtin Functions
• Digital I/O
• Analog I/O
• Due & Zero only
• Advanced I/O
• Time
• Math
• Trigonometry
• Characters
• Random Numbers
• Bits and Bytes
• External Interrupts
• Interrupts
• Communication
• USB (32u4 based boards and Due/Zero only)
What is Arduino?
• Arduino is an open-source platform used for building
electronics projects.
• Arduino consists of both a physical programmable circuit
board (often referred to as a microcontroller) and a piece
of software, or IDE (Integrated Development Environment)
that runs on your computer, used to write and upload
computer code to the physical board.
• The Arduino platform has become quite popular with
people just starting out with electronics
• Arduino does not need a separate piece of hardware (called a
programmer) in order to load new code onto the board
• It can be used simply using a USB cable Additionally, the
Arduino IDE uses a simplified version of C++, making it easier to
learn to program.
• Finally, Arduino provides a standard form factor that breaks out
the functions of the micro-controller into a more accessible
package.
This is an Arduino Uno
• The Uno is one of the more popular boards in the Arduino
family and a great choice for beginners.
Arduino Uno, what it does?
• The Arduino hardware and software was designed for artists, designers, hobbyists,
hackers, and anyone interested in creating interactive objects or environments.
• Arduino can interact with buttons, LEDs, motors, speakers, GPS units, cameras, the
internet, and even your smart-phone or your TV!
• This flexibility combined with the fact that the Arduino software is free, the hardware
boards are pretty cheap, and both the software and hardware are easy to learn has
led to a large community of users who have contributed code and released
instructions for a huge variety of Arduino-based projects.
• For everything from robots and a heating pad hand warming blanket to 
honest fortune-telling machines, and even a 
Dungeons and Dragons dice-throwing gauntlet, the Arduino can be used as the brains
behind almost any electronics project.
Arduino characteristics
1. Inexpensive - Arduino boards are relatively inexpensive compared to other
microcontroller platforms. The least expensive version of the Arduino module can
be assembled by hand, and even the pre-assembled Arduino modules cost less than
$50
2. Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and
Linux operating systems. Most microcontroller systems are limited to Windows.
3. Simple, clear programming environment - The Arduino Software (IDE) is easy-to-
use for beginners, yet flexible enough for advanced users to take advantage of as
well. For teachers, it's conveniently based on the Processing programming
environment, so students learning to program in that environment will be familiar
with how the Arduino IDE works.
• Open source and extensible software - The Arduino software is published as
open source tools, available for extension by experienced programmers. The
language can be expanded through C++ libraries, and people wanting to
understand the technical details can make the leap from Arduino to the AVR C
programming language on which it's based. Similarly, you can add AVR-C code
directly into your Arduino programs if you want to.
• Open source and extensible hardware - The plans of the Arduino boards are
published under a Creative Commons license, so experienced circuit designers
can make their own version of the module, extending it and improving it. Even
relatively inexperienced users can build the breadboard version of the module in
order to understand how it works and save money.
Arduino Sensors , shields
• With some simple code, the Arduino can control and interact with a wide
variety of Sensors - things that can measure light, temperature, 
degree of flex, pressure, proximity, acceleration,  radioactivity, humidity, 
barometric pressure, you name it, you can sense it!
• Shields
• Additionally, there are these things called shields -- basically they are pre-
built circuit boards that fit on top of your Arduino and provide additional
capabilities -- controlling motors, connecting to the internet, 
providing cellular or other wireless communication, 
controlling an LCD screen, and much more.
Why Arduino is used in IoT?

• Arduino acts as the brain of the system and processes the data


from the sensor. Also IDE software
is needed for Arduino based IoT projects. And you need
to use ESP-8266 WiFi module to establish the WiFi
communication between the Arduino and cloud platform.
What is difference between Raspberry Pi and Arduino?

• The main difference between them is Arduino is


microcontroller board while raspberry pi is a mini computer.
Thus Arduino is just a part of raspberry pi. 
• Raspberry Pi is good at software applications,
while Arduino makes hardware projects simple.
Details
• These two boards run on very low power. But power interruption for raspberry pi may cause damage to the software and
applications. In case of Arduino if there is any power cut it again restarts. So raspberry pi must be properly shutdown before
disconnecting power.
• Raspberry Pi comes with the fully functional operating system called Raspbian. It has all features of a computer with a processor,
memory and graphics driver. Pi can use different operating systems. Although Linux is preferred android can also be
installed.Arduino does not have any operating system. Its firmware simply interprets the code written to it. It is very easy to execute
simple code.
• Input and output pins allow these boards to connect to other devices. Raspberry pi2 has 2 packs of input/output pins while Arduino
Uno has 20 pins.
• Pi is faster than Arduino by 40 times in clock speed.Pi has ram 128000 times more than Arduino.So Raspberry Pi is
more powerful than Arduino.
• Arduino has 32kb of storage on board.This is used for storing the code.This code decides the functions of the Arduino.Raspberry pi
does not have any onboard storage.But it provides micro SD port.
• Arduino can be expanded using external hardware like Wi-Fi, Ethernet, touchscreens, cameras etc. These boards are called shields.
These shields are easily installed for Arduino. While raspberry is self-constrained board.Pi can also add some hats to add hardware
like Touchscreen, GPS, RGB panels etc. but does not have many options like Arduino board has.
• Arduino uses Arduino IDE for developing the code. While Raspberry Pi can use Scratch, IDLE anything that supports Linux.
How to decide between Raspberry Pi and Arduino
• From above discussion we can understand that Arduino is good for repetitive
tasks such as opening the garage door, switching the lights on and off.
• While pi good for performing multiple tasks, driving complicated robots.
• For example, if you want to monitor the soil moisture and mail me if it is
necessary to water the plants.
• For this application, arduino can be used.But if you want to monitor the moisture,
mail me when the plants need to be watered and check the weather report from
online.If there is rain do nothing. For this application Raspberry pi required.
• In simple Arduino is used for beginners projects and some complicated projects
can be easily handled by pi.

You might also like