SlideShare a Scribd company logo
1 of 7
1
Arduino Tutorial #3
- Measuring the light -
Dong Ho Son
POSTECH
Pohang, Korea
donghoson@postech.ac.kr
2
Measuring the light - Overview
 Sensor: Analog  Digital
• Analog : continuous
• Digital : discrete
 Photoresistor (or Light-Dependent Resistor, LDR)
• A light-controlled variable resistor
• The resistance increases/decreases according to the brightness
 Let’s configure the circuit
• The brightness of the LED is changed according to the brightness of the
environment
• If dark, the LED also would be dark
• If bright, the LED also would be bright
source: wikimedia.org
3
Measure the light - Circuit
 Configure the circuit
+-
2kΩ
220Ω
Source: pixabay.com/photo-2168193
4
Measuring the light - Sketch (1/3)
 setup() { }
• pinMode(10, OUTPUT);
− Prepare the mode of pin
− We will use pin #10
− We will order to LED  OUTPUT
• Serial.begin(9600);
− Prepare the serial communication to get
the value of light from the sensor
− 9600: serial communication speed
– 9600 bits per second is the default for the Arduino
5
Measuring the light - Sketch (2/3)
 loop() { }
• int val = analogRead(A4);
− Read the analog value of light
• analogWrite(10, val/4);
− Turn on the LED
− Different from digitalWrite();
– digitalWrite(); just has HIGH or LOW
− Brightness of LED is controlled by ‘val/4’
− val  10 bit , val/4  8 bit
− analogWrite() uses 8 bit of digital pin
6
Measuring the light - Sketch (3/3)
 loop() { }
• Serial.print(“ Brightness = ”);
− It prints the text “ Bightness = ”
to the serial console
• Serial.println(val/4);
− It prints the value of ‘val/4’ to the serial console
− Also changes the line (newline)
• Delay(10);
− Need 10ms to check step-by-step
7
Measuring the light - Result
 The brightness of the LED is being changed!
+-
Brightness = 127
Brightness = 153
Brightness = 128
Brightness = 156
Brightness = 127
Brightness = 156
Brightness = 127
Brightness = 156
Brightness = 125
Brightness = 155
Brightness = 124
Brightness = 158
Brightness = 129
Brightness = 156
Brightness = 127
Brightness = 153
Brightness = 125
Source: pixabay
2kΩ
220Ω
Source: pixabay.com/photo-2168193

More Related Content

Similar to Arduino tutorial #3

arduinoworkshop-160204051621.pdf
arduinoworkshop-160204051621.pdfarduinoworkshop-160204051621.pdf
arduinoworkshop-160204051621.pdfAbdErrezakChahoub
 
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
UNIT 4 & 5 - I         nterfacing_Lecture7.pptxUNIT 4 & 5 - I         nterfacing_Lecture7.pptx
UNIT 4 & 5 - I nterfacing_Lecture7.pptxnaveen088888
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshopatuline
 
The IoT Academy IoT training Arduino Part 4 Arduino interfaces
The IoT Academy IoT training Arduino Part 4 Arduino interfacesThe IoT Academy IoT training Arduino Part 4 Arduino interfaces
The IoT Academy IoT training Arduino Part 4 Arduino interfacesThe IOT Academy
 
Analog to digital conversion
Analog to digital conversionAnalog to digital conversion
Analog to digital conversionEngr Ahmad Khan
 
Chap 3. signal processing elemnt part three
Chap 3. signal processing elemnt part threeChap 3. signal processing elemnt part three
Chap 3. signal processing elemnt part threeYemaneBayray
 
Basic Stamp Lightmeter Presentation
Basic Stamp Lightmeter PresentationBasic Stamp Lightmeter Presentation
Basic Stamp Lightmeter Presentationtomkinsc
 
Fundamentals of programming Arduino-Wk2.ppt
Fundamentals of programming Arduino-Wk2.pptFundamentals of programming Arduino-Wk2.ppt
Fundamentals of programming Arduino-Wk2.pptansariparveen06
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalTony Olsson.
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalTony Olsson.
 
signal processing in software and electric field sensing
signal processing in software and electric field sensingsignal processing in software and electric field sensing
signal processing in software and electric field sensingomidsalangi1
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptxHebaEng
 
Digital clock workshop
Digital clock workshopDigital clock workshop
Digital clock workshopKedarv
 
analog to digital converter.ppt
analog to digital converter.pptanalog to digital converter.ppt
analog to digital converter.pptDreamers6
 

Similar to Arduino tutorial #3 (20)

arduinoworkshop-160204051621.pdf
arduinoworkshop-160204051621.pdfarduinoworkshop-160204051621.pdf
arduinoworkshop-160204051621.pdf
 
