Вы находитесь на странице: 1из 92

{ Arduino

IoT? Smart Things?

{
Embedding - SCAC

Sensing Computing Actuation Communication


 Includes everything from fitness bands to industrial equipment
and infrastructures for smart cities
 Edge nodes use a familiar set of building blocks – a
combination of embedded processing, connectivity, security,
sensing, and software.
 Edge nodes are a natural evolution of embedded computing,
with connectivity to the cloud representing the next step in the
evolutionary ladder.
 The right levels of performance, scalability, compatibility, and
energy efficiency.

Edge Nodes with a


Competitive Edge
Design Prototype Refine

Feedback & Evaluation


 Broad family
 PicoPower Technology
 High integration
 Analog functions
 Rapid development
 IoT Ready

megaAVR
Microcontrollers
 The acronym AVR has been reported to stand
for: Advanced Virtual RISC and also for the
chip's designers: Alf-Egil Bogen and Vegard
Wollan who designed the basic architecture at the
Norwegian Institute of Technology.
 RISC stands for reduced instruction set
computer.

What does AVR RISC mean?


 True single cycle execution
→ single-clock-cycle-per-instruction
execution
 One MIPS (mega instructions per second) per MHz
→ up to 20 MHz clock
 32 general purpose registers
→ provide flexibility and performance when using
high level languages
→ prevents access to RAM
 Harvard architecture
→ separate bus for program and data memory

AVR 8-Bit RISC High


Performance
AVR® Flash microcontrollers share a single
core architecture
→ use the same code for all families
→ 1 Kbytes to 256 Kbytes of code
→8 to 100 pins
→ all devices have Internal oscillators

AVR 8-Bit RISC


Compatibility
 1.8 to 5.5V operation
→ will use all the energy stored in
your batteries

 A variety of sleep modes


→ AVR Flash microcontrollers have
up to six different sleep modes
→ fast wake-up from sleep modes

 Software controlled frequency

Low Power Consumption


Off-the-shelf
hardware development boards
Wiring is an open-source programming framework for microcontrollers.
Wiring allows writing cross-platform software to control devices attached
to a wide range of microcontroller boards to create all kinds of creative
coding, interactive objects, spaces or physical experiences. The framework
is thoughtfully created with designers and artists in mind to encourage a
community where beginners through experts from around the world share
ideas, knowledge and their collective experience
 Processing is a flexible software sketchbook and a language for
learning how to code within the context of the visual arts
Arduino is an open-source electronics
platform based on easy-to-use hardware
and software. It's intended for anyone

Arduino making interactive projects.

https://www.arduino.cc/
 An inexpensive and all-included solution
 A cross-platform tool chain running on
Windows, OS X, and Linux
 A very easy high-level C language and library
that can also tweak the low-level bits and
 A totally extensible open source framework

Hardware Prototyping as easy


as Software Prototyping
Programming Languages
for Embedded Systems
 It is a modern structured language that has been
standardized (ANSI).
 It is modular, allowing reuse of code.
 It is widely supported, allowing source code to be used
for several different platforms by just recompiling for
the new target.
 Its popularity means that several third-party add-ons
(libraries and modules) are available to “stretch” the
language.
 It has type checking which helps catch errors.
 It is very powerful, allowing you to get “close to the
metal”.
 Generally, it creates very efficient code (small space and
fast execution).

Why C?
 C++ is a superset of C.
 C++ literally means “increment C”, or perhaps “give
me the next C”.
 C++ does everything C does plus a whole lot more.
These extra features don’t come free and embedded
applications usually cannot afford the overhead.

C or C++
 Assembly has traditionally been used when
code space and speed are of utmost
importance. Years ago, virtually all embedded
work was done in assembly.
 Assembly is processor-specific, unstructured,
not standardized, nor particularly easy to read
or write.
 C now offers similar performance
characteristics to assembly but with all the
advantages of a modern structured language

How does C compare with assembly


language?
C + OOP
Class--ification

assignGrade(Grade)

Student Name Roll No. Contact No. Grade


Std0 Neelam 001 9826091280 A
Std1 Sameer 002 9929900991 F
admitStd (Name, Roll
No., Contact No.) Std2 Jitendra 003 9401122550 C

getStdDetails ( )
 https://arduino.googlecode.com/svn/trunk/libraries/
LiquidCrystal/LiquidCrystal.cpp

 LiquidCrystal
Class for manipulating LCD displays
 print()
Writes an int, float, byte, char, char[] or a number in
decimal, hexadecimal, octal or binary base to the
display.
 clear()
Clears the display screen.
 home()
Sets the display cursor at the beginning of the
screen.
 setCursor()
Moves the cursor to a specific column, row position.

Arduino is a language of methods


 A variable is a memory storage location
bounded to a symbolic name (Identifier). This
reserved memory area can be filled or left
empty. Basically, it is used to store different
types of values.

What is a variable ?
 Type Definition Size in memory
 void- This particular type is used only in
function declarations and while defining
pointers with unknown types.
 Boolean - It stores false or true.
 char - It stores single-quoted characters such as
'a' as numbers, following the ASCII chart It is a
signed type and stores numbers from -128 to
127; it can be unsigned and then stores
numbers from 0 to 255.

Data Types
 byte - It stores numbers as 8-bit unsigned data that means from 0
to 255.
 int -It stores numbers as 2-bytes signed data which means from -
32,768 to 32,767 it can also be unsigned and then store numbers
from 0 to 65,535.
 Word- It stores numbers as 2-bytes unsigned data exactly as
unsigned int does.
 long - It stores numbers as 4-bytes signed data, which means from
-2,147,483,648 to 2,147,483,647 and can be unsigned and then
stores numbers from 0 to 4,294,967,295.
 float - It basically stores numbers with a decimal point from -
3.4028235E + 38 to 3.4028235E + 38 as 4-bytes signed data.
 Double - It generally stores float values with a precision two
times greater than the float value.
 string - It stores text strings in an array of char where the last
element is null that is a particular character (ASCII code 0).

Contd
 Qualifiers are the keywords that are used to
change the processor's behavior considering
the qualified variable.

static, volatile, and const qualifiers


 The static qualifier makes the variable persistent
between two calls of the function.

int myGlobalVariable;

void setup()
{}

void loop()
{
myFunction(digitalPinValue);
}

void myFunction(argument)
{
int aLocalVariable;
aLocalVariable = aLocalVariable + argument;

Static }
 The volatile qualifier in a variable declaration
statement makes the variable to be loaded from
the RAM instead of the storage register
memory space of the board.
 Loading the variable from the RAM prevents
some possible inconsistencies of variable value.

Volatile
 The const qualifier means constant.
Qualifying a variable with const
makes it unvariable

const int Channel = 10;

This is equivalent to:


#define Channel 10

const
Operators
Arduino Interfacing
void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Bare Minimum
Life of Arduino
Blinking LED
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Sketch
Interfacing Switch
const int buttonPin = 2;
const int ledPin = 13;

int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);

if (buttonState == LOW) {
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}

Sketch
Usually for robotics application Permanent magnet DC motors (PMDC)
are generally used. PMDC motors have magnets as stator (stationary
part) and windings as the rotor (rotating part). We need to excite (give
supply) the rotor in order to make the motor to rotate.

DC Motors
int motor_forward = 7;
int motor_reverse = 6;
void setup() {
pinMode(motor_forward, OUTPUT);
pinMode(motor_reverse, OUTPUT);
}

void loop() {
digitalWrite(motor_forward,1); //terminal D1 will be HIGH
digitalWrite(motor_reverse,0); //terminal D2 will be LOW
delay(5000); //creates a 5 seconds delay
digitalWrite(motor_forward,0); //terminal D1 will be LOW
digitalWrite(motor_reverse,1); //terminal D2 will be HIGH
delay(5000); //creates a 5 seconds delay
digitalWrite(motor_forward,0); //terminal D1 will be LOW
digitalWrite(motor_reverse,0); //terminal D2 will be LOW
delay(5000); //creates a 5 seconds delay
}

Sketch
Interfacing IR Sensor
const int SPin = 2; // the number of the sensor pin
const int ledPin = 13; // the number of the LED pin
int SenosrState = 0;

void setup() { pinMode(ledPin, OUTPUT);


pinMode(SPin, INPUT);
}
void loop()
{
SensorState = digitalRead(SPin);

if (SensorState == HIGH)
digitalWrite(ledPin, LOW);
else
digitalWrite(ledPin, HIGH);
}

Sketch
Analog Input
int sensorPin = A0; // select the input pin for the
potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming
from the sensor
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from
the sensor:
digitalWrite(ledPin, HIGH); // turn the
ledPin on
delay(sensorValue); // stop the program for <sensorValue>
milliseconds
digitalWrite(ledPin, LOW); // turn the ledPin off:
delay(sensorValue); // stop the program for for <sensorValue>
milliseconds
}

