2. Outline of
the Talk
Introduction to IoT and Sensors
Introduction to Arduino
(Hardware and Programming)
Getting started with Arduino
(setup and basic programming for an IoT
hardware)
Arduino-based Demonstration
• Demo 1: Controlling an LED's Blink
• Demo-2: Controlling LED's fading
• Demo-3: Heart-rate computation
3. Introduction
• The evolution of communication technologies bring
Internet connection to devices at lower cost, less power
consumption and smaller sizes.
• As the results devices are able to be parts of the so called
Internet of Things (IoT).
• Arduino: flexible micro-controller and development
environment.
Used to control devices, and to read data from all kinds of
sensors.
Arduino is the best way to be introduced to the IoT
5. Internet of Things (IoT)
Computers, sensors and
actuators connected
through Internet
protocols
Measure or manipulate
physical properties
Imagine having small device connected that can sense temperature, smoke,
humidity, and light condition of your room and report them to a web services
6. IoT
A global network of smart
devices that can sense and
interact with their
environment using internet
for their communication
and interaction.
A network of Physical
Objects that can interact
with each other to share
information and take
Action.
8. IoT
device
Requirements common to all of IoT Device include
• Sensing and data collection capability (sensing
nodes)
• Layers of local embedded processing capability
(local embedded processing nodes)
• Wired and/or wireless communication
capability (connectivity nodes)
• Software to automate tasks and enable new classes
of services
• Remote network/cloud-based embedded
processing capability (remote embedded processing
nodes)
• Full security across the signal path
9. Feature of IoT
device
Thingspeak and Xively to store and use
sensor measurements
e.g. https://thingspeak.com/channels/9
10. Interaction with The Internet
• The ability to communicate directly or
indirectly with the internet make IoT device
different from other devices.
Why need to communicate with internet?
Sensors generate lot of data that need to be
managed.
Embedded memory is limited
Internet provide web application for data storage
which can be accessed anywhere or anytime.
Provide data exchanges between other applications.
11. Building Blocks of the IoT
• Control Units
• Sensors
• Communication Modules
• Power sources
12. Control Units
IoT device utilize microcontroller as the main
control unit
• A microcontroller: Is a small computer in a
single integrated circuit.
It contain a processor core, a memory, and
programmable I/O peripheral.
• MCU
The ‘brain’ controls everything
Reads input from sensors
Drives outputs
LED, Switch, Motor,…
13. Sensors: Integral part of an IoT device
• Device that can sense the physical quantities and
convert into signal which can be interpreted by the
MCU.
• Fall into two types
Analog and Digital Sensor
14. Arduino: A Computing Platform
• What is Arduino?
• An open-source physical computing platform based on
A simple microcontroller board and
A development environment for writing software for
the board.
• Used to develop stand-alone interactive objects
• It can be connected to a computer to retrieve or send
data to the Arduino.
The board can be assembled by hand or purchased
preassembled.
15. Arduino Platform
• Why Arduino used mostly
• It is inexpensive
• cross-platform (the Arduino software runs on Windows,
Mac OS X, and Linux), and
• easy to program.
• Both Arduino hardware and software are open source
and extensible
20. Note: Once it has been programmed, your board
can run on its own, without another computer
Getting started with Arduino
The IDE (Integrated Development Environment)
allows you to program your board, i.e. “make it
do something new”
You edit a program on your computer, then
upload it to your board where it’s stored in the
program memory (flash) and executed in RAM
21. Measuring and manipulating
IoT hardware has an interface to the real world
GPIO (General Purpose Input/Output) pins
Measure: read sensor value from input pin
Manipulate: write actuator value to output pin
Inputs and outputs can be digital or analog
22. Getting started with Arduino
To install the Arduino IDE and connect your
Arduino board to your computer via USB, see
http://arduino.cc/en/Guide/MacOSX or
http://arduino.cc/en/Guide/Windows or
http://arduino.cc/playground/Learning/Linux
24. Bare
minimum
code
setup : It is called only when
the Arduino is powered on or
reset. It is used to initialize
variables and pin modes
loop : The loop functions runs
continuously till the device is
powered off. The main logic of
the code goes here. Similar to
while (1) for micro-controller
programming.
25. PinMode
• A pin on arduino can be set as input
or output by using pinMode
function.
• pinMode(13, OUTPUT); // sets pin
13 as output pin
• pinMode(13, INPUT); // sets pin 13
as input pin
26. Reading/writing
digital values
• digitalWrite(13, LOW); //
Makes the output voltage
on pin 13 , 0V
• digitalWrite(13, HIGH); //
Makes the output voltage
on pin 13 , 5V
• int buttonState = digitalRea
d(2); // reads the value of
pin 2 in buttonState
29. The LED
The LED (Light Emitting Diode)
is a simple, digital actuator
LEDs have a short leg (-) and a long leg (+)
and it matters how they are oriented in a circuit
To prevent damage, LEDs are used together with
a 1KΩ resistor (or anything from 300Ω to 2KΩ)
+ -
+ -
Anode Cathode
30. The breadboard
A breadboard lets you wire electronic
components without any soldering
Its holes are connected
“under the hood” as
shown here
31. Wiring a LED with Arduino
The long leg of the
LED is connected to
pin 13, the short leg
to ground (GND)
Note: the additional
1K Ω resistor should
be used to prevent
damage to the pins /
LED if it’s reversed
The Ethernet Shield
is not needed here
+
32. HIGH = digital 1 (5V)
means LED is on,
LOW = digital 0 (0V)
means LED is off
Set ledPin as wired
in your LED circuit
Digital output with Arduino
int ledPin = 13;
void setup () {
pinMode(ledPin, OUTPUT);
}
void loop () {
digitalWrite(ledPin, HIGH);
delay(500); // wait 500ms
digitalWrite(ledPin, LOW);
delay(500);
}
Note: blinking a LED
is the Hello World of
embedded software
33. A few simple challenges
Let’s make LED#13 blink!
• Challenge 1a – blink with a 200 ms second
interval.
• Challenge 1b – blink to mimic a heartbeat
• Challenge 1c – find the fastest blink that the
human eye can still detect…
• 1 ms delay? 2 ms delay? 3 ms
delay???
35. Fading in and Fading Out
(Analog or Digital?)
• A few pins on the Arduino allow for us to
modify the output to mimic an analog signal.
• This is done by a technique called:
• Pulse Width Modulation (PWM)
36. Arduino Programming: LED Fading
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 25; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
37. Demo# 2 – Fading challenge
• Challenge 2a – Change the rate of the fading
in and out. There are at least two different
ways to do this – can you figure them out?
• Challenge 2b – Use 2 (or more) LEDs – so that
one fades in as the other one fades out.
40. A switch is a simple, digital sensor
Switches come in different forms, but all of them
in some way open or close a gap in a wire
The pushbutton switch has four legs for easier
mounting, but only two of them are needed
Note: you can also easily build your own switches,
for inspiration see e.g. http://vimeo.com/2286673
The switch
41. Wiring a switch with Arduino
Pushbutton switch
10K Ω resistor
5V
GND
D2 (max input 5V!)
Note: the resistor in
this setup is called
pull-down ‘cause it
pulls the pin voltage
down to GND (0V) if
the switch is open
42. Digital input with Arduino
int sensorPin = 2; // e.g. button switch
void setup () {
Serial.begin(9600); // setup log
pinMode(sensorPin, INPUT);
}
void loop () {
int sensorValue = digitalRead(sensorPin);
Serial.println(sensorValue); // log 0 or 1
}
Or run Arduino IDE
> File > Examples >
Digital > Button for
an example of how
to switch an LED
Open the Arduino
IDE serial monitor
to see log output
43. Photoresistor (LDR)
A photoresistor or LDR
(light dependent resistor) is
a resistor whose resistance
depends on light intensity
An LDR can be used as a simple, analog sensor
The orientation of an LDR does not matter
44. Wiring an LDR with Arduino
Photoresistor (LDR)
10K Ω resistor
5V
GND
A0
Note: this setup is a
voltage-divider, as
the 5V total voltage
is divided between
LDR and resistor to
keep 0V < A0 < 2.5V
45. int sensorPin = A0; // e.g. LDR
void setup () {
Serial.begin(9600); // setup log
}
void loop () {
int sensorValue = analogRead(sensorPin);
Serial.println(sensorValue); // log value
}
Analog input with Arduino
Open the Arduino
IDE serial monitor
to see log output
Note: use e.g. Excel to visualize values over time
47. Driving Motors or other High
Current Loads
• NPN Transistor (Common Emitter “Amplifier” Circuit)
to Digital
Pin 9
48. Connecting to the Internet
Ethernet (built-in or shield), plug it in anywhere
Wi-Fi (module), configured once per location
3G (module), configured once, easy to use
Bluetooth/BLE (module), via 3G/Wi-Fi of phone
ZigBee (module), via ZigBee gateway
USB (built-in), via desktop computer
49. Wiring CC3000 Wi-Fi with Arduino
CC3000 VIN to 5V
GND to GND
CLK to D13, MISO to
D12, MOSI to D11,
CS to D10, VBEN to
D5, IRQ to D3
Note: make sure to
use a reliable power
source, e.g. plug the
Arduino via USB or
use a LiPo battery
http://androidcontrol.blogspot.com/2015/05/arduino-wifi-control-with-esp8266-
module.html
50. Note: open the serial monitor window to see the log
http://learn.adafruit.com/adafruit-cc3000-wifi/c
c3000-library-software
File > Examples > Adafruit_CC3000 > WebClient
#define WLAN_SSID "..." // set your network
#define WLAN_PASS "..." // set your password
Using CC3000 Wi-Fi with Arduino
51. Note: please ask for assistance to get a unique address
Add an Ethernet shield to the Arduino, plug it in
File > Examples > Ethernet > WebClient
byte mac[] = { ... }; // set a unique MAC address
IPAddress ip(...); // set a local, unique IP address
Using Ethernet with Arduino
52. Monitoring sensors
Devices read (and cache) sensor data
Devices push data to a service with POST, PUT
Some services pull data from devices with GET
Service stores measurements, to be consumed
by humans or computers (incl. other devices)
#1: Arduino
Gadgeteer
Beagle Bone
…
Aim:
require no previous experience
(because almost nobody understands IoT end-to-end)
use simple language
be resourceful
provide links for further reading
#2: Themen dieses Workshops
Erste Schritte
(Einrichten und programmieren von IoT Hardware)
Messen und Manipulieren
(Physical Computing: Sensoren und Aktuatoren)
Verbinden von Geräten mit dem Internet
(IoT: Sensoren überwachen, Aktuatoren fernsteuern)
Mash-ups mit Internet-verbundenen Geräten
(zusammen, falls genug Zeit bleibt)
Wie das Internet funktioniert
#5: Das Internet der Dinge entsteht, wenn Internet-verbundene Computer mit Sensoren und Aktuatoren ausgestattet werden. Statt virtuelle Ressourcen, wie bisher im Web, werden damit physikalische Eigenschaften gemessen und manipuliert.
#20: Erste Schritte
Die Entwicklungsumgebung erlaubt es ein Board zu programmieren, d.h. "dem Gerät etwas neues beizubringen"
Man editiert ein Programm auf dem Computer, lädt das Programm auf das Board. Dort wird es im Programmspeicher (Flash) abgelegt und im RAM ausgeführt.
Bemerkung: Wenn es einmal programmiert ist, funktioniert das Board allein, ohne den Desktop-Computer.
#21: Messen und manipulieren
IoT Hardware hat immer eine Schnittstelle zur Realität
GPIO (General Purpose Input/Output) Pins
Messen: Sensor-Messwert vom Input-Pin lesen
Manipulieren: Aktuator Sollwert auf einen Output-Pin schreiben
Inputs und Outputs önnen digital oder analog sein
#22: Erste Schritte mit Arduino
Um die Entwicklungsumgebung zu installieren und das Arduino Board mit dem Computer zu verbinden, siehe die folgenden Links.
#29: Die LED
Eine LED (Leuchtdiode) ist ein einfacher digitaler Aktuator.
LEDs habe ein kurzes Bein (-) und ein langes (+) und es kommt drauf an, wie eine LED in die Schaltung eingebaut wird.
Um Schäden an der LED zu verhindern, wird ein Widerstand vorgeschaltet (irgendwas zwischen 300 Ohm und 2 Kilo-Ohm).
#30: Das Breadboard
Ein Breadboard erlaubt es elektronische Komponenten ohne Löten zusammenzustecken
Die Löcher sind unterirdisch durch Metall verbunden, wie hier angedeutet
#31: Verdrahten einer LED mit Arduino
Bemerkung: der zusätzliche 1K Ohm Widerstand sollte benutzt werden um Schäden an Pins / LED zu vermeiden, falls sie verkehrt eingesteckt wird.
Das längere Bein der LED ist mit Pin 13 verbunden, das kürzere mit Erde, oder Ground (GND)
Der Ethernet shield wird hier nicht benötigt
#32: Digitaler Output mit Arduino
Bemerkung: die blinkende LED ist das "Hello World" Programm der embedded Sofware
Der LED Pin sollte entsprechend der Verdrahtung gesetzt werden, in der Schaltung
HIGH bedeutet die LED ist an, LOW bedeutet die LED ist aus.
#40: Der Schalter
Ein Schalter ist ein einfacher, digitaler Sensor
Schalter gibt es in verschiedenen Formen, aber alle davon öffnen und schliessen eine Lücke in einem Kabel.
Der Druckknopf hat vier Beine um die Montage zu vereinfachen, aber nur zwei davon werden benötigt
Bemerkung: Schalter kann man auch einfach selber bauen, siehe z.B. diesen Link.
#41: Schalter Verkabeln mit Arduino
Bemerkung: der Widerstand hier wird auch pull-down Widerstand genannt, weil er die Pin Spannung auf Ground (0V) runterzieht, wenn der Schalter offen ist.
#42: Digitaler Input mit Arduino
Das Serial Monitor Fenster in der Arduino Entwicklungsumgebung zeigt den Log Output an
Für ein Beispiel das eine LED ein- und ausschaltet, siehe Datei > Beispiele > Digital > Button
#43: Fotowiderstand
Ein Fotowiderstand (LDR, Licht-abhängiger Widerstand) ist ein Widerstand dessen Wert von der einfallenden Lichtstärke abhängt
Ein Fotowiderstand kann als einfacher analoger Sensor benutzt werden
Die Orientierung eines LDR in der Schaltung ist egal
#44: LDR verkabeln mit Arduino
Bemerkung: diese Schaltung heisst auch Spannungsteiler, weil die 5V Spannung zwischen dem LDR und einem Widerstanf aufgeteilt werden, damit A0 zwischen 0 und 2.5V bleibt
#45: Analoger Input mit Arduino
Das Serial Monitor Fenster in der Arduino Entwicklungsumgebung zeigt den Log Output an
Bemerkung: eine Reihe von Messwerten kann z.B. mit Excel einfach visualisiert werden
#48: Verbinden mit dem Internet
Ethernet (eingebaut oder als Shield), überall einfach einstecken
Wi-Fi (Modul), muss einmal pro Location konfiguriert werden
3G (Modul), muss ein einziges mal konfiguriert werden, einfach zu benutzen
Bluetooth / Bluetooth Low Energy (BLE), via 3G oder Wi-Fi eines Smartphones
ZigBee (Modul), via ZigBee Gateway
USB (eingebaut), via Dekstop Computer
Bemerkung: In diesem Workshop fokussieren wir auf Ethernet und Wi-Fi
#49: Verkabeln von CC3000 Wi-Fi mit Arduino
Bemerkung: sicherstellen, dass eine zuverlässige Stromquelle benutzt wird, z.B. via USB oder mit einem LiPo Akku
#50: Benutzung des CC3000 Wi-Fi mit Arduino
Bemerkung: Das Serial Monitor Fenster in der Arduino Entwicklungsumgebung zeigt den Log Output an
>>
http://learn.adafruit.com/adafruit-cc3000-wifi/cc3000-library-software
http://learn.adafruit.com/adafruit-cc3000-wifi/buildtest
http://learn.adafruit.com/adafruit-cc3000-wifi/webclient
#51: Benutzung von Ethernet mit Arduino
Ethernet-Shield auf den Arduino stecken
Datei > Beispiele > Ethernet > WebClient
Bemerkung: Bitte uns fragen um eine MAC und IP Adresse zu bekommen
>>
http://learn.adafruit.com/adafruit-cc3000-wifi/cc3000-library-software
http://learn.adafruit.com/adafruit-cc3000-wifi/buildtest
http://learn.adafruit.com/adafruit-cc3000-wifi/webclient
#52: Sensoren überwachen
Gerät liest und speichert Sensor Daten
Gerät pusht Daten auf eine online Platform mit POST, PUT
Manche Services pullen (ziehen) Daten vom Gerät mit GET
Platformspeichert Messwerte, die dann von Menschen oder anderen Computern (inkl. embedded Geräten) konsumiert werden
>>
Cosm: Supports push and pull, stores and renders content, knows format
Twitter: Push only, doesn’t know anything about content format of Tweet