// Single LED brightness control with NTC
// LED on D3 (PWM), Thermistor on A0 with 10k resistor
const int thermistorPin = A0;
const int ledPin = 3;
int rawValue;
float temperature;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
rawValue = analogRead(thermistorPin);
// Convert to voltage (3.3V reference)
float V = rawValue * (3.3 / 1023.0);
// Voltage divider with 10k resistor
float R = (3.3 * 10000.0 / V) - 10000.0;
// Beta equation (B=3950, R0=10k at 25C)
const float BETA = 3950.0;
float tempK = 1.0 / ((1.0 / 298.15) + (1.0 / BETA) * log(R / 10000.0));
temperature = tempK - 273.15;
Serial.print("Temp: ");
Serial.print(temperature);
Serial.println(" °C");
if (temperature < 25.0) {
analogWrite(ledPin, 25); // ~10% brightness
}
else if (temperature < 30.0) {
analogWrite(ledPin, 128); // ~50% brightness
}
else {
analogWrite(ledPin, 255); // 100% brightness
}
delay(500);
}