Sketch
Analog Out
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
pinMode(led, OUTPUT);
}
void loop() {

analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
delay(30);
}

Sketch
 Libraries are a collection of code
that makes it easy for you to
connect to a sensor, display,
module, etc.
 For example, the built-
in LiquidCrystal library makes it
easy to talk to character LCD
displays. There are hundreds of
additional libraries available on
the Internet for download

Libraries
Function
This library allows an Arduino LiquidCrystal()
begin()
board to control Liquid Crystal clear()
displays (LCDs) based on the home()
Hitachi HD44780 (or a compatible) setCursor()
write()
chipset, which is found on most print()
text-based LCDs. The library works cursor()
with in either 4- or 8-bit mode (i.e. noCursor()
blink()
using 4 or 8 data lines in addition to noBlink()
the rs, enable, and, optionally, the display()
rw control lines). noDisplay()
scrollDisplayLeft()
scrollDisplayRight()
autoscroll()

LiquidCrystal noAutoscroll()
leftToRight()
rightToLeft()
createChar()
LCD
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2);
lcd.print("hello, world!");
}

void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}

Sketch
Functions
if (Serial)
available()
availableForWrite()
All Arduino boards have atleast begin()
one serial port (UART/USART) end()
find()
known as Serial used for findUntil()
communication between flush()
arduino board and a computer parseFloat()
or other devices. parseInt()
peek()
print()
println()
read()
readBytes()
readBytesUntil()

