Bare LDR and Thermistor Circuits
Build bare LDR and NTC thermistor dividers, switch an LED from raw readings, then estimate temperature with a rough two-point calibration.
Lesson 15 · Bare LDR: read light and switch an LED
Use a bare light-dependent resistor and a fixed 10 kΩ resistor, not a sensor module. Connect them as a divider and measure the junction on A0.
const int ledPin = 8;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int lightRaw = analogRead(A0);
Serial.println(lightRaw);
if (lightRaw < 500) digitalWrite(ledPin, HIGH);
else digitalWrite(ledPin, LOW);
delay(100);
}Cover and uncover the LDR; note your real values. Replace 500 with a threshold between the readings you measured. In this arrangement darker light should give a lower reading.
Lesson 16 · Bare thermistor: read temperature change
Replace the LDR with a bare 10 kΩ NTC thermistor, keeping the 10 kΩ fixed resistor from A0 to GND. With this orientation the A0 reading normally falls as the NTC warms. Check it on your own components.
void setup() {
pinMode(8, OUTPUT);
Serial.begin(9600);
}
void loop() {
int temperatureRaw = analogRead(A0);
Serial.println(temperatureRaw);
if (temperatureRaw < 500) digitalWrite(8, HIGH);
else digitalWrite(8, LOW);
delay(200);
}Record the actual room and warmed-by-hand readings, then put a threshold between them instead of assuming 500 suits every build.
Lesson 17 · Rough two-point calibration
Write down the raw room reading and a raw reading after the thermistor has settled against your hand. For temperature labels, use independent thermometer estimates for those two conditions. Hand surface temperature is not a fixed 37 °C, and an NTC is nonlinear, so this is only a classroom approximation between the two points.
const int roomRaw = 512; // replace with your reading
const int handRaw = 445; // replace with your reading
const int roomC = 20; // measured room temperature
const int handC = 30; // measured hand-surface temperature
void setup() { Serial.begin(9600); }
void loop() {
int raw = analogRead(A0);
long roughC = map(raw, roomRaw, handRaw, roomC, handC);
Serial.print("Raw: "); Serial.print(raw);
Serial.print(" Rough C: "); Serial.println(roughC);
delay(300);
}