Concept: This project combines analog and digital inputs to control LEDs in an innovative way. It’s an “Emotional Room Temperature Indicator”, which uses temperature data and user input to reflect the room’s “mood” with light.
Components Used:
- Arduino Uno
- TMP36 Temperature Sensor (Analog Sensor)
- Push-button switch (Digital Sensor)
- Standard LED (Digital LED)
- RGB LED (Analog LED)
- 220-ohm resistors for LEDs
- 10k-ohm resistor for the button switch
- Breadboard
- Jumper wires
Implementation: I made a reel with description and uploaded as a YouTube shorts embedded below:
Programming:
#define LED_PIN 3 #define BUTTON_PIN 7 int redPin = 9; int greenPin = 10; int bluePin = 11; int sensor = A0; byte lastButtonState = LOW; byte ledState = LOW; unsigned long debounceDuration = 50; // millis unsigned long lastTimeButtonStateChanged = 0; void setup() { pinMode(LED_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); pinMode(sensor, INPUT); // Reading sensor data Serial.begin(9600); // Initialize serial communication at 9600 bits per second } int givetemp() { int reading = analogRead(sensor); float voltage = reading * 5.0 / 1024.0; float temperatureC = (voltage - 0.5) * 100; Serial.print(voltage); Serial.print(" volts - "); Serial.print(temperatureC); Serial.println(" degrees C - "); return (int)temperatureC; // Convert float temperature to int before returning } void loop() { int currentTemp = givetemp(); // Call once and use the result multiple times if (currentTemp >= 20 && currentTemp <= 30) { digitalWrite(greenPin, HIGH); digitalWrite(bluePin, LOW); digitalWrite(redPin, LOW); } else if (currentTemp < 20) { digitalWrite(greenPin, LOW); digitalWrite(bluePin, HIGH); digitalWrite(redPin, LOW); } else if (currentTemp > 30) { digitalWrite(greenPin, LOW); digitalWrite(bluePin, LOW); digitalWrite(redPin, HIGH); } if (millis() - lastTimeButtonStateChanged > debounceDuration) { byte buttonState = digitalRead(BUTTON_PIN); if (buttonState != lastButtonState) { lastTimeButtonStateChanged = millis(); lastButtonState = buttonState; if (buttonState == HIGH) { // Assumes active HIGH button ledState = !ledState; // Toggle the state digitalWrite(LED_PIN, ledState); } } } }
Actual temperature of the room:
The TMP36 senses the room temperature. Depending on the “comfort” range (set here as 20°C to 30°C), the RGB LED changes colors — blue for cool, red for hot, and green for just right.
The push-button allows the user to set the mood of the room. When pressed, the standard yellow LED lights up to acknowledge that the room is at a comfortable temperature, while the RGB LED shows the current temperature-based mood of the room. The user can thus get immediate visual feedback on whether the room’s temperature is within a comfortable range or not.