SlideShare a Scribd company logo
Sensors, actuators and the
Raspberry PI
Programming GPIO using Python
Raspberry PI vs Desktop PC
• Smaller footprint
• Slower processor

Less memory

Non-standard peripherals
Using GPIO – output mode
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # refer to GPIO pins
GPIO.setwarnings(False) # ignore warnings
GPIO.setup(pin, GPIO.OUT) # make GPIO pin for output
GPIO.output(pin, GPIO.HIGH) # turn ON GPIO pin
GPIO.output(pin, GPIO.LOW) # turn OFF GPIO pin
Using GPIO – input mode
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # refer to GPIO pins
GPIO.setwarnings(False) # ignore warnings
GPIO.setup(pin, GPIO.IN) # make GPIO pin for input
val = GPIO.input(pin) # read GPIO pin
Relay Connections
Relay board Raspberry PI
GND 6
IN1 15 (GPIO 22)
IN2 16 (GPIO 23)
IN3 18 (GPIO 24)
IN4 22 (GPIO 25)
VCC 2
Relay controller sample code
import RPi.GPIO as GPIO
import time
pins = [22,23,24,25]
for p in pins:
GPIO.setup(p, GPIO.OUT)
while True:
for q in pins:
GPIO.output(q, GPIO.HIGH)
time.sleep(5)
for q in pins:
GPIO.output(q, GPIO.LOW)
time.sleep(5)
Sensor Connections
Sensor board Raspberry PI
GND 6
OUT 11 (GPIO 17)
VCC 2
Sensor sample code
pin = 17
GPIO.setup(pin, GPIO.IN) # make GPIO pin for input
state = GPIO.input(pin) # read GPIO pin
while True:
time.sleep(1)
r = GPIO.input(pin)
if (r != state):
state = r
print "state changed"
AD/DA board connections
AD/DA board Raspberry PI
SDA 3
SCL 5
VCC 2
GND 6
Convertor sample code
import smbus
def read(a):
bus.read_byte_data(0x48, a)
return bus.read_data(0x48)
bus = smbus.SMBus(1)
control = read(0)
light = read(1)
temperature = read(2)
custom = read(3)
bus.write_byte(self.addr, 99)
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python

More Related Content

What's hot

Introduction to ARM LPC2148
Introduction to ARM LPC2148Introduction to ARM LPC2148
Introduction to ARM LPC2148
Veera Kumar
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Richard Rixham
 
Raspberrypi best ppt
Raspberrypi best ppt Raspberrypi best ppt
Raspberrypi best ppt
SOMRAJ GAUTAM
 
Introduction to Arduino Programming
Introduction to Arduino ProgrammingIntroduction to Arduino Programming
Introduction to Arduino Programming
James Lewis
 
Arduino uno
Arduino unoArduino uno
Arduino uno
creatjet3d labs
 
Arduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic ArduinoArduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic Arduino
Vishnu
 
Buzzer
BuzzerBuzzer
Arduino Microcontroller
Arduino MicrocontrollerArduino Microcontroller
Arduino Microcontroller
Shyam Mohan
 
PPT ON Arduino
PPT ON Arduino PPT ON Arduino
PPT ON Arduino
Ravi Phadtare
 
NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1
Andy Gelme
 
Basics of arduino uno
Basics of arduino unoBasics of arduino uno
Basics of arduino uno
Rahat Sood
 
Esp8266 NodeMCU
Esp8266 NodeMCUEsp8266 NodeMCU
Esp8266 NodeMCU
roadster43
 
Arduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIYArduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIY
Vishnu
 
Presentation on Raspberry pi
Presentation on Raspberry piPresentation on Raspberry pi
Presentation on Raspberry pi
OpenDev
 
PIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC InterfacingPIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC Interfacing
International Institute of Information Technology (I²IT)
 
Lesson sample introduction to arduino
Lesson sample   introduction to arduinoLesson sample   introduction to arduino
Lesson sample introduction to arduino
Betsy Eng
 
ARM Micro-controller
ARM Micro-controllerARM Micro-controller
ARM Micro-controller
Ravikumar Tiwari
 
Arduino vs Raspberry Pi
Arduino vs Raspberry PiArduino vs Raspberry Pi
Arduino vs Raspberry Pi
Jitendra Adhikari
 
