SlideShare a Scribd company logo
1
Raspberry Pi Tutorial #2
- Measuring the light -
Dong Ho Son
POSTECH
Pohang, Korea
donghoson@postech.ac.kr
2
Measuring the light - Overview
 Let’s use the sensor
• Sensor : Analog  Digital
− Analog : continuous
− Digital : discrete
• Photoresistor 3 pin (or light-dependent resistor, LDR)
− A light-controlled variable resistor
− The resistance increases/decreases according to the brightness of light
• Let’s configure the circuit
− The brightness of the LED is changed according to the brightness of the environment
− If dark, the LED is turned on
− If bright, the LED is turned off
3
Measuring the light - Overview
 Measure the brightness of light and turn on/off the LED
 Necessary Components
• 1 x Raspberry Pi
• 1 x Breadboard
• 1 x red LED
• 1 x Resistor
• 1 x Photoresistor 3 pin
• Jumper cables
Anode
Cathode
GND
OUT
VCC
4
Measuring the light – Circuit configuration
 Ground pin  the cathode of the LED
 The anode of the LED  a ballast resistor
 The ballast resistor  the pin GPIO 18
 VCC of photoresistor  3.3V
 OUT of photoresistor  the pin GPIO 17
 GND of photoresistor  Ground pin
Cathode Anode
5
Measuring the light - Python
 Import RPi.GPIO as GPIO
• Import Python GPIO module
 GPIO.setmode(GPIO.BCM)
• Use Broadcom chip number
 GPIO.setup(17, GPIO.IN)
• Select GPIO #17 as input pin
• Measure the brightness using sensor
 GPIO.setup(18, GPIO.OUT)
• Select GPIO #18 as output pin
• Turn on/off the LED
6
Measuring the light - Python
 GPIO.input(17)
• Return 0(bright) or 1(dark)
 GPIO.output(18, GPIO.LOW)
• Turn off the LED
 GPIO.output(18, GPIO.HIGH)
• Turn on the LED
 time.sleep(1)
• Delay for 1 second
7
Measuring the light - Result
 If bright, the LED is turned off
 If dark, the LED is turned on
Cathode Anode

More Related Content

Similar to Raspberry pi tutorial #2

Basics of elec.
Basics of elec.Basics of elec.
Basics of elec.
Nitesh Singh
 
Basics of elec.
Basics of elec.Basics of elec.
Basics of elec.
Shivani Pakal
 
Measurements upload
Measurements uploadMeasurements upload
Measurements upload
Nandana Priyanka Eluri
 
Simplest Continuity Tester
Simplest Continuity TesterSimplest Continuity Tester
Simplest Continuity Tester
Muhammad Khan
 
Automatic street light circuit using ldr
Automatic street light circuit using ldrAutomatic street light circuit using ldr
Automatic street light circuit using ldr
SmartxProKits
 
Automatic street light using ldr and relay
Automatic street light using ldr and relayAutomatic street light using ldr and relay
Automatic street light using ldr and relay
Shivam Raidas
 
Chapter33 (1).ppt
Chapter33 (1).pptChapter33 (1).ppt
Chapter33 (1).ppt
Chetan253021
 
Basics of electronics
Basics of electronicsBasics of electronics
Basics of electronics
Patruni Chidananda Sastry
 
Basics of elec.
Basics of elec.Basics of elec.
Basics of elec.
Ashish Kholia
 
Automatic light control Using LDR
Automatic light control Using LDRAutomatic light control Using LDR
Automatic light control Using LDR
Badrul Alam
 
FUNDAMENTAL OF ELECTRONICS AND HARDWARE
FUNDAMENTAL OF ELECTRONICS AND HARDWAREFUNDAMENTAL OF ELECTRONICS AND HARDWARE
FUNDAMENTAL OF ELECTRONICS AND HARDWARE
Vikrant Thakur
 
lab_2.pdf
lab_2.pdflab_2.pdf
BASIC ELECTRONICSBasic electronics a by abdul rahaman
BASIC ELECTRONICSBasic electronics a by abdul rahamanBASIC ELECTRONICSBasic electronics a by abdul rahaman
BASIC ELECTRONICSBasic electronics a by abdul rahaman
Abdul45678
 
ELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMER
ELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMERELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMER
ELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMER
Kesagani Ranga Uma Maheshwar Rao
 
Basic_electronics (2).pptx
Basic_electronics (2).pptxBasic_electronics (2).pptx
Basic_electronics (2).pptx
MadhuriKulkarni21
 
IoT_IO1_3 Getting familiar with Hardware - Sensors.pdf
IoT_IO1_3 Getting familiar with Hardware - Sensors.pdfIoT_IO1_3 Getting familiar with Hardware - Sensors.pdf
IoT_IO1_3 Getting familiar with Hardware - Sensors.pdf
DanishMahmood23
 
21ELN24 [PROJECT ].pptx
21ELN24 [PROJECT ].pptx21ELN24 [PROJECT ].pptx
21ELN24 [PROJECT ].pptx
TLRTHR
 
PRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptx
PRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptxPRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptx
PRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptx
NURHADIALHAKIMBINISM
 
Analog Electronics ppt on Photo Diodes and LED by Being topper
Analog Electronics  ppt on Photo Diodes  and LED by Being topperAnalog Electronics  ppt on Photo Diodes  and LED by Being topper
Analog Electronics ppt on Photo Diodes and LED by Being topper
Vipin Kumar
 
report on intelligent energy conservation system
report on intelligent energy conservation system report on intelligent energy conservation system
report on intelligent energy conservation system
vyomesh upadhyay
 

Similar to Raspberry pi tutorial #2 (20)

Basics of elec.
Basics of elec.Basics of elec.
Basics of elec.
 
Basics of elec.
Basics of elec.Basics of elec.
Basics of elec.
 
Measurements upload
Measurements uploadMeasurements upload
Measurements upload
 
Simplest Continuity Tester
Simplest Continuity TesterSimplest Continuity Tester
Simplest Continuity Tester
 
Automatic street light circuit using ldr
Automatic street light circuit using ldrAutomatic street light circuit using ldr
Automatic street light circuit using ldr
 
Automatic street light using ldr and relay
Automatic street light using ldr and relayAutomatic street light using ldr and relay
Automatic street light using ldr and relay
 
Chapter33 (1).ppt
Chapter33 (1).pptChapter33 (1).ppt
Chapter33 (1).ppt
 
Basics of electronics
Basics of electronicsBasics of electronics
Basics of electronics
 
Basics of elec.
Basics of elec.Basics of elec.
Basics of elec.
 
Automatic light control Using LDR
Automatic light control Using LDRAutomatic light control Using LDR
Automatic light control Using LDR
 
FUNDAMENTAL OF ELECTRONICS AND HARDWARE
FUNDAMENTAL OF ELECTRONICS AND HARDWAREFUNDAMENTAL OF ELECTRONICS AND HARDWARE
FUNDAMENTAL OF ELECTRONICS AND HARDWARE
 
lab_2.pdf
lab_2.pdflab_2.pdf
lab_2.pdf
 
BASIC ELECTRONICSBasic electronics a by abdul rahaman
BASIC ELECTRONICSBasic electronics a by abdul rahamanBASIC ELECTRONICSBasic electronics a by abdul rahaman
BASIC ELECTRONICSBasic electronics a by abdul rahaman
 
ELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMER
ELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMERELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMER
ELECTRONIC EYE FOR NIGHT DEVICE SWITCHING USING 555 TIMER
 
Basic_electronics (2).pptx
Basic_electronics (2).pptxBasic_electronics (2).pptx
Basic_electronics (2).pptx
 
IoT_IO1_3 Getting familiar with Hardware - Sensors.pdf
IoT_IO1_3 Getting familiar with Hardware - Sensors.pdfIoT_IO1_3 Getting familiar with Hardware - Sensors.pdf
IoT_IO1_3 Getting familiar with Hardware - Sensors.pdf
 