Serial readString()
readStringUntil()
setTimeout()
Communication write()
serialEvent()
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the
interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and
rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop() {
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {

Sketch }
// display each character to the LCD
lcd.write(Serial.read());
}
}
 Sensor - Arduino
 VCC – 5V
 Gnd – Gnd
 Trig – 13
 Echo - 11

Measuring distance using ultrasonic sensor


int trigPin=13; //Sensor Trig pin connected to Arduino pin 13
int echoPin=11; //Sensor Echo pin connected to Arduino pin 11
float pingTime; //time for ping to travel from sensor to target and return
float targetDistance; //Distance to Target in inches
float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees.

void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
digitalWrite(trigPin, LOW); //Set trigger pin low
delayMicroseconds(2000); //Let signal settle
digitalWrite(trigPin, HIGH); //Set trigPin high
delayMicroseconds(15); //Delay in high state
digitalWrite(trigPin, LOW); //ping has now been sent
delayMicroseconds(10); //Delay in low state

pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microceconds


pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds
in a second)
pingTime=pingTime/3600; //convert pingtime to hourse by dividing by 3600 (seconds in an hour)
targetDistance= speedOfSound * pingTime; //This will be in miles, since speed of sound was miles
per hour
targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you

Sketch must divide by 2 for actual target distance.


targetDistance= targetDistance*63360; //Convert miles to inches by multipling by 63360 (inches per
mile)

Serial.println(targetDistance);
delay(100); //delay tenth of a second to slow things down a little.
}
Wireless Communication
 IEEE 802 refers to a family of
IEEE standards dealing with
Local Area Networks and
Metropolitan Area Networks

IEEE 802 standards


http://www.raviyp.com/embedded/207-868-mhz-frequency-is-not-license-free-in-india-lora-in-india
Frequency Band: 865-867 MHz
Low power RFID equipments or any other low power wireless devices or equipments
Power: Maximum transmitter output power of 1 Watt ( 4 Watts Effective Radiated Power)Carrier Bandwidth: 200 KHz
Reference: GSR 564 ( E) dated 30 July 2008

Frequency Band: 2.4-2.4835 GHz


Use : Low power equipments
Power: Maximum transmitter output power of 1 Watt ( 4 Watts Effective Radiated Power)
Carrier Bandwidth: spectrum spread of 10 MHz or higher
Reference: GSR 45E dated 28.1.2005

Frequency Band: 5.150-5.350 GHz, 5.725 - 5875


Use : Low power equipments for Cellular telecom systems including Radio Local Area Networks, Indoor applications
Power: maximum mean Effective Isotropic Radiated Power of 200mW, maximum mean Effective Isotropic Radiated Power density of 10mW/MHz in any 1 MHz
bandwidth,
Carrier Bandwidth: 1MHz
Reference: GSR No 46E dated 28.1.2005

Frequency Band: 5.825 to 5.875 GHz


Use : Low power equipments
Power: maximum transmitter output power of 1 Watt ( 4 Watts Effective Radiated Power)Carrier Bandwidth: spectrum spread of 10 MHz or higher
Reference: GSR no 38E dated 19.1.2007

Frequency Band: 26.957-27.283 MHz


Use : Wireless equipments intended to be used while in motion or during halts
Power: maximum Effective Radiated Power ( ERP) of 5 Watts
Reference: GSR no 35 E dated 10.01.2007

Frequency Band: 335.7125, 335.7375,335.7625, 335.7875, 335.8125 and 335.8375MHz


Use : Low power equipments for the remote control of cranes
Power: maximum transmit power of 1mW
Carrier Bandwidth: 10 KHz
Reference: GSR 34( E) dated 10.1.2007 and GSR 532 ( E) dated 12.8.2005

List of License free frequencies in India for


