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
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
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
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
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
Sensors, actuators and the Raspberry PI using Python
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)
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
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"
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
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

PPT
IoT with Arduino
PPTX
Raspberry Pi Introduction
PPTX
Introduction to Node MCU
PPTX
Arduino: On-board components description, IDE and Programming
PDF
Introduction to arm architecture
PPTX
Arduino Interfacing with different sensors and motor
PPTX
Raspberry pi
PPTX
Introduction to Arduino
IoT with Arduino
Raspberry Pi Introduction
Introduction to Node MCU
Arduino: On-board components description, IDE and Programming
Introduction to arm architecture
Arduino Interfacing with different sensors and motor
Raspberry pi
Introduction to Arduino

What's hot (20)

PPT
Raspberry pi 3
PPTX
Arduino uno lcd display 16x2
PPTX
PDF
Avr instruction set
PDF
Introduction to Raspberrypi
PPT
Interfacing adc
PDF
Esp8266 basics
PPT
Embedded System Basics
PDF
Introduction to ESP32 Programming [Road to RIoT 2017]
PDF
Arduino Workshop Day 2 - Advance Arduino & DIY
PPTX
temperature control using 8086 microprocessor by vikas arya
PPTX
Introduction to Arduino Hardware and Programming
PPTX
Module 2 ARM CORTEX M3 Instruction Set and Programming
PPTX
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
PPTX
Interrupts in pic
PPT
Microprocessors and microcontrollers
PPTX
Raspberry pi
PPT
Memory organization of 8051
PPT
Intro to Arduino
PDF
Embedded systems basics
Raspberry pi 3
Arduino uno lcd display 16x2
Avr instruction set
Introduction to Raspberrypi
Interfacing adc
Esp8266 basics
Embedded System Basics
Introduction to ESP32 Programming [Road to RIoT 2017]
Arduino Workshop Day 2 - Advance Arduino & DIY
temperature control using 8086 microprocessor by vikas arya
Introduction to Arduino Hardware and Programming
Module 2 ARM CORTEX M3 Instruction Set and Programming
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Interrupts in pic
Microprocessors and microcontrollers
Raspberry pi
Memory organization of 8051
Intro to Arduino
Embedded systems basics
Ad

Viewers also liked (8)

PPTX
Sensors and Actuators
PPTX
Internet of Things
PDF
92058 sensors transducers and actuators
PPSX
Mechanical sensors 2
PPTX
Mechanical sensor
PDF
Introduction to Windows IoT via Raspberry Pi 3
PPTX
Internet of things using Raspberry Pi
PPTX
The Future of Embedded and IoT Security: Kaspersky Operating System
Sensors and Actuators
Internet of Things
92058 sensors transducers and actuators
Mechanical sensors 2
Mechanical sensor
Introduction to Windows IoT via Raspberry Pi 3
Internet of things using Raspberry Pi
The Future of Embedded and IoT Security: Kaspersky Operating System
Ad

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

PDF
4. GPIO Access
PDF
Getting Started With Raspberry Pi - UCSD 2013
PDF
IoT Physical Devices and End Points.pdf
PDF
Getting Started with Raspberry Pi - USC 2013
PPTX
Raspberry pi
PDF
Ins and Outs of GPIO Programming
 
PPTX
Python in raspberry pi
PPTX
Python-in-Embedded-systems.pptx
PPTX
Raspberry pi led blink
PPTX
Raspberry Pi Sensors Tutorial
PDF
Introduction to Raspberry Pi
PDF
Intro to the raspberry pi board
PPTX
Not so hard hardware
ODP
Introduction to Raspberry Pi and GPIO
PPTX
[5]投影片 futurewad樹莓派研習會 141218
PDF
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
PDF
Intoduction to physical computing using Raspberry Pi, 18-02-2016
PPTX
Custard pi 7 user information
PDF
Getting Started with Raspberry Pi - DCC 2013.1
PPT
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING
4. GPIO Access
Getting Started With Raspberry Pi - UCSD 2013
IoT Physical Devices and End Points.pdf
Getting Started with Raspberry Pi - USC 2013
Raspberry pi
Ins and Outs of GPIO Programming
 
Python in raspberry pi
Python-in-Embedded-systems.pptx
Raspberry pi led blink
Raspberry Pi Sensors Tutorial
Introduction to Raspberry Pi
Intro to the raspberry pi board
Not so hard hardware
Introduction to Raspberry Pi and GPIO
[5]投影片 futurewad樹莓派研習會 141218
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Intoduction to physical computing using Raspberry Pi, 18-02-2016
Custard pi 7 user information
Getting Started with Raspberry Pi - DCC 2013.1
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING

Recently uploaded (20)

PPTX
Embedded for Artificial Intelligence 1.pptx
PPTX
ERP good ERP good ERP good ERP good good ERP good ERP good
PPTX
executive branch_no record.pptxsvvsgsggs
PDF
Prescription1 which to be used for periodo
PDF
Chapter -24-By Dr Sajid Ali Ansari 2021.pdf
PDF
How NGOs Save Costs with Affordable IT Rentals
PPTX
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
PPTX
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew
PPT
Welcome-to-Information-Technology.pptx.ppt
PPTX
PROGRAMMING-QUARTER-2-PYTHON.pptxnsnsndn
PDF
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
PPTX
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
PDF
Smarter Security: How Door Access Control Works with Alarms & CCTV
PPTX
udi-benefits-ggggggggfor-healthcare.pptx
PPT
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
PPTX
IOT piching HEALTH MONITORING SYSTEM USING ARDUINO123.pptx
PPTX
Embeded System for Artificial intelligence 2.pptx
PPTX
code of ethics.pptxdvhwbssssSAssscasascc
PPTX
title _yeOPC_Poisoning_Presentation.pptx
PPTX
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx
Embedded for Artificial Intelligence 1.pptx
ERP good ERP good ERP good ERP good good ERP good ERP good
executive branch_no record.pptxsvvsgsggs
Prescription1 which to be used for periodo
Chapter -24-By Dr Sajid Ali Ansari 2021.pdf
How NGOs Save Costs with Affordable IT Rentals
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew
Welcome-to-Information-Technology.pptx.ppt
PROGRAMMING-QUARTER-2-PYTHON.pptxnsnsndn
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
Smarter Security: How Door Access Control Works with Alarms & CCTV
udi-benefits-ggggggggfor-healthcare.pptx
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
IOT piching HEALTH MONITORING SYSTEM USING ARDUINO123.pptx
Embeded System for Artificial intelligence 2.pptx
code of ethics.pptxdvhwbssssSAssscasascc
title _yeOPC_Poisoning_Presentation.pptx
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx

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
  • 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
  • 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
  • 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)
  • 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"
  • 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)