Using arduino and raspberry pi for internet of things

Sudar Muthu
Sudar MuthuIndependent Consultant
Using Arduino and Raspberry Pi 
for Internet of Things 
Sudar Muthu (@sudarmuthu) 
http://hardwarefun.com/ 
http://github.com/sudar
Who am I? 
 Research Engineer by profession 
 I build robots as a hobby 
 Playing with Arduino for more than 4 years 
 Blogger about Arduino at http://hardwarefun.com 
 Moderator for Arduino India forum 
http://hardwarefun.com 2
Objective 
 Introduce Arduino 
 Introduce Raspberry Pi 
 Emphasis on IoT 
 See how both can be used for IoT 
http://hardwarefun.com 3
Arduino 
http://hardwarefun.com 4
What is Arduino? 
 Visual Basic for hardware 
 Includes both Hardware and software 
http://hardwarefun.com 5 
Photo credit Arduino team
Different Arduino types 
 Arduino Uno (The one I am going to use today) 
 Arduino Mega 
 Arduino Due 
 Lillypad 
 Arduino BT 
 Arduino Ethernet 
 .. and clones 
http://hardwarefun.com 6
Getting to know the Arduino 
http://hardwarefun.com 7
Specs (Uno, Leonardo) 
Type Value 
Microcontroller ATmega328 
Operating Voltage 5v 
Digital I/O Pins 14 (of which 6 provide PWM output) 
Analog Input Pins 6 
Flash Memory 32 KB (ATmega328) of which 0.5 KB used 
by bootloader 
SRAM 2 KB (ATmega328) 
EEPROM 1 KB (ATmega328) 
Clock Speed 16 MHz 
http://hardwarefun.com 8
Identify these components in 
 Microcontroller 
 Power jacket 
 USB jacket 
 Digital pins 
 Analog pins 
 Reset button 
Arduino 
http://hardwarefun.com 9
Identify these components in 
Arduino 
 Voltage Regulator 
 Power Pins (how many are there?) 
 Ground Pins (how many are there?) 
 Vin Pin 
 Rx and Tx Pins 
 ICSP Headers 
http://hardwarefun.com 10
Identify these components in 
 Power Led 
 Rx and Tx Led’s 
 Test Led 
 Crystal 
 Anything else? 
Arduino 
http://hardwarefun.com 11
Powering up Arduino 
http://hardwarefun.com 12
Different ways to power up Arduino 
 Using USB cable 
 Using DC power jacket 
 Giving voltage directly into Vin pin 
 Giving regulated voltage directly into 5V pin 
http://hardwarefun.com 13
Setting up Arduino 
http://hardwarefun.com 14
Testing the setup with a “Hello 
World” program 
http://hardwarefun.com 15
Blinking LED 
http://hardwarefun.com 16
Making a LED blink 
 Insert a LED in pin 13 
 Open File->Examples->Basics->Blink 
 Select Tools->Boards->Arduino Uno 
 Select File->Upload (or press ctrl+u) 
 You should get the message “Done upload” 
 Your Led should blink 
 Congrats you can program Arduino now  
http://hardwarefun.com 17
People with electronics background 
Did I miss anything? 
http://hardwarefun.com 18
People with electronics background 
Did I miss anything? 
Hint: Ohm’s Law 
http://hardwarefun.com 19
Anatomy of an Arduino sketch 
http://hardwarefun.com 20
Printing values through Serial 
 Uno has one UART hardware port, using which we 
can exchange information with computer 
 Very useful for debugging 
 Works at a specified baud rate 
 Use Serial Monitor to read values 
 SoftwareSerial is also available 
http://hardwarefun.com 21
Breadboard Basics 
http://hardwarefun.com 22
How to use a breadboard 
 The first two and the last two rows are connected 
 In all the other rows, columns are connected 
 Connect the first and last row to power 
 Connect the second and second last row to ground 
http://hardwarefun.com 23
Digital Input and Output 
http://hardwarefun.com 24
Digital Input 
http://hardwarefun.com 25
Digital Output 
The LED blink that we did at “setting up Arduino” is 
Digital output 
http://hardwarefun.com 26
Analog Input 
http://hardwarefun.com 27
Reading Analog values from sensors 
 Connect the LDR on pin A0 and Gnd 
 LDR’s resistance varies based on the amount of light 
present 
 Read the current value using analogRead() 
 Print the value in Serial Monitor 