Wireless usage
http://www.indiasemiconductorforum.com/wirelesss/321-list-licence-free-frequencies-india-wireless-usage.html
• Modulation type is GFSK/FHSS
• Peak data rate is about 1Mbps
• RF Bandwidth is 220KHz and 1MHz
• RF frequency band is 2.4 GHz
• No. of RF carriers are 23/79
• RF carrier spacing is 1 MHz
• 1600 hops/sec frequency hopping
• Time Division Duplex mode
• Transmit power is about 0.1 watt
• Distance coverage of up to 10m to 100m
• 7 simultaneous links possible in a star configuration (Piconet)

Bluetooth RF and baseband specifications


• Bluetooth Low Energy (LE) (also called
Bluetooth Smart or Version 4.0+ of the
Bluetooth specification) is the power-
and application-friendly version of
Bluetooth that was built for the Internet
of Things (IoT)

Bluetooth
Versions
 HC-05 module is an easy to use Bluetooth SPP (Serial Port Protocol)
module, designed for transparent wireless serial connection setup.
 Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR
(Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio
transceiver and baseband. It uses CSR Bluecore 04-External single chip
Bluetooth system with CMOS technology and with AFH(Adaptive
Frequency Hopping Feature). It has the footprint as small as
12.7mmx27mm. Hope it will simplify your overall
design/development cycle.

Bluetooth
 Bluetooth networks (commonly
referred to as piconets) use a
master/slave model to control
when and where devices can
send data. In this model, a single
master device can be connected
to up to seven different slave
devices. Any slave device in the
piconet can only be connected to
a single master.

Masters, Slaves, and Piconets


 Every single Bluetooth device has a unique 48-bit address, commonly
abbreviated BD_ADDR. This will usually be presented in the form of a
12-digit hexadecimal value. The most-significant half (24 bits) of the
address is an organization unique identifier (OUI), which identifies the
manufacturer. The lower 24-bits are the more unique part of the address.
 Bluetooth devices can also have user-friendly names given to them. They
can be up to 248 bytes long, and two devices can share the same name.
Sometimes the unique digits of the address might be included in the
name to help differentiate devices.

Bluetooth Addresses and Names


 When two Bluetooth devices share a special affinity for
each other, they can be bonded together. Bonded
devices automatically establish a
connection whenever they’re close enough.
 Bonds are created through one-time a process
called pairing. When devices pair up, they share their
addresses, names, and profiles, and usually store them
in memory. The also share a common secret key, which
allows them to bond whenever they’re together in the
future.
 Pairing usually requires an authentication
process where a user must validate the connection
between devices.
 pairing processes involve the entering of a common
PIN code on each device. The PIN code can range in
length and complexity from four numbers (e.g. “0000”
or “1234”) to a 16-character alphanumeric string.

Bonding and Pairing


 Bluetooth profiles are additional protocols
that build upon the basic Bluetooth
standard to more clearly define what kind
of data a Bluetooth module is transmitting.
While Bluetooth specifications define how
the technology works, profiles define how
it’s used.
 For two Bluetooth devices to be compatible,

they must support the same profiles.

Bluetooth Profiles
 Bluetooth’s original purpose was to replace RS232 cables
 SPP is great for sending bursts of data between two devices
 Using SPP, each connected device can send and receive data just as
if there were RX and TX lines connected between them.

Serial Port Profile (SPP)


Interfacing
int led =13;
char val;

void setup(){
Serial.begin(9600);
Serial1.begin(9600);
pinMode(led, OUTPUT);
}

void loop() {

if(Serial1.available()>0)
{
delay(100);
while(Serial1.available()>0)
val = Serial1.read();
Serial.println(val);
if (val == 'A')
digitalWrite(led, HIGH);
if(val == 'B')
digitalWrite(led, LOW);
if(val =='C')
{
digitalWrite(led, HIGH);

Sketch delay(3000);
digitalWrite(led, LOW);
}

}
}
 The ESP8266 is a low-cost Wi-Fi chip with full TCP/IP stack and
microcontroller capability produced by Shanghai-based Chinese
manufacturer, Espressif Systems
 32-bit RISC CPU: Tensilica Xtensa LX106 running at 80 MHz
 64 KiB of instruction RAM, 96 KiB of data RAM
 External QSPI flash - 512 KiB to 4 MiB (up to 16MiB is supported)
 IEEE 802.11 b/g/n Wi-Fi
 Integrated TR switch, balun, LNA, power amplifier and matching
network
 WEP or WPA/WPA2 authentication, or open networks
 16 GPIO pins
 SPI, I²C,
 I²S interfaces with DMA (sharing pins with GPIO)
 UART on dedicated pins, plus a transmit-only UART can be
enabled on GPIO2
 1 10-bit ADC

WiFi
 AT Command Processor (Default)
 NodeMCU - Lua interpreter onboard
 Custom Firmware (using the Arduino IDE)
 Espruino
 Micropython

Using ESP8266
http://arduino.esp8266.c
om/stable/package_esp8
266com_index.json

Вам также может понравиться