Ardui no
Ardui no Ardui no
Ardui no
 
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
UNIT 4 & 5 - I         nterfacing_Lecture7.pptxUNIT 4 & 5 - I         nterfacing_Lecture7.pptx
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshop
 
Iot 101
Iot 101Iot 101
Iot 101
 
The IoT Academy IoT training Arduino Part 4 Arduino interfaces
The IoT Academy IoT training Arduino Part 4 Arduino interfacesThe IoT Academy IoT training Arduino Part 4 Arduino interfaces
The IoT Academy IoT training Arduino Part 4 Arduino interfaces
 
Analog to digital conversion
Analog to digital conversionAnalog to digital conversion
Analog to digital conversion
 
Chap 3. signal processing elemnt part three
Chap 3. signal processing elemnt part threeChap 3. signal processing elemnt part three
Chap 3. signal processing elemnt part three
 
Basic Stamp Lightmeter Presentation
Basic Stamp Lightmeter PresentationBasic Stamp Lightmeter Presentation
Basic Stamp Lightmeter Presentation
 
Arduino
ArduinoArduino
Arduino
 
Arduino wk2
Arduino wk2Arduino wk2
Arduino wk2
 
Fundamentals of programming Arduino-Wk2.ppt
Fundamentals of programming Arduino-Wk2.pptFundamentals of programming Arduino-Wk2.ppt
Fundamentals of programming Arduino-Wk2.ppt
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
signal processing in software and electric field sensing
signal processing in software and electric field sensingsignal processing in software and electric field sensing
signal processing in software and electric field sensing
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
 
Lab3
Lab3Lab3
Lab3
 
Lec08
Lec08Lec08
Lec08
 
Digital clock workshop
Digital clock workshopDigital clock workshop
Digital clock workshop
 
analog to digital converter.ppt
analog to digital converter.pptanalog to digital converter.ppt
analog to digital converter.ppt
 

More from 동호 손

Raspberry pi tutorial #3
Raspberry pi tutorial #3Raspberry pi tutorial #3
Raspberry pi tutorial #3동호 손
 
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 동호 손 (7)

Raspberry pi tutorial #3
Raspberry pi tutorial #3Raspberry pi tutorial #3
Raspberry pi tutorial #3
 
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

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 

Arduino tutorial #3

  • 1. 1 Arduino Tutorial #3 - Measuring the light - Dong Ho Son POSTECH Pohang, Korea donghoson@postech.ac.kr
  • 2. 2 Measuring the light - Overview  Sensor: Analog  Digital • Analog : continuous • Digital : discrete  Photoresistor (or Light-Dependent Resistor, LDR) • A light-controlled variable resistor • The resistance increases/decreases according to the brightness  Let’s configure the circuit • The brightness of the LED is changed according to the brightness of the environment • If dark, the LED also would be dark • If bright, the LED also would be bright source: wikimedia.org
  • 3. 3 Measure the light - Circuit  Configure the circuit +- 2kΩ 220Ω Source: pixabay.com/photo-2168193
  • 4. 4 Measuring the light - Sketch (1/3)  setup() { } • pinMode(10, OUTPUT); − Prepare the mode of pin − We will use pin #10 − We will order to LED  OUTPUT • Serial.begin(9600); − Prepare the serial communication to get the value of light from the sensor − 9600: serial communication speed – 9600 bits per second is the default for the Arduino
  • 5. 5 Measuring the light - Sketch (2/3)  loop() { } • int val = analogRead(A4); − Read the analog value of light • analogWrite(10, val/4); − Turn on the LED − Different from digitalWrite(); – digitalWrite(); just has HIGH or LOW − Brightness of LED is controlled by ‘val/4’ − val  10 bit , val/4  8 bit − analogWrite() uses 8 bit of digital pin
  • 6. 6 Measuring the light - Sketch (3/3)  loop() { } • Serial.print(“ Brightness = ”); − It prints the text “ Bightness = ” to the serial console • Serial.println(val/4); − It prints the value of ‘val/4’ to the serial console − Also changes the line (newline) • Delay(10); − Need 10ms to check step-by-step
  • 7. 7 Measuring the light - Result  The brightness of the LED is being changed! +- Brightness = 127 Brightness = 153 Brightness = 128 Brightness = 156 Brightness = 127 Brightness = 156 Brightness = 127 Brightness = 156 Brightness = 125 Brightness = 155 Brightness = 124 Brightness = 158 Brightness = 129 Brightness = 156 Brightness = 127 Brightness = 153 Brightness = 125 Source: pixabay 2kΩ 220Ω Source: pixabay.com/photo-2168193