http://hardwarefun.com 28
Control an LED based on light 
void setup(){ 
pinMode(13, OUTPUT); 
} 
void loop(){ 
int val = analogRead(A0); 
if (val > 50) { 
digitalWrite(13, HIGH); 
} else { 
digitalWrite(13, LOW); 
} 
} 
http://hardwarefun.com 29
Analog Output 
http://hardwarefun.com 30
Analog Output 
 What is PWM? 
 Analog like behavior using digital output 
 Works by switching the LED on and off regularly 
 Changing the brightness of a Led 
http://hardwarefun.com 31
This is just the tip of an 
iceberg 
http://hardwarefun.com 32 
There are tons of other 
features to Arduino which I 
have not talked about
Internet of Things 
http://hardwarefun.com 33
http://hardwarefun.com 34 
"Internet of Things" by Wilgengebroed on Flickr
LoT is an overloaded term 
But I like this definition… 
“The Internet of Things is the interconnection of 
uniquely identifiable embedded computing devices 
within the existing Internet infrastructure” 
http://hardwarefun.com 35
Connecting Arduino to Internet 
 Ethernet Shield 
 WIFI Shield 
 3G Shield 
 Using another intermediate component 
http://hardwarefun.com 36
Demo of network connectivity 
using Arduino 
http://hardwarefun.com 37
Let’s take a break  
http://hardwarefun.com 38
Raspberry Pi
Credit Card Sized 
Computer 
http://hardwarefun.com 40
GPIO Pins 
http://hardwarefun.com 41 http://learn.adafruit.com/assets/3052
Setup Python 
sudo apt-get install python-dev 
sudo apt-get install python-rpi.gpio 
http://hardwarefun.com 42
Set the status of GPIO Pins 
https://github.com/sudar/r http://hardwarefun.com asp4b3erry-pi-sketches/blob/master/led-blink/led-blink.py
Set the status of GPIO Pins 
import RPi.GPIO as GPIO 
import time 
GPIO.setmode(GPIO.BOARD) 
GPIO.setup(12, GPIO.OUT) 
try: 
while True: 
GPIO.output(12, GPIO.HIGH) 
time.sleep(1) 
GPIO.output(12, GPIO.LOW) 
time.sleep(1) 
finally: 
GPIO.cleanup() 
https://github.com/sudar/raspberry-http://hardwarefun.com 44 pi-sketches/blob/master/led-blink/led-blink.py
Demo 
Let there be Light 
https://github.com/sudar/r http://hardwarefun.com 45aspberry-pi-sketches/blob/master/led-blink/led-blink.py
Changing the brightness of the LED 
import RPi.GPIO as GPIO 
import time 
GPIO.setmode(GPIO.BOARD) 
GPIO.setup(12, GPIO.OUT) 
p = GPIO.PWM(12, 50) # channel=12 frequency=50Hz 
p.start(0) 
try: 
while True: 
for dc in range(0, 101, 5): 
p.ChangeDutyCycle(dc) 
time.sleep(0.1) 
for dc in range(100, -1, -5): 
p.ChangeDutyCycle(dc) 
time.sleep(0.1) 
finally: 
p.stop() 
GPIO.cleanup() 
http://hardwarefun.com 46 
https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/pwm.py
Demo 
Can you see the brightness changing? 
https://github.com/sudar/raspberry-http://hardwarefun.com 47 pi-sketches/blob/master/led-blink/pwm.py
Reading the status of the Pin 
import RPi.GPIO as GPIO 
import time 
GPIO.setmode(GPIO.BOARD) 
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 
try: 
while True: 
if GPIO.input(11): 
print "Button is on" 
else: 
print "Button is off" 
time.sleep(0.1) 
finally: 
GPIO.cleanup() 
http://hardwarefun.com 48 
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
Reading the status of the Pin 
http://hardwarefun.com 49 
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
Demo 
What happens when the button is pressed? 
http://hardwarefun.com 50 
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
Combining Input and Output 
import RPi.GPIO as GPIO 
import time 
GPIO.setmode(GPIO.BOARD) 
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 
GPIO.setup(12, GPIO.OUT) 
try: 
while True: 
if GPIO.input(11): 
print "Button is on" 
GPIO.output(12, 1) 
else: 
GPIO.output(12, 0) 
time.sleep(0.1) 
finally: 
GPIO.cleanup() 
http://hardwarefun.com 51 
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
Combining Input and Output 
http://hardwarefun.com 52 
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
Demo 
Let’s control the LED by pressing the button 
http://hardwarefun.com 53 
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
What more can be done? 
http://hardwarefun.com 54
More protocols 
 I2C 
 SPI 
 Serial 
