Modul 6: Analog Input Photoresistor
Modul 6: Analog Input Photoresistor
Analog Input
Photoresistor
Oleh :
Sugeng Purwantoro E.S.G.S
Muhammad Mahrus Zain
Agus Urip Ari Wibowo
Analog Input – Photoresistor
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
void setup()
{
pinMode(8, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int readValue = analogRead(A0);
Serial.println(readValue);
}
Analog Input - Practice
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