Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Technische Universität MünchenLehrstuhl für Geoinformatik
Geoinformatics III – Geo Sensor Web
Introduction to IoT: Microcontrollers, Sensors, Actuators
Prof. Dr. Thomas H. Kolbe
Chair of Geoinformatics
Technische Universität München
27th of April 2020
Realtime Sensor Observation Service
Technische Universität MünchenLehrstuhl für Geoinformatik
Terms of Use
► The material provided is intended exclusively for use for the
course and its participants in the named semester.
► Any material provided may not be passed on to third parties
without the written permission of the lecturer.
● Excluded are, of cause, embedded hyperlinks to publicly accessible
websites or the TUM library.
► A publication or transfer to internet services or learning
platforms is also strictly prohibited.
► Students are not permitted to record lectures. The reasons for
this are a) examination law, b) copyright law, c) the personal
rights and data protection law of the lecturer and the individual
participants.
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 2
Technische Universität MünchenLehrstuhl für Geoinformatik
‘Internet Of Things‘ is when
your toaster mines bitcoins
to pay off its gambling debts
to the fridge
Source: Internet / Twitter
Image: Lidl
Technische Universität MünchenLehrstuhl für Geoinformatik
IoT – Application Fields
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 5
Figure: Patel & Patel 2016: Internet of Things-IOT: Definition, Characteristics, Architecture, Enabling Technologies, Application & Future
Challenges. Int. Journal of Engineering Science and Computing, May 2016
Technische Universität MünchenLehrstuhl für Geoinformatik
Accessing Sensors / Actuators over the Internet
…comprises the following steps or tiers:
1. Make sensors and actuators controllable by computers
● attach sensors & actuators to a microcontroller / microcomputer
2. Bring sensor data into the Internet / Make actuators
controllable over the Internet
● connect microcontrollers directly / indirectly to the Internet
3. Integration, storage, and analysis of sensor data collected
over distributed sensors / stations
● collect sensor data on software platforms; distribute sensor events
4. Access IoT devices (sensors, actuators) and their
acquired data from application programs over the Internet
● user applications retrieve and send data over the platform(s)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 8
Technische Universität MünchenLehrstuhl für Geoinformatik
Accessing Sensors / Actuators over the Internet
…comprises the following steps or tiers:
1. Make sensors and actuators controllable by computers
● attach sensors & actuators to a microcontroller / microcomputer
2. Bring sensor data into the Internet / Make actuators
controllable over the Internet
● connect microcontrollers directly / indirectly to the Internet
3. Integration, storage, and analysis of sensor data collected
over distributed sensors / stations
● collect sensor data on software platforms; distribute sensor events
4. Access IoT devices (sensors, actuators) and their
acquired data from application programs over the Internet
● user applications retrieve and send data over the platform(s)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 9
Today and
next week!
Technische Universität MünchenLehrstuhl für Geoinformatik
Structure of this Lecture
I. Microcontroller & Microcomputer
● Introduction & Overview
● Microcontroller Boards & Extension Boards
● Microcomputer & Extension Boards
II. Sensors
● Definition & Characteristics
● Examples for Sensors & Sensor Boards
III. Actuators & Indicators
● Definition
● Examples for Actuators & Indicator Boards; Dashboards
IV. Developing Microcontroller Systems
● Arduino Integrated Development Environment (IDE)
● Using the Hardware & Input/Output Pins of Arduino-type Microcontrollers
● Important Rules when connecting components
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 10
Technische Universität MünchenLehrstuhl für Geoinformatik
Requirements on Sensor Stations / Nodes
► Sensors need to be configured, controlled, and queried
● many modern sensors employ digital communication protocols
● sensor data readings often need additional calculations / treatments
(like temperature compensation or unit conversions) in order to
determine proper observation values
► Sensor data should be
● registered / stored locally at the station,
● displayed locally at the station, and/or
● transmitted to a remote server requires data encoding,
encryption, and the implementation of communication protocols
► Actuators need to be configured and controlled, too
► Thus, we need a controlling device
● typically realized by a microcontroller or a microcomputer
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 13
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontrollers (MC, MCU, 𝛍C)
► A microcontroller is an integrated circuit combining
● a microprocessor / central processing unit (CPU),
● working memory (RAM), program storage memory (ROM),
● peripheral functions like communication interfaces, and
● programmable external digital and analog input/output (I/O) lines
in a single package or an encapsulated module
► MCs are typ. programmed to implement a dedicated task
and are embedded into devices to control their functions
● for that purpose they are small, low cost, low power
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 14
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontrollers
► Important characteristics of Microcontrollers are
● Number of CPU cores
● Type of CPU instruction set (CISC vs. RISC)
● Clock frequency (typ. 8 MHz, 16 MHz, 48 MHz, or 240 MHz)
● Operating voltage (typ. 1.8V, 3.3V, or 5V)
● Power consumption and power saving modes
● Data bus width (typ. 8 bit, 16 bit, 32 bit, or 64 bit)
● Amount of working memory (RAM, typ. 2 KB up to 8 MB)
● Amount of program memory (Flash ROM, typ. 32 KB up to 8 MB)
● Amount of configuration memory (EEPROM, 0 Bytes up to 8 KB)
● Maximum addressable memory (address bus width)
● Type of memory architecture (von Neumann vs. Harvard)
● Number of General Purpose Input / Output (GPIO) lines
● Supported communication interfaces and protocols
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 15
Technische Universität MünchenLehrstuhl für Geoinformatik
Recapitulation: Bits and Bytes
► Bit
● smallest unit of digital data representation
● can be 0 or 1 (i.e. it can distinguish 2 possible values)
● 0 / 1 are typically represented by voltage levels (low / high)
► Byte
● one Byte consists of 8 Bits
● allows to represent 28 = 256 different combinations of 1’s and 0’s
● Byte has been the unit to represent alphanumeric characters, i.e.
single digits (0-9), letters (a-z, A-Z, äöüß), punctuation (;:,.-_/) etc.
● max. 256 different characters / symbols
● today, often 2 Bytes are being used to represent one character to
also cover international alphabets (216 = 65536 characters)
● multiple bytes: 1 Kilobyte (KB) = 1024 Bytes
1 Megabyte (MB) = 1024 KB = 1048576 Bytes
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 16
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for widely used Microcontrollers
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 17
Characteristics \ MC ATmega328 SAMD21 Cortex M0+ ESP32
Manufacturer Atmel / Microchip Atmel / Microchip Espressif Systems
Number of CPU cores 1 1 2
Data bus width 8 32 32
Max. clock frequency 20 MHz 48 MHz 240 MHz
RAM 2 KB 32 KB 520 KB
Flash ROM 32 KB 256 KB 4MB – 16MB
EEPROM 1 KB - (can be emulated) - (can be emulated)
GPIO lines 23 38 34
Hardware interfaces I2C, UART, SPI I2C, I2S, UART, SPI,
USB
I2C, I2S, SPI, CAN,
UART, Ethernet,
BT4.2, WIFI, SDCard
Analog inputs/outputs 6 (10Bits) / 6 (PWM) 14 (12Bits) / 1 (10Bits) 18 (12Bits) / 2 (8Bits)
Used e.g. on these
MC boards
Arduino Uno / Mini /
Nano
Seeeduino LoRaWAN,
Adafruit Feather M0
ESP32-WROVER,
PyCom LoPy4
Market price 1.00 € / unit 2.50 € / unit 2.00 € / unit
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller Boards
► MCs are typically installed on a printed circuit board (PCB)
together with other functional components like
● input/output interfaces (to connect sensors, actuators, and displays)
● communication interfaces (wired and wireless)
● power supply (very often voltage regulators; sometimes voltage
converters, battery chargers)
● onboard sensors, actuators, and displays
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 18
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller Boards & Peripherals
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 19
Sensor1(e.g. GPS, Gas)
Sensorm
Actuator1(e.g. Relay, Servo)
Actuatorn
Indicator1(e.g. display, LED)
Indicatork
Microcontroller Board (e.g. Arduino) or
Microcomputer (e.g. Raspberry Pi)
External Module1
Power Supply
(typ. 3.3V, 5V or 6-15V)
Add-on Boards
(“Shields“ / “Wings“)
Functional
Component1
Functional
Componenti
External Modulej
Ha
rdw
are
Inte
rface
s (e
.g. G
PIO
, I2C
, SP
I, Se
rial, U
SB
)
Ha
rdw
are
Inte
rface
s (e
.g. G
PIO
, I2C
, SP
I, Se
rial)
Hardware Interfaces
Flash ROMRealtime
Debugger
Programming
Interface
RAM EEPROM
CPU(s)
GSM, 3G, 4G
Onboard
Sensors
Battery
Charger
Memory
Card
Onboard
Displays
RTC
Bluetooth
LoRa(WAN)
WiFi
Ethernet
optional functional components:
communication
interfaces
⋮
⋮
⋮ ⋮
⋮
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller Boards
► Functional elements of microcontroller boards:
● microcontroller (CPU(s) + I/O interfaces + clock generator; often
built-in working memory (RAM), program memory (Flash ROM),
configuration memory (EEPROM))
● (additional) working memory (RAM – Random Access Memory)
● (additional) program memory (Flash ROM – Reprogrammable
Read Only Memory)
● (additional) configuration memory (EEPROM – Electrically
Erasable Programmable Read Only Memory)
● (additional) input/output (I/O) interfaces
● programming interface
● optionally: communication interfaces, real time clock (RTC)
● power supply, optionally: battery charger
● optionally: sensors, actuators, indicators
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 20
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller Example: Arduino UNO R3
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 21
Image: Make Magazine, CC BY-SA 4.0
USB Connector
External
Power
Supply
(EPS)
Reset Button ► CPU: ATMega328
8 Bit, 16 MHz
● 32 KB Flash ROM
● 2 KB RAM
● 1 KB EEPROM
► Power: 5V over USB
or 7-20V over EPS
► I/O Voltage: 5V
► Programming: over
USBSerial interface
or ISP interface
► Hardware interfaces
● I2C: 1
● SPI: 1
● Serial: 1
● Analog inputs: 6
● Analog outs/PWM: 6
● Digital in-/outputs: 14
► User LEDs: 1
In-System
Program-
ming Conn.
(ISP)
Microcontroller
I/O & Power Connectors
I/O & Power Connectors
Technische Universität MünchenLehrstuhl für Geoinformatik
Arduino UNO R3 – Compatible Boards
► compatible boards are typically less expensive (starting from 2.50 €)
► same dimensions, connectors, and CPU (often in a different package)
► often different types of USB connectors and USBSerial interface chips
► some have extra connectors, buttons, LEDs
► some can switch to 3.3V operating and I/O voltage
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 22
Seeeduino Lotus V1.1Seeeduino V4.2 no name
Image: Seeed Studio Image sourceImage: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller Example: Seeeduino LoRaWAN
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 23
USB Connector
LiPo
Battery
Conn.
Reset Button
► CPU: ATSAMD21G18
(ARM Cortex-M0+)
32 Bit, 48 MHz
● 256 KB Flash ROM
● 32 KB RAM
► Power: 5V over USB
or 3.7V LiPo battery
► I/O Voltage: 3.3V
► Programming: over
USBSerial interface
or ISP interface
► Hardware interfaces
● Gen. Purpose I/O: 20
● I2C: 1
● SPI: 1
● Serial: 2
● Analog inputs: 6
● Analog outputs: 1
► User LEDs: 1
In-System
Program-
ming Conn.
(ISP)
Microcontroller
I/O & Power
Connectors
I/O & Power Connectors
LoRaWAN Module
GPS ReceiverImage: Seeed Studio
GPS Antenna
Grove
Module
Conn.
LoRa
Antenna
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller: Adafruit Feather M0 RFM95 LoRa
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 24
USB
Connector
LiPo Battery Connector
Reset Button
► CPU: ATSAMD21G18
(ARM Cortex-M0+)
32 Bit, 48 MHz
● 256 KB Flash ROM
● 32 KB RAM
► Power: 5V over USB
or 3.7V LiPo battery
► I/O Voltage: 3.3V
► Programming: over
USB interface
► Hardware interfaces
● Gen. Purpose I/O: 20
● I2C: 1
● SPI: 1
● Serial: 2
● Analog inputs: 10
● Analog outputs: 1
● PWM outputs: 8
► User LEDs: 1
LoRa Module
(868 MHz)
Microcontroller
I/O & Power
Connectors
I/O & Power Connectors
Image: Adafruit
LoRa
Antenna
Conn.
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller: SODAQ ONE-EU-RN2483-V3
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 25
USB Connector
Reset Button
► CPU: ATSAMD21G18
(ARM Cortex-M0+)
32 Bit, 48 MHz
● 256 KB Flash ROM
● 32 KB RAM
► Power: 5V over USB
or 3.7V LiPo battery
► I/O Voltage: 3.3V
► Programming: over
USB interface
► Hardware interfaces
● Gen. Purpose I/O: 14
● I2C: 1
● SPI: 1
● Serial: 2
● Analog inputs: 10
● Analog outputs: 1
● PWM outputs: 8
► User LEDs: 1 RGB
Solar
Panel
Conn.
Microcontroller
I/O & Power Connectors
I/O & Power
Connectors
LiPo
Battery
Conn.
GPS ReceiverGPS Antenna
Connector
LoRaWAN
Module
(868 MHz)
LoRa Antenna
Connector
Image: SODAQ
Accelerometer +
Magnetometer
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller Example: PyCom LoPy4
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 26
LoRa & SIGFOX
Modules
WiFi &
Bluetooth
Chip
Antenna
Reset Button ► CPU: ESP32 Dual
Core, 32 Bit, 240 MHz
● 8 MB Flash ROM
● 520 KB + 4 MB RAM
● Real Time Clock
► Power: 3.5 – 5.5V
► I/O Voltage: 3.3V
► Programming: over
Serial interface
► Hardware interfaces
● Gen. Purpose I/O: 24
● I2C: 2
● I2S: 1
● SPI: 1
● Serial / UART: 2
● Analog inputs: 18
● Analog outs/PWM: 18
► User LEDs: 1 RGB
LoRa
Antenna
Connector
Microcontroller
I/O & Power Connectors
I/O &
Power Connectors
Image: PyCom
WiFi &
Bluetooth
Interface
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller STM32F103C8T6 “Blue Pill”
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 27
Image source: Internet
USB
Connector
Reset Button
► CPU: ARM32 Cortex-
M3; 32 Bit, 72 MHz
● 64 KB Flash ROM
● 20 KB RAM
● Real Time Clock
► Power: 5V over USB
► I/O Voltage: 3.3V,
some 5V tolerant inputs
► Programming: over
USB, SWD, or Serial
interface
► Hardware interfaces
● I2C: 2; SPI: 2
● Serial / USART: 3
● USB: 1; CAN: 1
● Analog inputs: 10
● Analog outs/PWM: 4
● Total I/O pins: 37
► User LEDs: 1
Serial Wire Debug
Connector (SWD)
Microcontroller
I/O & Power
Connectors
I/O & Power Connectors
Technische Universität MünchenLehrstuhl für Geoinformatik
Extension Boards for Microcontroller Boards
► For many microcontroller boards a series of hardware
extensions are available
● Extensions are called „Shields“ (Arduino family), „Wings“ (Adafruit
Feather), or „HATs“ (Raspberry Pi) because they are directly
plugged above, below, or next to the microcontroller board
● Shields / Wings / HATs match to a specific (family of) microcontroller
boards (due to pin layout and electrical power & signal compatibility)
► Shields / Wings / HATs typically provide a combination of
● indicators (LEDs, displays like TFT screens, LCDs, buzzers),
● sensors (e.g. GPS, IMU, temperature, humidity, light, gas),
● actuators (e.g. relays, motor drivers, servo drivers),
● interfaces (e.g. WiFi, Bluetooth, LoRa, GSM/3G/4G, SDcard)
● power supply (e.g. battery pack & charger)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 28
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Arduino Shields (1)
► Seeed Solar Charger Shield v2.2
● for operating the microcontroller
board on battery
● support for 3.7V LiPo battery,
5V step-up converter, solar charger
► Seeed Studio Grove Base Shield v2
● provides connectors to attach
Seeed Grove compatible modules
● supports 3.3V and 5V microcontroller
boards
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 29
Images source: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Arduino Shields (2)
► Dragino LoRa/GPS Shield
● GPS receiver with onboard antenna;
external antenna can be connected
● 868 MHz LoRa transceiver chip with
SMA antenna connector
► LCD KeyPad Shield
● adds an LCD display with 2 lines
à 16 characters
● has buttons for e.g. menu navigation
or selection of options
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 30
Image: Dragino Image: DFRobot
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Arduino Shields (3)
► Sparkfun MP3 Player Shield
● plays audio files from a Micro SD
card over 3.5mm audio jack
● supports Ogg Vorbis, MP3, AAC,
WMA, MIDI audio formats
► 2.8” TFT touch display
● 320x200 Pixels with 18 Bits color per
Pixel and touch functionalities
● SPI interface; Micro SD card slot to
load and display images
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 31
Image: Sparkfun Image: Adafruit
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Adafruit Feather Wings
► Alphanumeric FeatherWing Display
● four digit 14-segment LED display for
text and numbers
● uses I2C connection (3 wires),
software library for easy usage
► Power Relay FeatherWing
● control high current and voltage
devices like pumps, lamps, valves
● can switch up to 5A @ 240V AC
resistive loads or 2.5A inductive loads
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 32
Images source: Adafruit
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for PyCom LoPy4 Extension Boards
► Expansion Board 3.0
● provides USB connection; connector
and charger for a 3.7V LiPo battery
● Micro SD card slot for storing sensed
data or generally using files
► Pysense
● provides USB connection; connector
and charger for a 3.7V LiPo battery
● temperature, humidity, light sensors,
3 axes accelerometer
● Micro SD card slot
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 33
Images source: PyCom
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcomputer Example: Raspberry Pi 3 B+
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 34
Image: ELV.de
USB Connectors
Power
Supply
(USB)
Micro
SD Card Slot
► CPU: Quad Core
ARM Cortex A53,
64 Bit, 1.4 GHz
● up to 64GB Flash ROM
● 1 GB RAM
► Power: 5V over USB
► I/O Voltage: 3.3V
► Programming: over
USBSerial interface
or ISP interface
► Hardware interfaces
● USB 2.0: 4
● HDMI; Compos. Video
● Stereo Audio Port
● Ethernet (1 GBit/s)
● Gen. Purpose I/O: 26
● I2C: 1; SPI: 2
● Serial: 1
● Analog outs/PWM: 1Ethernet Port
Microcontroller (incl.
Graphics Processor)
I/O & Power
Connectors
HDMI Port
Audio & Composite Video
RAM Chip
Camera Conn.
Display
Connector
WiFi & Bluetooth Chip
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Raspberry Pi HATs
► Grove Pi+
● Grove connectors for 7 digital,
3 analog, 3 I2C, and 1 serial port
● all Grove connectors provide 5V
operating voltage
► Dragino LoRa / GPS HAT
● GPS receiver with onboard antenna;
external antenna can be connected
● 868 MHz LoRa transceiver chip with
SMA antenna connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 35
Image: Seeed Studio Image: Dragino
Technische Universität MünchenLehrstuhl für Geoinformatik
Microcontroller Boards vs. Microcomputers
Microcontroller Boards
► Examples: Arduino Uno, Adafruit
Feather, ESP8266, ESP32
► typ. single core CPU; 8 Bit, 16 Bit
or 32 Bit data bus width; 8 MHz –
240 MHz clock rate
► no operating system (only a boot
loader to upload a program;
sometimes a system kernel)
► small memory size (2 KB – 4 MB
RAM, 8 KB – 8 MB Flash ROM)
► typ. many I/O lines & interfaces
► low power consumption (modes);
can run on battery power from
days up to years
► very cheap (1 € – 100 €)
Microcomputers
► Examples: Raspberry Pi, Notebook,
Tablet & Desktop PC
► 1…n CPU cores, 32 Bit or 64 Bit data
bus width; 700 MHz – 2 GHz clock
rate
► typically run an operating system like
Linux, Windows, or Android
► larger memory (256 MB – 8 GB RAM)
► user interfaces are built-in: keyboard,
mouse, (touch) display
► require a mass storage device
(SSD, SDcard, hard disk)
► high power consumption; short
runtime on battery power, < 24h)
► more expensive (10 € – 1000 €)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 36
Technische Universität MünchenLehrstuhl für Geoinformatik
Structure of this Lecture
I. Microcontroller & Microcomputer
● Introduction & Overview
● Microcontroller Boards & Extension Boards
● Microcomputer & Extension Boards
II. Sensors
● Definition & Characteristics
● Examples for Sensors & Sensor Boards
III. Actuators & Indicators
● Definition
● Examples for Actuators & Indicator Boards; Dashboards
IV. Developing Microcontroller Systems
● Arduino Integrated Development Environment (IDE)
● Using the Hardware & Input/Output Pins of Arduino-type Microcontrollers
● Important Rules when connecting components
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 37
Technische Universität MünchenLehrstuhl für Geoinformatik
Sensors
► Definition: A sensor is a device that responds to a physical
stimulus (such as heat, light, sound, pressure, magnetism,
or a particular motion) and transmits a resulting impulse
(as for measurement or operating a control).[Mirriam-Webster Dictionary]
► Sensors typically transform one type of energy into
another form of energy
● for example, a temperature or pressure into a voltage level
► Sensor measurements should not affect the measured
quantity (as far as possible)
► Sensors should be insensitive to changes of conditions
that they should not measure
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 38
Technische Universität MünchenLehrstuhl für Geoinformatik
Sensor Characteristics (I)
Important sensor characteristics are
► Sensitivity
● How much does the sensor output changes when the input quantity
being measured changes?
► Precision
● How close are sensor output values when repeatedly measuring the
same measured quantity? (mostly related to noise)
► Accuracy
● How close are sensor output values to the real quantity being
measured? (absolute deviations)
► Insensitivity regarding environmental conditions
● e.g. stability with respect to temperature or operating voltage
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 39
Technische Universität MünchenLehrstuhl für Geoinformatik
Sensor Characteristics (II)
Important sensor characteristics are
► Type of Output
● analog signal (typ. a voltage level)
● digital signal (often using a digital communication protocol)
► Passive or Active
● active: the sensor device sends out a signal to be reflected like a
light or radio impulse (e.g. LASER scanning, RADAR)
● passive: the sensor detects signals emitted from the environment
► Powered or Unpowered
● the sensor device needs / does not need a power supply to work
● all sensors using digital communication need to be powered
● when powered: Power Consumption is also important!
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 40
Technische Universität MünchenLehrstuhl für Geoinformatik
Sensor Characteristics (III)
► Settlement Time
● How fast can the sensor follow changes of the measured quantity
until a correct and stable sensor output value can be achieved?
When sensor values are being digitized (using an analog to
digital converter ADC) or being determined in a digital way,
then these further characteristics are important:
► Resolution
● Onto which number spectrum are the sensor output values being
mapped, i.e. how many different value steps are available?
(e.g.: 10 bits resolution means 1024 values can be distinguished)
► Measuring Rate
● What is the frequency range of measurements (sampling rates) and
how often can the sensor produce a new output value?
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 41
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Sensors (1)
► Push Button
● a simple momentary push button
● usage e.g. for menu item selection;
activation / deactivation of some
function; initiation of a process;
on/off switching
● 3.3–5V operating voltage
● digital interface; Grove connector
► 360°Rotary Encoder
● rotation of the axis is transformed to a
pattern of digital pulses
● direction of rotation can be determined
● usage e.g. for volume control, menu
navigation
● a knob can be mounted to the axis
● 3.3–5V operating voltage
● digital interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 42
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Sensors (2)
► Aosong DHT22 air temperature &
humidity sensor
● temperature range: -40 – 80°C,
resolution: 0.1° accuracy: ±0.5°C
● relative humidity: 5 – 99%,
resolution 0.1% accuracy: ±2%
● measurement period: ≥ 2s
● 3.3–6V operating voltage, 1.5mA max.
● OneWire interface; Grove connector
► Bosch BME280 air temperature,
humidity, and pressure sensor
● temperature range: -40 – 85°C,
resolution: 0.01° accuracy: ±1°C
● relative humidity: 0 – 100%,
resolution 0.008% accuracy: ±3%
● atmospheric pressure: 300 – 1100 hPa,
resolution: 0.18 Pa accuracy: ±1 hPa
● 3.3–5V operating voltage, 0.4mA max.
● I2C & SPI interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 43
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Sensors (3)
► Bosch BME680 air quality, humidity,
temperature & pressure sensor
● air quality according to volatile organic
compounds (VOC)
● temperature range: -40 – 85°C,
resolution: 0.01° accuracy: ±1°C
● relative humidity: 0 – 100%,
resolution 0.008% accuracy: ±3%
● atmospheric pressure: 300 – 1100 hPa,
resolution: 0.18 Pa accuracy: ±0.6 hPa
● 3.3–5V operating voltage
● I2C & SPI interface; Grove connector
► Loudness Sensor
● detects the loudness of environmental
sound using the onboard microphone
● built-in amplifier and filter;
working frequency: 50 – 2000 Hz
● sensitivity: -48 – 66 dB
● loudness is transformed to an analog
output voltage level
● 3.5–10V operating voltage
● analog interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 44
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Sensors (4)
► HM3301 Dust Sensor
● measures the concentration of
particulate matter in the air
● LASER light scattering technology
● direct output of PM1, PM2.5, PM10
mass concentration with unit of μg/m3
● 3.3–5V operating voltage, 75mA max.
● I2C interface; Grove connector
► MH-Z16 Infrared CO2 Sensor
● measuring the range of 0-2000 parts per
million (PPM), accuracy: 200 PPM
● non-dispersive infrared (NDIR)
measuring principle
● warm-up time 3min, response time <90s
● 4.5–5V operating voltage, 100mA max.
● UART interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 45
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Sensors (5)
► GPS Receiver
● 22 tracking / 66 acquisition channel
GPS receiver
● used for position determination (lat,
lon, height @ WGS84), accuracy: 5m
● cold start 29s, hot start 1s, 1 Hz freq.
● 3.3–5V operating voltage, 40mA max.
● UART interface; Grove connector
► 9DOF Inertial Measurement Unit (IMU)
● 3 axis electronic compass with
0.15 μT/LSB (typ.) sensitivity
● 3 axis gyroscope with programmable
range from ±250 to ±2000 dps
● 3 axis accelerometer with programmable
range of ±2g, ±4g, ±8g, or ±16g
● based the two chips LCM20600, AK09918
● 3.3–5V operating voltage, 5 mA @ 100 Hz
● I2C interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 46
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Sensors (6)
► Soil Moisture Sensor
● can qualitatively test the humidity of
the soil (no quantitative measuring)
● capacitive measuring principle
● corrosion resistant
● 3.3–5V operating voltage
● analog interface; Grove connector
► M11*1.25 Water Flow Sensor
● consists of a plastic valve body, a water
rotor, and a hall-effect sensor
● flow rate range 0.3 – 6 l/min
● pulse frequency (Hz) = 73Q, Q is flow
rate in l/min
● 4.5–24V operating voltage, 15mA max.
● digital interface (3 pin connector, 0.1in
pin spacing)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 47
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Some Remarks on Sensors
► Sensors need to be calibrated
● often they come calibrated from the manufacturer
● sometimes they need to be recalibrated in regular intervals
► For each kind of phenomenon there are sensors available
in different price classes (can go from 0.01 to 5000 €)
● cheap sensors typically low accuracy, low resolution
● can be used to observe trends, but often not suitable to
measure e.g. absolute gas or particulate matter concentrations
● however, there are many use cases in which this is sufficient
► Gas sensors are often not only sensitive to one type of gas
● for example, CO sensors often react to other gases, too
(hence, an increased sensor output value can have different reasons)
► Always download and check the datasheets!
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 48
Technische Universität MünchenLehrstuhl für Geoinformatik
Structure of this Lecture
I. Microcontroller & Microcomputer
● Introduction & Overview
● Microcontroller Boards & Extension Boards
● Microcomputer & Extension Boards
II. Sensors
● Definition & Characteristics
● Examples for Sensors & Sensor Boards
III. Actuators & Indicators
● Definition
● Examples for Actuators & Indicator Boards; Dashboards
IV. Developing Microcontroller Systems
● Arduino Integrated Development Environment (IDE)
● Using the Hardware & Input/Output Pins of Arduino-type Microcontrollers
● Important Rules when connecting components
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 49
Technische Universität MünchenLehrstuhl für Geoinformatik
Actuators
► Definition: a mechanical device for moving or controlling
something. [Mirriam-Webster Dictionary]
► Similar to sensors, actuators typically transform one type of
energy into another form of energy
► Typically electrical signals are transformed into mechanical
energy
● rotation, lifting, moving by a motor, servo, valve, solenoid
● movement of air molecules: wind, but also acoustics
► Actuators can also be used to emit electromagnetic waves
● light by a lamp, LED, display
● radio frequency signals like microwaves
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 50
Technische Universität MünchenLehrstuhl für Geoinformatik
Indicators / Displays
► Actuators are often used as indicators by producing a
signal that is visible, audible, or tactile
► Purpose: communicate information about the state of
a system (typically to a human)
► visual indicators are called displays
► Examples are
● screens, LEDs, lamps, flasher
● meters, counters, gauges
● loud speaker, head phone
● siren, buzzer
● vibration and force-feedback devices (e.g. in Smart Phones)
● braille terminal (for the blind)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 51
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Actuators (1) – Indicators
► LED Bar
● 10 segment LED gauge bar controlled
by an MY9221 chip
● 1 red, 1 yellow, 1 light green, and 7
green LEDs
● can be used e.g. as a level indicator
● 3.3–5V operating voltage, 75mA max.
● digital interface; Grove connector
► 4 digit 7-segment LED display
● controlled by a TM1637 chip
● used to display numeric values, time, or
1-4 characters (as far as they are
representable with 7 segments)
● 3.3–5V operating voltage, 80mA max.
● digital interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 52
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Actuators (2) – Indicators
► LCD Character Display
● 16 characters×2 lines;
built-in English and Japanese fonts
● switchable LED backlight
● can be used to display text, numbers,
messages, menus etc.
● 3.3–5V operating voltage, 60mA max.
● I2C interface; Grove connector
► OLED Display
● available in different sizes (0.96in / 1.12in)
and pixel resolutions (128×64 / 128×128)
● single color / 16 gray scales
● can be used to display text, numbers,
messages, menus, graphics etc.
● 5V / 3.3–5V operating voltage
● I2C interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 53
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Actuators (3) – Indicators
► TFT Display
● 2.4in full color display, 320x200 pixels
● 16 bits color per pixel; touchscreen
● SPI interface; Micro SD card slot to
load and display images
● 3.3V operating voltage, 100mA max.
● direct connector to an Adafruit Feather
► Relay
● used to switch larger electrical loads
like lamps, pumps, motors
(max. 250V AC or 30V DC, 5A)
● 3.3–5V operating voltage, 100mA max.
● digital interface; Grove connector
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 54
Image: Seeed Studio Image: Adafruit
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Actuators (4)
► Servo
● motor + potentiometer to drive (move,
turn, or shift) a mechanism
● angle controlled via PWM signal
● torque: 1.5–1.8 kgf∙cm
● turning speed: 0.12–0.16s / 60°
● 4.8–6V operating voltage
● digital interface; Grove connector
► Water Pump
● suction lift: 10cm, spit out lift: 50cm
● flow rate: 1.31 ±0.26 l/min
● 5mm vinyl tubing can directly be attached
● 10–13V operating voltage, needs its own
power supply; no load current: 250mA
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 55
Images: Seeed Studio
Technische Universität MünchenLehrstuhl für Geoinformatik
Dashboards
► Indicators and control elements are also called instruments
► A dashboard is a dedicated composition of instruments with
the function of a user interface to a system
► Purpose
● give overview and important details on the status of a system by
showing information about different sub systems in a comprehensive
and user-friendly way
● control a system by providing elements like switches, buttons,
knobs, joysticks to change the operation parameters of sub systems
► A dashboard has to address the specific information and
control demands of the type of user it is dedicated for
● a captain has to see different status information about a ship than
the chief engineer or machinist
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 56
Technische Universität MünchenLehrstuhl für Geoinformatik
Examples for Dashboards
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 57
Image: Aaron Logan, CC BY 1.0
Image: Hans Braxmeier from Pixabay
► Dashboards are also called instrument panels
Image: Yovko Lambrev, CC BY 3.0
Technische Universität MünchenLehrstuhl für Geoinformatik
Structure of this Lecture
I. Microcontroller & Microcomputer
● Introduction & Overview
● Microcontroller Boards & Extension Boards
● Microcomputer & Extension Boards
II. Sensors
● Definition & Characteristics
● Examples for Sensors & Sensor Boards
III. Actuators & Indicators
● Definition
● Examples for Actuators & Indicator Boards; Dashboards
IV. Developing Microcontroller Systems
● Arduino Integrated Development Environment (IDE)
● Using the Hardware & Input/Output Pins of Arduino-type Microcontrollers
● Important Rules when connecting components
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 69
Technische Universität MünchenLehrstuhl für Geoinformatik
How to Program Microcontroller (Boards)
► Microcontroller boards typically have no operating system,
but come with a boot loader
● the boot loader receives a user program transferred from the
Integrated Development Environment (IDE) on the development
computer and stores it in the reprogrammable Flash ROM
● also called „uploading“ or „burning“ the program into Flash ROM
● after uploading the program is typ. immediately started
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 70
USB Cable
Technische Universität MünchenLehrstuhl für Geoinformatik
How to Program Microcontroller (Boards)
► For some microcontroller boards specific buttons must be
pressed or some pins need to be connected to enable
upload mode
● refer to the board documentation
● in most cases, when the MC board is connected via USB to the
development computer, switching to upload mode is automatic
► When no bootloader is there or when the bootloader soft-
ware itself should be replaced: ISP programmer required
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 71
Technische Universität MünchenLehrstuhl für Geoinformatik
Uploading Programs to a Microcontroller Board
► While the program development for microcontrollers is
typically carried out on a developer computer using an IDE,
the compiled program (sketch) has to be transferred to the
microcontroller in order to be executed
► Using a bootloader
● most microcontroller boards come with a pre-installed bootloader
software (to be used with the Arduino IDE)
● the program (sketch) is uploaded to the MC board typ. using a Serial
connection (often via USB) and permanently stored in the Flash ROM
● the upload process typ. can be initiated directly from the IDE; the MC
board automatically detects this and switches to “upload mode”
► Using a microcontroller programming device
● if no bootloader is provided in the microcontroller or if the bootloader
itself should be programmed
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 72
Technische Universität MünchenLehrstuhl für Geoinformatik
Arduino Integrated Development Environment IDE
The Open Source development environment for the Arduino
comes with many integrated functions:
► Source code editor
► Compiler
► Uploading tool
► Serial console
► Abstracts from and works with many different
microcontroller boards and CPUs
● Support for specific boards can easily be added
► Manages software libraries
It can be freely downloaded from www.arduino.cc for MacOS,
Linux, and Windows
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 73
Technische Universität MünchenLehrstuhl für Geoinformatik
Programming within the Arduino Framework
► Arduino programs are called Sketches
► Sketches have to be implemented in the programming
languages C and C++
► Sketches consist typically of two parts:
● The method setup():
● setup() is called once when the microcontroller board is switched on,
or when a reset condition has been met (e.g. the user presses the
‚reset‘ button). Afterwards, the loop() method is called.
Typically this method is used to initialize attached hardware
(configuration of GPIO pins, attached sensors etc.).
● The method loop():
● loop() is a method that loops infinitely (until the MC board is switched
off). Everytime the execution reaches the end of the loop() method, it
will be restarted again.
Typically this method performs the regular and repetitive activities
(e.g. reading and displaying data from sensors, transmit data).
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 74
Technische Universität MünchenLehrstuhl für Geoinformatik
The First Arduino Program: Blink an LED
/* Turn on an LED for one second, then off for one second, repeatedly.
Most microcontroller boards have an on-board LED that can
be controlled by a user program. There is a predefined macro
LED_BUILTIN that has the proper digital pin name for the selected
microcontroller board (often this is digital pin 13).
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn LED on (HIGH is the voltage level)
delay(1000); // wait for 1000ms = 1 second
digitalWrite(LED_BUILTIN, LOW); // turn LED off by making the voltage LOW
delay(1000); // wait for a second
}
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 75
Technische Universität MünchenLehrstuhl für Geoinformatik
Getting Started with Microcontrollers
1. Collect the relevant hardware
● microcontroller board
● some sensors, actuators, indicators / displays
● connection cable to a developer computer
● possibly a power supply (e.g. battery), if not powered by USB cable
2. Prepare the required software
● download & install the Integrated Development Environment (IDE)
for the developer computer
● possibly download & install a hardware driver for the USB interface
chip of the microcontroller
3. Connect the microcontroller to the developer computer
4. Start the IDE, load a demo application (e.g. “Blink”),
compile and upload the program onto the microcontroller
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 76
Technische Universität MünchenLehrstuhl für Geoinformatik
The 2nd Arduino Program: Print messages
/* Print the text message "Hello World!" to the Serial port. Then every two
seconds further messages ”...and again: Hello World!" are printed.
The serial port is typically connected to a Serial/USB converter and,
hence, the text is sent over USB to the connected developer computer.
Open the Serial Monitor Window in the Arduino IDE to see the messages.
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
delay(6000); // wait 6 seconds before printing the first message
Serial.println("Hello World!");
}
// the loop routine runs over and over again forever:
void loop() {
delay(2000); // wait two seconds
Serial.println("...and again: Hello World!");
}
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 77
Technische Universität MünchenLehrstuhl für Geoinformatik
The 3rd Arduino Program: Command an LED
/* Command an LED over the Serial connection. Open the Serial Monitor Window
in the Arduino IDE and type in the input line at the top 0 and <Return> to
switch the LED off, and any other number and <Return> to switch it on.
At the bottom of the Serial Monitor choose "New line" and "9600 baud”.
*/
void setup() { // runs only once after power on or reset
Serial.begin(9600); // initialize serial communication at 9600 bps
pinMode(LED_BUILTIN, OUTPUT); // initialize pin LED_BUILTIN as an output
}
void loop() { // the loop routine runs over and over again forever
while (Serial.available() > 0) { // if any characters were received,
int ledstatus = Serial.parseInt(); // try convert them to an integer number
if (Serial.read() == '\n') { // look for the newline: <Return> pressed
if (ledstatus == 0) digitalWrite(LED_BUILTIN, LOW);
else digitalWrite(LED_BUILTIN, HIGH);
}
}
}
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 78
Technische Universität MünchenLehrstuhl für Geoinformatik
Remarks on the Usage of Serial Ports
► the Arduino board has only one hardware UART / serial port
● in Arduino sketches this port is named "Serial"
● the serial port can be used via the USB connector (USB serial) or
by connecting a device to digital pins D0 (RX) and D1 (TX)
► additional Serial ports can be emulated in software
● using the Arduino library SoftwareSerial
● certain digital I/O pins can be employed as TX and RX lines
● users can choose their own names for SoftwareSerial ports
► some microcontrollers (and boards) offer more than one
UART / serial port
● all ports have different names (SerialUSB, Serial1, Serial2, Serial3)
● often their USB port is attached not to "Serial", but to "SerialUSB"
(this is the case, for example, for Seeeduino LoRaWAN)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 79
Technische Universität MünchenLehrstuhl für Geoinformatik
Overview of Hardware Serial Ports
Board USB CDC Name Serial pins Serial1
pins
Serial2
pins
Serial3
pins
Arduino Uno,
Nano, Mini
Serial 0(RX), 1(TX)
Arduino Mega Serial 0(RX), 1(TX) 19(RX),
18(TX)
17(RX),
16(TX)
15(RX),
14(TX)
Arduino DUE SerialUSB (native
USB Port only)
0(RX), 1(TX) 19(RX),
18(TX)
17(RX),
16(TX)
15(RX),
14(TX)
Arduino
Leonardo
Serial 0(RX), 1(TX)
Seeeduino V4.2 Serial 0(RX), 1(TX)
Seeeduino
LoRaWAN GPS
SerialUSB (native
USB Port only)
connected to
GPS module
can be
configured
to diff. pins
can be
configured
to diff. pins
can be
configured
to diff. pins
Adafruit
Feather M0
RFM95 LoRa
Serial (internally
mapped onto
SerialUSB)
0(RX), 1(TX) can be
configured
to diff. pins
can be
configured
to diff. pins
can be
configured
to diff. pins
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 80
Technische Universität MünchenLehrstuhl für Geoinformatik
Arduino Connectors & Pin Naming
► Arduino connectors have standardized pinouts
► most pins can be used for different I/O purposes
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 81
Image: Alberto Piganti (pighixxx), CC BY-SA, see https://www.pinterest.de/pighixxx/
Technische Universität MünchenLehrstuhl für Geoinformatik
Arduino Digital and Analog Pins
► In the Arduino development environment the digital and
analog pins are addressed using their names/numbers
► Pins 0-13 denote digital inputs/outputs
● use pinMode(pin, mode) to determine I/O direction
(mode: INPUT, INPUT_PULLUP, OUTPUT)
● use digitalWrite(pin, level) to set the output voltage
(level: HIGH ≙ VCC, i.e. 3.3V or 5V; LOW ≙ 0V)
● use digitalRead(pin) to read the logic level (result is HIGH or LOW)
► Pins A0-A5 denote the six analog inputs
● use analogRead(pin) to determine voltage level at pin using the
built-in analog-to-digital converter (ADC), (resolution is 10 bits,
0 ≙ 0V, 1023 ≙ 5V)
● analog pins A0-A5 can also be used as digital inputs/outputs, e.g.
pinmode(A2,OUTPUT); digitalWrite(A2,HIGH);
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 82
Technische Universität MünchenLehrstuhl für Geoinformatik
Remarks on the Usage of I/O Pins
► digital pins 0 and 1 are also used by the Serial port
● do not use for digital I/O, if the Serial port should be used (also
important with regard to program uploads)
► on most MC boards, digital pin 13 is connected to an LED
► pins A0-A5 can also be addressed using pin numbers 14-19
► most pins are also used for specific hardware interfaces
● pins 18, 19 (or A4, A5): I2C interface
● pins 10-13: SPI interface
● pins 3, 5, 6, 9-11: usable as pulse width modulation (PWM) outputs
● when the respective hardware interface is being used, these pins
cannot be used for digital or analog input/output
► non-Arduino Uno boards typically provide further pins and
different hardware interface mappings (check the docs!!)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 83
Technische Universität MünchenLehrstuhl für Geoinformatik
2nd Exercise: Add a Sensor
1. Choose some sensor and connect it to the microcontroller
● e.g. temperature & humidity sensor DHT22 Grove module
● use proper cabling to connect the sensor module (e.g. Grove cable)
2. Prepare the required software
● start the IDE and download a specific software using the library
manager of the IDE
● for some devices, multiple libraries are available choose one
3. With the installation of a library typ. some demonstration
programs have also been loaded
● choose a demo and check, if some configurations need to be
adapted in the source code (e.g. pin numbers)
● typ. the programs print messages over the Serial interface
4. Compile & upload the demo program, open the console
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 88
Technische Universität MünchenLehrstuhl für Geoinformatik
Practical Rules when connecting components (1)
► Check operating voltages: Ensure that the voltage of the power
supply matches the operating voltage of the microcontroller board
● typical operating voltages are 3.3V or 5V. Do not put 5V to a board that only
accepts 3.3V – or you’ll most likely kill the board.
● often microcontroller boards have voltage regulators reducing the voltage
level from the power connector down to 3.3V or 5V
● hence, if a microcontroller board is powered by the USB connector (which
has 5V), you cannot automatically assume that the board itself runs on 5V;
it can also be less (3.3V)
● this is important when connecting external modules or shields / wings:
ensure that the operating voltage of the module or shield matches the
operating voltage of the microcontroller board
► Checking operating voltages is always important when connecting
modules to a microcontroller board, a shield, or to each other
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 89
Technische Universität MünchenLehrstuhl für Geoinformatik
Practical Rules when connecting components (2)
► Everything needs to be powered: all components typically need to
be connected to a power supply.
● when connecting a shield / wing to a microcontroller board, its power
supply is normally provided through the connector
● when connecting external modules you need to make sure that the
external component either receives power from the microcontroller board
or is powered separately using its own power supply.
● when connecting external modules using the Grove module system from
the company Seeedstudio, the power supply of the modules is typically
provided through the 4-pin Grove connector cable
● if a connected module has its own power supply, you must connect the
Ground (GND) pins of the microcontroller board and the module, but you
must not connect the anode (positive power pin, often labeled as VCC or
+5V or +3.3V) of the microcontroller with the respective anode of the
component
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 90
Technische Universität MünchenLehrstuhl für Geoinformatik
Practical Rules when connecting components (3)
► Provide enough power: all components draw energy from the power
supply. Ensure that the power supply is capable to provide at least as
much power as required by all components together
● not all components and parts draw constantly the same current; often the
demand jumps according to different activities. For example, when a WiFi
transmitter is becoming active it can easily draw up to 200mA
● when the entire circuit is powered just by a small battery with limited
capacity or by the voltage regulator of the microcontroller board, the
operating voltage can drop to a critical level, if too much power is drawn by
the components. This can lead to failure of operation, caused e.g. by
spurious resets of the microcontroller
● for example, if an Arduino is powered over the USB connector from a
connected computer or using a USB charger, the 5V pin of an Arduino can
deliver at maximum 500mA, but the 3.3V pin only 150mA (Arduino Uno) or
50mA (Arduino Nano) respectively
● for higher demands use an external power supply (with own regulator)
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 91
Technische Universität MünchenLehrstuhl für Geoinformatik
Practical Rules when connecting components (4)
► Check pins before connection: when connecting I/O or interface pins
between components, it has to be known which pins are Input or Output pins
● Input pins are used to sense a voltage level (could be a logic level or an
analog voltage), i.e. to receive or read signals / data
● Output pins are set to a specific voltage level (could be a logic level or an
analog voltage), i.e. to emit or write signals / data
● typically the Output pins of one component are connected to Input pins of
the other component and vice versa
● it is also allowed to connect multiple Input pins to a single Output pin
● but: do not connect an Output to another Output unless you really know
what you are doing! Setting one Output to logic 1 level (i.e. 5V or 3.3V
depending on the operating voltage) and the other to logic 0 level (i.e. 0V
or Ground (GND)), will create a short circuit. This can damage the devices
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 92
Technische Universität MünchenLehrstuhl für Geoinformatik
Practical Rules when connecting components (5)
► Check pins before connection: when connecting I/O or interface pins
between components, it has to be known which pins are Input or Output pins
● some I/O pins of microcontroller boards or of external modules have a
fixed configuration. However, many I/O lines of microcontroller (boards)
can be freely configured by the user to operate as Input or Output. These
are called General Purpose I/O (GPIO) pins
● this means that the direction (in / out) of GPIO pins depends on software
and, hence, on the program created by the user. The direction can even be
switched during program execution
● thus, in order to check for pin compatibility when connecting GPIO pins you
need to learn about the pin configuration from checking the user program
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 93
Technische Universität MünchenLehrstuhl für Geoinformatik
Practical Rules when connecting components (6)
► Data protocols: connect pins supporting the same protocol
● when an external module uses a specific protocol, for example I2C, make
sure to connect all required I2C pins of the module with those pins on the
microcontroller board, which are dedicated to I2C
● some microcontroller boards offer multiple instances of the same interface
type (e.g. multiple I2C, Serial, USB, or SPI ports). In this case you can
choose one, but ensure that you configure your software to use this port
● for some hardware connections the lines have to be crossed between
connected components. For example, when using the RS232 serial
communication interface the “transmit” pin (TX) of one component has to be
connected to the “receive” pin (RX) of the other component and vice versa.
The same applies to the so-called handshake pins (if used) - “clear to send”
(CTS) and “ready to send” (RTS), which also must be cross connected
27. 4. 2020 T. H. Kolbe: GI3 – Introduction to IoT: Microcontrollers, Sensors, Actuators 94