http://hardwarefun.com 55
Interacting with webcam 
 “PyGame” provides easy interface 
 Can get fancy using “opencv” 
 Both USB and GPIO interface are supported 
http://hardwarefun.com 56
Distributed Computing 
 Each Pi can be used as cheap node 
 Form grids using a cluster of Pi’s 
 Can share CPU, memory and disk space 
http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/ 
distributed-computing/ 
http://hardwarefun.com 57
Limitations 
 No built-in Analog to Digital support 
 Can’t run Inductive load (motors) 
 Is not real-time (CPU might be busy) 
 No “safe circuits” present 
 Operates at 3.3V and is not directly compatible with 
Arduino voltage 
http://hardwarefun.com 58
Arduino vs Raspberry Pi 
for IoT 
http://hardwarefun.com 59
Advantages of Raspberry Pi 
 Entire Linux software stack is available 
 It is very easy to connect to internet 
 Can be programmed using variety of programming 
languages 
http://hardwarefun.com 60
Disadvantage of Raspberry Pi 
 Accessing hardware is not real-time. If the CPU is 
busy, then interfacing with hardware can be delayed 
 No built-in Analog to Digital converter available 
 Does not have enough power to drive inductive loads 
 The hardware design is not open source. Even though 
it is not a big deal, for some people it might a deal 
breaker 
http://hardwarefun.com 61
Advantages of Arduino 
 Very easy to get started 
 Very easy to extend it and has tons of user 
contributed shields and libraries. Shields are available 
to do pretty much anything 
 Can be used to for real-time applications 
 Everything (both hardware, software and IDE) are 
open source 
 Not much programming knowledge needed to do 
basic stuff 
http://hardwarefun.com 62
Disadvantages of Arduino 
 Not very powerful when compared with Raspberry Pi 
(Micro processor vs Micro controller) 
 You need to program using either Arduino or C/C++ 
(or assembly if you really want to) 
 Connecting to internet is slightly difficult (you have 
shields and libraries, but is not straight forward), but 
not impossible. 
http://hardwarefun.com 63
In Short.. 
Feature Raspberry Pi Arduino 
Processor Speed 700 MHz 16 MHz 
Programming Language No limit Arduino, C/C++ 
Real-time Hardware No real-time In real-time 
Analog to Digital Convertor No Yes 
Hardware Design Closed source Open source 
Internet Connection Very easy Not easy, but doable 
http://hardwarefun.com 64
My Solution? 
http://hardwarefun.com 65
Use both together  
Best of both worlds 
http://hardwarefun.com 66 
http://learn.adafruit.com/assets/3199 http://learn.adafruit.com/assets/2123
Links 
 Source code - https://github.com/sudar/raspberry-pi-sketches/ 
 My blog - http://hardwarefun.com 
 Python GPIO - https://code.google.com/p/raspberry-gpio- 
python/ 
 Distributed computing using Pi - 
http://www.cl.cam.ac.uk/projects/raspberrypi/tutorial 
s/distributed-computing/ 
http://hardwarefun.com 67
Links 
 Arduino – http://arduino.cc 
 Asimi – A simple bot using Arduino 
http://hardwarefun.com/project/asimi 
 Getting started with hardware programming 
http://hardwarefun.com/tutorials/getting-started-with-hardware- 
programming 
 Getting started with Arduino 
http://hardwarefun.com/tutorials/getting-started-with-arduino- 
and-avr 
http://hardwarefun.com 68
Questions 
Thank You 
Sudar Muthu (@sudarmuthu) 
http://hardwarefun.com/ 
https://github.com/sudar/arduino-robotics-workshop 
https://github.com/sudar/raspberry-pi-sketches 
http://hardwarefun.com 69
1 of 69

Recommended

Single Board Computers & Raspberry Pi Basics by
Single Board Computers & Raspberry Pi BasicsSingle Board Computers & Raspberry Pi Basics
Single Board Computers & Raspberry Pi BasicsEueung Mulyana
1.9K views59 slides
Arduino vs Raspberry Pi by
Arduino vs Raspberry PiArduino vs Raspberry Pi
Arduino vs Raspberry PiJitendra Adhikari
3.2K views6 slides
Introduction to Arduino by
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduinoyeokm1
1.9K views15 slides
Introduction to Raspberrypi by
Introduction to  RaspberrypiIntroduction to  Raspberrypi
Introduction to RaspberrypiIheb Ben Salem
4.3K views24 slides
Introduction to Arduino & Raspberry Pi by
Introduction to Arduino & Raspberry PiIntroduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiAhmad Hafeezi
5.3K views24 slides
My arduino presentation by
My arduino presentationMy arduino presentation
My arduino presentationSham Arsenal
1.9K views19 slides