introduction of arduino and node mcu
introduction of arduino and node mcuintroduction of arduino and node mcu
introduction of arduino and node mcu
6305HASANBASARI
 

What's hot (20)

Introduction to ARM LPC2148
Introduction to ARM LPC2148Introduction to ARM LPC2148
Introduction to ARM LPC2148
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Raspberrypi best ppt
Raspberrypi best ppt Raspberrypi best ppt
Raspberrypi best ppt
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino Programming
Introduction to Arduino ProgrammingIntroduction to Arduino Programming
Introduction to Arduino Programming
 
Arduino uno
Arduino unoArduino uno
Arduino uno
 
Arduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic ArduinoArduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic Arduino
 
Buzzer
BuzzerBuzzer
Buzzer
 
Arduino Microcontroller
Arduino MicrocontrollerArduino Microcontroller
Arduino Microcontroller
 
PPT ON Arduino
PPT ON Arduino PPT ON Arduino
PPT ON Arduino
 
NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1
 
Basics of arduino uno
Basics of arduino unoBasics of arduino uno
Basics of arduino uno
 
Esp8266 NodeMCU
Esp8266 NodeMCUEsp8266 NodeMCU
Esp8266 NodeMCU
 
Arduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIYArduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIY
 
Presentation on Raspberry pi
Presentation on Raspberry piPresentation on Raspberry pi
Presentation on Raspberry pi
 
PIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC InterfacingPIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC Interfacing
 
Lesson sample introduction to arduino
Lesson sample   introduction to arduinoLesson sample   introduction to arduino
Lesson sample introduction to arduino
 
ARM Micro-controller
ARM Micro-controllerARM Micro-controller
ARM Micro-controller
 
Arduino vs Raspberry Pi
Arduino vs Raspberry PiArduino vs Raspberry Pi
Arduino vs Raspberry Pi
 
introduction of arduino and node mcu
introduction of arduino and node mcuintroduction of arduino and node mcu
introduction of arduino and node mcu
 

Viewers also liked

Sensors and Actuators
Sensors and Actuators Sensors and Actuators
Sensors and Actuators
Aamir Shaikh
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
Rainmaker Ho
 
92058 sensors transducers and actuators
92058 sensors transducers and actuators92058 sensors transducers and actuators
92058 sensors transducers and actuators
kumar19792
 
Mechanical sensor
Mechanical sensorMechanical sensor
Mechanical sensor
B.k. Das
 
Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3
Lee Richardson
 
Internet of things using Raspberry Pi
Internet of things using Raspberry PiInternet of things using Raspberry Pi
Internet of things using Raspberry Pi
Yash Gajera
 
The Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating SystemThe Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating System
Kaspersky Lab
 

Viewers also liked (8)

Sensors and Actuators
Sensors and Actuators Sensors and Actuators
Sensors and Actuators
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 
92058 sensors transducers and actuators
92058 sensors transducers and actuators92058 sensors transducers and actuators
92058 sensors transducers and actuators
 
Mechanical sensors 2
Mechanical sensors 2Mechanical sensors 2
Mechanical sensors 2
 
Mechanical sensor
Mechanical sensorMechanical sensor
Mechanical sensor
 
Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3Introduction to Windows IoT via Raspberry Pi 3
Introduction to Windows IoT via Raspberry Pi 3
 
Internet of things using Raspberry Pi
Internet of things using Raspberry PiInternet of things using Raspberry Pi
Internet of things using Raspberry Pi
 
The Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating SystemThe Future of Embedded and IoT Security: Kaspersky Operating System
The Future of Embedded and IoT Security: Kaspersky Operating System
 

Similar to Sensors, actuators and the Raspberry PI using Python

Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3
Dnyanesh Patil
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
vishal choudhary
 
PPT+.pdf
PPT+.pdfPPT+.pdf
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development
FastBit Embedded Brain Academy
 
4. GPIO Access
4. GPIO Access4. GPIO Access
4. GPIO Access
Mayank Joneja
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
CAVEDU Education
 
Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO Programming
ICS
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Tom Paulus
 
Atomic pi Mini PC
Atomic pi Mini PCAtomic pi Mini PC
Atomic pi Mini PC
Dwika Sudrajat
 
