Let’s connect the LDR.
One leg to 5V, one leg to A0.
Now let’s WRITE some code.
(No. No copy-paste here…)
// Block 01 : DECLARE
// Name pins we use
// What pin? ; Name ; type ; const
const int LDR_PIN = A0;
// Block 02 : INIT
void setup() {
// Start serial terminal
Serial.begin(9600);
// Set declared pins
pinMode(LDR_PIN, INPUT);
}
// Block 03 : RUN
void loop() {
// What do we do? input-read; output-show; delay
// Analog values? 0 - 1023
// How do we input / read?
// What KIND/GROUP of pins?
// What pin?
// To where?
// What TYPE is ldrValue?
int ldrValue = analogRead(LDR_PIN);
// How does Arduino TALK to us?
// PRINT from Arduino to SERIAL "terminal"
Serial.print("Light Level: ");
Serial.println(ldrValue);
// How do we delay? Wait?
// Why 500? delay works in ms.
// Print every half a second
delay(500);
}
// Block 04 : LOGIC
// Nothing here yet…