More Related Content

What's hot

Introduction to Raspberry PI by
Introduction to Raspberry PIIntroduction to Raspberry PI
Introduction to Raspberry PIChandrashekar Babu
5.7K views17 slides
Raspberry pi by
Raspberry piRaspberry pi
Raspberry piPravesh Sahu
251 views26 slides
Raspberry Pi by
Raspberry Pi Raspberry Pi
Raspberry Pi Selvaraj Seerangan
2.9K views104 slides
Introducing the Arduino by
Introducing the ArduinoIntroducing the Arduino
Introducing the ArduinoCharles A B Jr
2.1K views49 slides
Getting Started with Raspberry Pi by
Getting Started with Raspberry PiGetting Started with Raspberry Pi
Getting Started with Raspberry Piyeokm1
1.8K views25 slides
Introduction to Arduino Hardware and Programming by
Introduction to Arduino Hardware and ProgrammingIntroduction to Arduino Hardware and Programming
Introduction to Arduino Hardware and ProgrammingEmmanuel Obot
2.1K views32 slides

What's hot(20)

Getting Started with Raspberry Pi by yeokm1
Getting Started with Raspberry PiGetting Started with Raspberry Pi
Getting Started with Raspberry Pi
yeokm11.8K views
Introduction to Arduino Hardware and Programming by Emmanuel Obot
Introduction to Arduino Hardware and ProgrammingIntroduction to Arduino Hardware and Programming
Introduction to Arduino Hardware and Programming
Emmanuel Obot2.1K views
Arduino Platform with C programming. by Govind Jha
Arduino Platform with C programming.Arduino Platform with C programming.
Arduino Platform with C programming.
Govind Jha1.3K views
Raspberry Pi (Introduction) by Mandeesh Singh
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)
Mandeesh Singh39.6K views
Arduino slides by sdcharle
Arduino slidesArduino slides
Arduino slides
sdcharle1.8K views
arduino by jhcid
 arduino arduino
arduino
jhcid527 views
Raspberry pi : an introduction by LTG Oxford
Raspberry pi : an introductionRaspberry pi : an introduction
Raspberry pi : an introduction
LTG Oxford63.4K views
Embedded Software Development by Sanjay Kumar
Embedded Software DevelopmentEmbedded Software Development
Embedded Software Development
Sanjay Kumar2.8K views
Introduction to Arduino by Yong Heui Cho
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Yong Heui Cho11.6K views
Lesson sample introduction to arduino by Betsy Eng
Lesson sample   introduction to arduinoLesson sample   introduction to arduino
Lesson sample introduction to arduino
Betsy Eng1.2K views

Similar to Using arduino and raspberry pi for internet of things

Arduino Robotics workshop Day1 by
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Sudar Muthu
12.8K views52 slides
Intro to arduino by
Intro to arduinoIntro to arduino
Intro to arduinoJosé Faria
627 views23 slides
What are the different types of arduino boards by
What are the different types of arduino boardsWhat are the different types of arduino boards
What are the different types of arduino boardselprocus
2.7K views27 slides
Arduino by
ArduinoArduino
Arduinovipin7vj
57.6K views18 slides
Getting started with Intel IoT Developer Kit by
Getting started with Intel IoT Developer KitGetting started with Intel IoT Developer Kit
Getting started with Intel IoT Developer KitSulamita Garcia
17.8K views67 slides
Microcontroller arduino uno board by
Microcontroller arduino uno boardMicrocontroller arduino uno board
Microcontroller arduino uno boardGaurav
243 views16 slides

Similar to Using arduino and raspberry pi for internet of things(20)