Atomic PI apug
Atomic PI apugAtomic PI apug
Atomic PI apug
Dwika Sudrajat
 
Day4
Day4Day4
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
savageautomate
 
Raspberry pi tutorial #1
Raspberry pi tutorial #1Raspberry pi tutorial #1
Raspberry pi tutorial #1
동호 손
 
Project ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN GPIO mediator introduction
Project ACRN GPIO mediator introduction
Project ACRN
 
F9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets ledF9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets led
Benux Wei
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
RICELEEIO
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry Pi
Neil Broers
 
Raspberry pi and pi4j
Raspberry pi and pi4jRaspberry pi and pi4j
Raspberry pi and pi4j
Narendran Solai Sridharan
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
ABHIJITPATRA23
 

Similar to Sensors, actuators and the Raspberry PI using Python (20)

Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
 
PPT+.pdf
PPT+.pdfPPT+.pdf
PPT+.pdf
 
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development
 
4. GPIO Access
4. GPIO Access4. GPIO Access
4. GPIO Access
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO Programming
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
 
Atomic pi Mini PC
Atomic pi Mini PCAtomic pi Mini PC
Atomic pi Mini PC
 
Atomic PI apug
Atomic PI apugAtomic PI apug
Atomic PI apug
 
Day4
Day4Day4
Day4
 
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
 
Raspberry pi tutorial #1
Raspberry pi tutorial #1Raspberry pi tutorial #1
Raspberry pi tutorial #1
 
Project ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN GPIO mediator introduction
Project ACRN GPIO mediator introduction
 
F9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets ledF9 microkernel app development part 2 gpio meets led
F9 microkernel app development part 2 gpio meets led
 
PPT+.pdf
PPT+.pdfPPT+.pdf
PPT+.pdf
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry Pi
 
Raspberry pi and pi4j
Raspberry pi and pi4jRaspberry pi and pi4j
Raspberry pi and pi4j
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
 

Sensors, actuators and the Raspberry PI using Python

  • 1. Sensors, actuators and the Raspberry PI Programming GPIO using Python
  • 2. Raspberry PI vs Desktop PC • Smaller footprint • Slower processor  Less memory  Non-standard peripherals
  • 3.
  • 4.
  • 5.
  • 6. Using GPIO – output mode import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # refer to GPIO pins GPIO.setwarnings(False) # ignore warnings GPIO.setup(pin, GPIO.OUT) # make GPIO pin for output GPIO.output(pin, GPIO.HIGH) # turn ON GPIO pin GPIO.output(pin, GPIO.LOW) # turn OFF GPIO pin
  • 7. Using GPIO – input mode import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # refer to GPIO pins GPIO.setwarnings(False) # ignore warnings GPIO.setup(pin, GPIO.IN) # make GPIO pin for input val = GPIO.input(pin) # read GPIO pin
  • 8.
  • 9.
  • 10.
  • 11. Relay Connections Relay board Raspberry PI GND 6 IN1 15 (GPIO 22) IN2 16 (GPIO 23) IN3 18 (GPIO 24) IN4 22 (GPIO 25) VCC 2
  • 12.
  • 13. Relay controller sample code import RPi.GPIO as GPIO import time pins = [22,23,24,25] for p in pins: GPIO.setup(p, GPIO.OUT) while True: for q in pins: GPIO.output(q, GPIO.HIGH) time.sleep(5) for q in pins: GPIO.output(q, GPIO.LOW) time.sleep(5)
  • 14.
  • 15.
  • 16.
  • 17. Sensor Connections Sensor board Raspberry PI GND 6 OUT 11 (GPIO 17) VCC 2
  • 18. Sensor sample code pin = 17 GPIO.setup(pin, GPIO.IN) # make GPIO pin for input state = GPIO.input(pin) # read GPIO pin while True: time.sleep(1) r = GPIO.input(pin) if (r != state): state = r print "state changed"
  • 19.
  • 20.
  • 21. AD/DA board connections AD/DA board Raspberry PI SDA 3 SCL 5 VCC 2 GND 6
  • 22. Convertor sample code import smbus def read(a): bus.read_byte_data(0x48, a) return bus.read_data(0x48) bus = smbus.SMBus(1) control = read(0) light = read(1) temperature = read(2) custom = read(3) bus.write_byte(self.addr, 99)