0% found this document useful (0 votes)
53 views

Modul 6: Analog Input Photoresistor

The document discusses using a photoresistor (light-dependent resistor) for analog input in Arduino. It provides examples of reading photoresistor values, using them to turn an LED on or off, and toggling an LED based on light levels measured by the photoresistor. Sketches with sample code are provided to demonstrate reading photoresistor values and using them to control an LED.

Uploaded by

HANDRI ZALIL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Modul 6: Analog Input Photoresistor

The document discusses using a photoresistor (light-dependent resistor) for analog input in Arduino. It provides examples of reading photoresistor values, using them to turn an LED on or off, and toggling an LED based on light levels measured by the photoresistor. Sketches with sample code are provided to demonstrate reading photoresistor values and using them to control an LED.

Uploaded by

HANDRI ZALIL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Modul 6

Analog Input
Photoresistor
Oleh :
Sugeng Purwantoro E.S.G.S
Muhammad Mahrus Zain
Agus Urip Ari Wibowo
Analog Input – Photoresistor

A photoresistor or photocell is a light-controlled variable


resistor. The resistance of a photoresistor decreases with
increasing incident light intensity. A photoresistor can be
applied in light-sensitive detector circuits, and light- and
dark-activated switching circuits. It's also called light-
dependent resistor (LDR).

https://www.google.co.kr/search?q=photoresistor&newwindow=1&safe=off&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjGp
8eMvrHaAhVJhbwKHd2SDdUQ_AUICigB&biw=1280&bih=669
Analog Input - Practice

Read value from photoresistor – circuit


Analog Input - Practice

Read value from photoresistor – sketch

void setup()
{
pinMode(8, OUTPUT);
Serial.begin(9600);
}

void loop()
{
int readValue = analogRead(A0);
Serial.println(readValue);
}
Analog Input - Practice

LED on/off with photoresistor – circuit


Analog Input - Practice

LED on/off with photoresistor – sketch

void setup() void loop()


{ {
pinMode(8, OUTPUT); int readValue = analogRead(A0);
Serial.begin(9600); Serial.println(readValue);
}
if (readValue < 500) {
digitalWrite(8, HIGH);
}
else {
digitalWrite(8, LOW);
}
}
Analog Input - Practice

Toogle LDR with photoresistor – sketch

void loop() {
const int lamp = 8; int c = analogRead(A0);
boolean x = true; delay(500);
if ( c<300 && x == true){
void setup() { digitalWrite(8,HIGH);
Serial.begin(9600); x = false;
pinMode(lamp , OUTPUT); delay(1000);

} }
else if ( c <300 && x == false) {
x = true;
digitalWrite(8,LOW);
delay(1000);
}
}
Analog Input - Practice

Uses a photo
resistor to
determine
whether a room
is bright,
average or dark.
It shows this
using 2 LEDs
and/or the serial
monitor.
Analog Input - Practice

int light = 0; else if(light > 229 && light < 451) {
Serial.println("It is average light!");
void setup() { digitalWrite(13, HIGH);
Serial.begin(9600); digitalWrite(12,LOW);
pinMode(13, OUTPUT); }
pinMode(12, OUTPUT); else {
} Serial.println("It is pretty dark!");
digitalWrite(13,HIGH);
void loop() { digitalWrite(12,HIGH);
light = analogRead(A0); }
Serial.println(light); delay(1000);
}
if(light > 450) {
Serial.println("It is quite
light!");
digitalWrite(13,LOW);
digitalWrite(12,LOW);
}
Thank You

You might also like