Arduino Robotics workshop Day1 by Sudar Muthu
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
Sudar Muthu12.8K views
Intro to arduino by José Faria
Intro to arduinoIntro to arduino
Intro to arduino
José Faria627 views
What are the different types of arduino boards by elprocus
What are the different types of arduino boardsWhat are the different types of arduino boards
What are the different types of arduino boards
elprocus2.7K views
Arduino by vipin7vj
ArduinoArduino
Arduino
vipin7vj57.6K views
Getting started with Intel IoT Developer Kit by Sulamita Garcia
Getting started with Intel IoT Developer KitGetting started with Intel IoT Developer Kit
Getting started with Intel IoT Developer Kit
Sulamita Garcia17.8K views
Microcontroller arduino uno board by Gaurav
Microcontroller arduino uno boardMicrocontroller arduino uno board
Microcontroller arduino uno board
Gaurav 243 views
Arduino-Workshop-4.pptx by HebaEng
Arduino-Workshop-4.pptxArduino-Workshop-4.pptx
Arduino-Workshop-4.pptx
HebaEng88 views
pcDuino Presentation at SparkFun by Jingfeng Liu
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
Jingfeng Liu2.4K views
Lab Handson: Power your Creations with Intel Edison! by Codemotion
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
Codemotion2K views
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING by Silvio Cesare
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKINGA BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
A BEGINNER’S JOURNEY INTO THE WORLD OF HARDWARE HACKING
Silvio Cesare5.9K views
Advanced View Arduino Projects List - Use Arduino for Projects {4}.pdf by Ismailkhan77481
Advanced View Arduino Projects List - Use Arduino for Projects {4}.pdfAdvanced View Arduino Projects List - Use Arduino for Projects {4}.pdf
Advanced View Arduino Projects List - Use Arduino for Projects {4}.pdf
Ismailkhan7748115 views
Getting started with arduino workshop by Sudar Muthu
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshop
Sudar Muthu3.6K views
Advanced View of Atmega Microcontroller Projects List - ATMega32 AVR.pdf by WiseNaeem
Advanced View of Atmega Microcontroller Projects List - ATMega32 AVR.pdfAdvanced View of Atmega Microcontroller Projects List - ATMega32 AVR.pdf
Advanced View of Atmega Microcontroller Projects List - ATMega32 AVR.pdf
WiseNaeem3 views
IoT with openHAB on pcDuino3B by Jingfeng Liu
IoT with openHAB on pcDuino3BIoT with openHAB on pcDuino3B
IoT with openHAB on pcDuino3B
Jingfeng Liu3.7K views
Controlling robots using javascript by Sudar Muthu
Controlling robots using javascriptControlling robots using javascript
Controlling robots using javascript
Sudar Muthu7K views
Advanced View Arduino Projects List - Use Arduino for Projects 4.pdf by WiseNaeem
Advanced View Arduino Projects List - Use Arduino for Projects 4.pdfAdvanced View Arduino Projects List - Use Arduino for Projects 4.pdf
Advanced View Arduino Projects List - Use Arduino for Projects 4.pdf
WiseNaeem3 views
Zach Murray CEIS 106 Project by ZacharyMurray8
Zach Murray CEIS 106 ProjectZach Murray CEIS 106 Project
Zach Murray CEIS 106 Project
ZacharyMurray8252 views

More from Sudar Muthu

A quick preview of WP CLI - Chennai WordPress Meetup by
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupSudar Muthu
1.5K views8 slides
WordPress Developer tools by
WordPress Developer toolsWordPress Developer tools
WordPress Developer toolsSudar Muthu
9.1K views23 slides
WordPress Developer Tools to increase productivity by
WordPress Developer Tools to increase productivityWordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivitySudar Muthu
2.1K views23 slides
Unit testing for WordPress by
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPressSudar Muthu
5.2K views27 slides
Unit testing in php by
Unit testing in phpUnit testing in php
Unit testing in phpSudar Muthu
2.1K views19 slides
How arduino helped me in life by
How arduino helped me in lifeHow arduino helped me in life
How arduino helped me in lifeSudar Muthu
2.8K views16 slides

More from Sudar Muthu(20)

