Arduino Photoresistor: Difference between revisions
From wikiluntti
(→Code) |
(→Code) |
||
(One intermediate revision by the same user not shown) | |||
Line 3: | Line 3: | ||
Simple code to use photoresistor or photocell or light-dependent resistor LDR. | Simple code to use photoresistor or photocell or light-dependent resistor LDR. | ||
The resistance of a photoresistor decreases when it is hit by light, or it lets electricity flow through it if light is hitting it | The resistance of a photoresistor decreases when it is hit by light, or it lets electricity flow through it if light is hitting it. | ||
Need to use a voltage divider. | |||
== Code == | == Code == | ||
* | Simple code. Connect | ||
* LDR and a resistor to +5V and GND | |||
* A0 between LDR and R. | |||
<syntaxhighlight lang="C"> | |||
void setup() { | |||
Serial.begin(9600); | |||
} | |||
void loop() { | |||
int value = analogRead(A0); | |||
Serial.print("Analog Value: "); | |||
Serial.println(value); | |||
delay(25); | |||
} | |||
</syntaxhighlight> | |||
== == | == == |
Latest revision as of 18:07, 29 November 2024
Introduction
Simple code to use photoresistor or photocell or light-dependent resistor LDR.
The resistance of a photoresistor decreases when it is hit by light, or it lets electricity flow through it if light is hitting it.
Need to use a voltage divider.
Code
Simple code. Connect
- LDR and a resistor to +5V and GND
- A0 between LDR and R.
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A0);
Serial.print("Analog Value: ");
Serial.println(value);
delay(25);
}