21ELN24 [PROJECT ].pptx
21ELN24 [PROJECT ].pptx21ELN24 [PROJECT ].pptx
21ELN24 [PROJECT ].pptx
 
PRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptx
PRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptxPRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptx
PRESENTATION PRACTICAL TASK (A) MINI PROJECT-2.pptx
 
Analog Electronics ppt on Photo Diodes and LED by Being topper
Analog Electronics  ppt on Photo Diodes  and LED by Being topperAnalog Electronics  ppt on Photo Diodes  and LED by Being topper
Analog Electronics ppt on Photo Diodes and LED by Being topper
 
report on intelligent energy conservation system
report on intelligent energy conservation system report on intelligent energy conservation system
report on intelligent energy conservation system
 

More from 동호 손

Raspberry pi : how to get started
Raspberry pi : how to get startedRaspberry pi : how to get started
Raspberry pi : how to get started
동호 손
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
동호 손
 
Arduino tutorial #1
Arduino tutorial #1Arduino tutorial #1
Arduino tutorial #1
동호 손
 
Arduino : how to get started
Arduino : how to get startedArduino : how to get started
Arduino : how to get started
동호 손
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
동호 손
 
OpenVirtex (OVX) Tutorial
OpenVirtex (OVX) TutorialOpenVirtex (OVX) Tutorial
OpenVirtex (OVX) Tutorial
동호 손
 

More from 동호 손 (6)

Raspberry pi : how to get started
Raspberry pi : how to get startedRaspberry pi : how to get started
Raspberry pi : how to get started
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
 
Arduino tutorial #1
Arduino tutorial #1Arduino tutorial #1
Arduino tutorial #1
 
Arduino : how to get started
Arduino : how to get startedArduino : how to get started
Arduino : how to get started
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
OpenVirtex (OVX) Tutorial
OpenVirtex (OVX) TutorialOpenVirtex (OVX) Tutorial
OpenVirtex (OVX) Tutorial
 

Recently uploaded

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 

Recently uploaded (20)

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 

Raspberry pi tutorial #2

  • 1. 1 Raspberry Pi Tutorial #2 - Measuring the light - Dong Ho Son POSTECH Pohang, Korea donghoson@postech.ac.kr
  • 2. 2 Measuring the light - Overview  Let’s use the sensor • Sensor : Analog  Digital − Analog : continuous − Digital : discrete • Photoresistor 3 pin (or light-dependent resistor, LDR) − A light-controlled variable resistor − The resistance increases/decreases according to the brightness of light • Let’s configure the circuit − The brightness of the LED is changed according to the brightness of the environment − If dark, the LED is turned on − If bright, the LED is turned off
  • 3. 3 Measuring the light - Overview  Measure the brightness of light and turn on/off the LED  Necessary Components • 1 x Raspberry Pi • 1 x Breadboard • 1 x red LED • 1 x Resistor • 1 x Photoresistor 3 pin • Jumper cables Anode Cathode GND OUT VCC
  • 4. 4 Measuring the light – Circuit configuration  Ground pin  the cathode of the LED  The anode of the LED  a ballast resistor  The ballast resistor  the pin GPIO 18  VCC of photoresistor  3.3V  OUT of photoresistor  the pin GPIO 17  GND of photoresistor  Ground pin Cathode Anode
  • 5. 5 Measuring the light - Python  Import RPi.GPIO as GPIO • Import Python GPIO module  GPIO.setmode(GPIO.BCM) • Use Broadcom chip number  GPIO.setup(17, GPIO.IN) • Select GPIO #17 as input pin • Measure the brightness using sensor  GPIO.setup(18, GPIO.OUT) • Select GPIO #18 as output pin • Turn on/off the LED
  • 6. 6 Measuring the light - Python  GPIO.input(17) • Return 0(bright) or 1(dark)  GPIO.output(18, GPIO.LOW) • Turn off the LED  GPIO.output(18, GPIO.HIGH) • Turn on the LED  time.sleep(1) • Delay for 1 second
  • 7. 7 Measuring the light - Result  If bright, the LED is turned off  If dark, the LED is turned on Cathode Anode