A quick preview of WP CLI - Chennai WordPress Meetup by Sudar Muthu
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
Sudar Muthu1.5K views
WordPress Developer tools by Sudar Muthu
WordPress Developer toolsWordPress Developer tools
WordPress Developer tools
Sudar Muthu9.1K views
WordPress Developer Tools to increase productivity by Sudar Muthu
WordPress Developer Tools to increase productivityWordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivity
Sudar Muthu2.1K views
Unit testing for WordPress by Sudar Muthu
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
Sudar Muthu5.2K views
Unit testing in php by Sudar Muthu
Unit testing in phpUnit testing in php
Unit testing in php
Sudar Muthu2.1K views
How arduino helped me in life by Sudar Muthu
How arduino helped me in lifeHow arduino helped me in life
How arduino helped me in life
Sudar Muthu2.8K views
Having fun with hardware by Sudar Muthu
Having fun with hardwareHaving fun with hardware
Having fun with hardware
Sudar Muthu2.6K views
Python in raspberry pi by Sudar Muthu
Python in raspberry piPython in raspberry pi
Python in raspberry pi
Sudar Muthu8K views
Hack 101 at IIT Kanpur by Sudar Muthu
Hack 101 at IIT KanpurHack 101 at IIT Kanpur
Hack 101 at IIT Kanpur
Sudar Muthu1.7K views
PureCSS open hack 2013 by Sudar Muthu
PureCSS open hack 2013PureCSS open hack 2013
PureCSS open hack 2013
Sudar Muthu3.7K views
Arduino Robotics workshop day2 by Sudar Muthu
Arduino Robotics workshop day2Arduino Robotics workshop day2
Arduino Robotics workshop day2
Sudar Muthu9.5K views
Hands on Hadoop and pig by Sudar Muthu
Hands on Hadoop and pigHands on Hadoop and pig
Hands on Hadoop and pig
Sudar Muthu2.6K views
Lets make robots by Sudar Muthu
Lets make robotsLets make robots
Lets make robots
Sudar Muthu2.7K views
Capabilities of Arduino (including Due) by Sudar Muthu
Capabilities of Arduino (including Due)Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
Sudar Muthu2.8K views
Picture perfect hacks with flickr API by Sudar Muthu
Picture perfect hacks with flickr APIPicture perfect hacks with flickr API
Picture perfect hacks with flickr API
Sudar Muthu2.7K views
Capabilities of Arduino by Sudar Muthu
Capabilities of ArduinoCapabilities of Arduino
Capabilities of Arduino
Sudar Muthu5.7K views
Introduction to node.js GDD by Sudar Muthu
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar Muthu7.3K views
Using Javascript in today's world by Sudar Muthu
Using Javascript in today's worldUsing Javascript in today's world
Using Javascript in today's world
Sudar Muthu2.3K views

Recently uploaded

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
146 views15 slides
Uni Systems for Power Platform.pptx by
Uni Systems for Power Platform.pptxUni Systems for Power Platform.pptx
Uni Systems for Power Platform.pptxUni Systems S.M.S.A.
61 views21 slides
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... by
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...ShapeBlue
79 views17 slides
"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
53 views29 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
103 views23 slides
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...ShapeBlue
144 views12 slides

Recently uploaded(20)

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue146 views
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... by ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue79 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue103 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue144 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue222 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu365 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue112 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE69 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue117 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue93 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue176 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software385 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue101 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue123 views

Using arduino and raspberry pi for internet of things

  • 1. Using Arduino and Raspberry Pi for Internet of Things Sudar Muthu (@sudarmuthu) http://hardwarefun.com/ http://github.com/sudar
  • 2. Who am I?  Research Engineer by profession  I build robots as a hobby  Playing with Arduino for more than 4 years  Blogger about Arduino at http://hardwarefun.com  Moderator for Arduino India forum http://hardwarefun.com 2
  • 3. Objective  Introduce Arduino  Introduce Raspberry Pi  Emphasis on IoT  See how both can be used for IoT http://hardwarefun.com 3
  • 5. What is Arduino?  Visual Basic for hardware  Includes both Hardware and software http://hardwarefun.com 5 Photo credit Arduino team
  • 6. Different Arduino types  Arduino Uno (The one I am going to use today)  Arduino Mega  Arduino Due  Lillypad  Arduino BT  Arduino Ethernet  .. and clones http://hardwarefun.com 6
  • 7. Getting to know the Arduino http://hardwarefun.com 7
  • 8. Specs (Uno, Leonardo) Type Value Microcontroller ATmega328 Operating Voltage 5v Digital I/O Pins 14 (of which 6 provide PWM output) Analog Input Pins 6 Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz http://hardwarefun.com 8
  • 9. Identify these components in  Microcontroller  Power jacket  USB jacket  Digital pins  Analog pins  Reset button Arduino http://hardwarefun.com 9
  • 10. Identify these components in Arduino  Voltage Regulator  Power Pins (how many are there?)  Ground Pins (how many are there?)  Vin Pin  Rx and Tx Pins  ICSP Headers http://hardwarefun.com 10
  • 11. Identify these components in  Power Led  Rx and Tx Led’s  Test Led  Crystal  Anything else? Arduino http://hardwarefun.com 11
  • 12. Powering up Arduino http://hardwarefun.com 12
  • 13. Different ways to power up Arduino  Using USB cable  Using DC power jacket  Giving voltage directly into Vin pin  Giving regulated voltage directly into 5V pin http://hardwarefun.com 13
  • 14. Setting up Arduino http://hardwarefun.com 14
  • 15. Testing the setup with a “Hello World” program http://hardwarefun.com 15
  • 17. Making a LED blink  Insert a LED in pin 13  Open File->Examples->Basics->Blink  Select Tools->Boards->Arduino Uno  Select File->Upload (or press ctrl+u)  You should get the message “Done upload”  Your Led should blink  Congrats you can program Arduino now  http://hardwarefun.com 17
  • 18. People with electronics background Did I miss anything? http://hardwarefun.com 18
  • 19. People with electronics background Did I miss anything? Hint: Ohm’s Law http://hardwarefun.com 19
  • 20. Anatomy of an Arduino sketch http://hardwarefun.com 20
  • 21. Printing values through Serial  Uno has one UART hardware port, using which we can exchange information with computer  Very useful for debugging  Works at a specified baud rate  Use Serial Monitor to read values  SoftwareSerial is also available http://hardwarefun.com 21
  • 23. How to use a breadboard  The first two and the last two rows are connected  In all the other rows, columns are connected  Connect the first and last row to power  Connect the second and second last row to ground http://hardwarefun.com 23
  • 24. Digital Input and Output http://hardwarefun.com 24
  • 26. Digital Output The LED blink that we did at “setting up Arduino” is Digital output http://hardwarefun.com 26
  • 28. Reading Analog values from sensors  Connect the LDR on pin A0 and Gnd  LDR’s resistance varies based on the amount of light present  Read the current value using analogRead()  Print the value in Serial Monitor http://hardwarefun.com 28
  • 29. Control an LED based on light void setup(){ pinMode(13, OUTPUT); } void loop(){ int val = analogRead(A0); if (val > 50) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } } http://hardwarefun.com 29
  • 31. Analog Output  What is PWM?  Analog like behavior using digital output  Works by switching the LED on and off regularly  Changing the brightness of a Led http://hardwarefun.com 31
  • 32. This is just the tip of an iceberg http://hardwarefun.com 32 There are tons of other features to Arduino which I have not talked about
  • 33. Internet of Things http://hardwarefun.com 33
  • 34. http://hardwarefun.com 34 "Internet of Things" by Wilgengebroed on Flickr
  • 35. LoT is an overloaded term But I like this definition… “The Internet of Things is the interconnection of uniquely identifiable embedded computing devices within the existing Internet infrastructure” http://hardwarefun.com 35
  • 36. Connecting Arduino to Internet  Ethernet Shield  WIFI Shield  3G Shield  Using another intermediate component http://hardwarefun.com 36
  • 37. Demo of network connectivity using Arduino http://hardwarefun.com 37
  • 38. Let’s take a break  http://hardwarefun.com 38
  • 40. Credit Card Sized Computer http://hardwarefun.com 40
  • 41. GPIO Pins http://hardwarefun.com 41 http://learn.adafruit.com/assets/3052
  • 42. Setup Python sudo apt-get install python-dev sudo apt-get install python-rpi.gpio http://hardwarefun.com 42
  • 43. Set the status of GPIO Pins https://github.com/sudar/r http://hardwarefun.com asp4b3erry-pi-sketches/blob/master/led-blink/led-blink.py
  • 44. Set the status of GPIO Pins import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) try: while True: GPIO.output(12, GPIO.HIGH) time.sleep(1) GPIO.output(12, GPIO.LOW) time.sleep(1) finally: GPIO.cleanup() https://github.com/sudar/raspberry-http://hardwarefun.com 44 pi-sketches/blob/master/led-blink/led-blink.py
  • 45. Demo Let there be Light https://github.com/sudar/r http://hardwarefun.com 45aspberry-pi-sketches/blob/master/led-blink/led-blink.py
  • 46. Changing the brightness of the LED import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) p = GPIO.PWM(12, 50) # channel=12 frequency=50Hz p.start(0) try: while True: for dc in range(0, 101, 5): p.ChangeDutyCycle(dc) time.sleep(0.1) for dc in range(100, -1, -5): p.ChangeDutyCycle(dc) time.sleep(0.1) finally: p.stop() GPIO.cleanup() http://hardwarefun.com 46 https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/pwm.py
  • 47. Demo Can you see the brightness changing? https://github.com/sudar/raspberry-http://hardwarefun.com 47 pi-sketches/blob/master/led-blink/pwm.py
  • 48. Reading the status of the Pin import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) try: while True: if GPIO.input(11): print "Button is on" else: print "Button is off" time.sleep(0.1) finally: GPIO.cleanup() http://hardwarefun.com 48 https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
  • 49. Reading the status of the Pin http://hardwarefun.com 49 https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
  • 50. Demo What happens when the button is pressed? http://hardwarefun.com 50 https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
  • 51. Combining Input and Output import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(12, GPIO.OUT) try: while True: if GPIO.input(11): print "Button is on" GPIO.output(12, 1) else: GPIO.output(12, 0) time.sleep(0.1) finally: GPIO.cleanup() http://hardwarefun.com 51 https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
  • 52. Combining Input and Output http://hardwarefun.com 52 https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
  • 53. Demo Let’s control the LED by pressing the button http://hardwarefun.com 53 https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
  • 54. What more can be done? http://hardwarefun.com 54
  • 55. More protocols  I2C  SPI  Serial http://hardwarefun.com 55
  • 56. Interacting with webcam  “PyGame” provides easy interface  Can get fancy using “opencv”  Both USB and GPIO interface are supported http://hardwarefun.com 56
  • 57. Distributed Computing  Each Pi can be used as cheap node  Form grids using a cluster of Pi’s  Can share CPU, memory and disk space http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/ distributed-computing/ http://hardwarefun.com 57
  • 58. Limitations  No built-in Analog to Digital support  Can’t run Inductive load (motors)  Is not real-time (CPU might be busy)  No “safe circuits” present  Operates at 3.3V and is not directly compatible with Arduino voltage http://hardwarefun.com 58
  • 59. Arduino vs Raspberry Pi for IoT http://hardwarefun.com 59
  • 60. Advantages of Raspberry Pi  Entire Linux software stack is available  It is very easy to connect to internet  Can be programmed using variety of programming languages http://hardwarefun.com 60
  • 61. Disadvantage of Raspberry Pi  Accessing hardware is not real-time. If the CPU is busy, then interfacing with hardware can be delayed  No built-in Analog to Digital converter available  Does not have enough power to drive inductive loads  The hardware design is not open source. Even though it is not a big deal, for some people it might a deal breaker http://hardwarefun.com 61
  • 62. Advantages of Arduino  Very easy to get started  Very easy to extend it and has tons of user contributed shields and libraries. Shields are available to do pretty much anything  Can be used to for real-time applications  Everything (both hardware, software and IDE) are open source  Not much programming knowledge needed to do basic stuff http://hardwarefun.com 62
  • 63. Disadvantages of Arduino  Not very powerful when compared with Raspberry Pi (Micro processor vs Micro controller)  You need to program using either Arduino or C/C++ (or assembly if you really want to)  Connecting to internet is slightly difficult (you have shields and libraries, but is not straight forward), but not impossible. http://hardwarefun.com 63
  • 64. In Short.. Feature Raspberry Pi Arduino Processor Speed 700 MHz 16 MHz Programming Language No limit Arduino, C/C++ Real-time Hardware No real-time In real-time Analog to Digital Convertor No Yes Hardware Design Closed source Open source Internet Connection Very easy Not easy, but doable http://hardwarefun.com 64
  • 66. Use both together  Best of both worlds http://hardwarefun.com 66 http://learn.adafruit.com/assets/3199 http://learn.adafruit.com/assets/2123
  • 67. Links  Source code - https://github.com/sudar/raspberry-pi-sketches/  My blog - http://hardwarefun.com  Python GPIO - https://code.google.com/p/raspberry-gpio- python/  Distributed computing using Pi - http://www.cl.cam.ac.uk/projects/raspberrypi/tutorial s/distributed-computing/ http://hardwarefun.com 67
  • 68. Links  Arduino – http://arduino.cc  Asimi – A simple bot using Arduino http://hardwarefun.com/project/asimi  Getting started with hardware programming http://hardwarefun.com/tutorials/getting-started-with-hardware- programming  Getting started with Arduino http://hardwarefun.com/tutorials/getting-started-with-arduino- and-avr http://hardwarefun.com 68
  • 69. Questions Thank You Sudar Muthu (@sudarmuthu) http://hardwarefun.com/ https://github.com/sudar/arduino-robotics-workshop https://github.com/sudar/raspberry-pi-sketches http://hardwarefun.com 69

Editor's Notes

  1. "Internet of Things" by Wilgengebroed on Flickr - Cropped and sign removed from Internet of things signed by the author.jpg. Licensed under Creative Commons Attribution 2.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Internet_of_Things.jpg#mediaviewer/File:Internet_of_Things.jpg