







First step is to write a code.

Code: const int hot = 87; //set hot parameter const int cold = 75; //set cold parameter void setup() { pinMode(PB4, INPUT); //sensor pinMode(PB0, OUTPUT); //blue pinMode(PB1, OUTPUT); //green pinMode(PB2, OUTPUT); //red Serial.begin(9600); } void loop() { int sensor = analogRead(PB4); float voltage = (sensor / 1024.0) * 5.0; float tempC = (voltage - .5) * 100; float tempF = (tempC * 1.8) + 32; Serial.print("temp: "); Serial.print(tempF); if (tempF < cold) { //cold digitalWrite(PB0, LOW); digitalWrite(PB1, HIGH); digitalWrite(PB2, HIGH); delay(100); digitalWrite(PB0, HIGH); delay(100); digitalWrite(PB0, LOW); delay(100); digitalWrite(PB0, HIGH); Serial.println(" It's Cold."); } else if (tempF >= hot) { //hot digitalWrite(PB0, HIGH); digitalWrite(PB1, HIGH); digitalWrite(PB2, LOW); delay(100); digitalWrite(PB2, HIGH); delay(100); digitalWrite(PB2, LOW); delay(100); digitalWrite(PB2, HIGH); Serial.println(" It's Hot."); } else { //fine digitalWrite(PB0, HIGH); digitalWrite(PB1, LOW); digitalWrite(PB2, HIGH); delay(100); digitalWrite(PB1, HIGH); delay(100); digitalWrite(PB1, LOW); delay(100); digitalWrite(PB1, HIGH); Serial.println(" It's Fine."); } delay(3000); } I am using a common anode RGB led which has a common positive terminal and a GND for separate colored LEDs. The RGB LED changes color according to temperature i.e. Red color for hot temperature, blue color for cool temperature and green for moderate temperature.





In the code, I have chosen hot value as 85 analog value and cold as 75 analog value. We will try to analyze this value in upcoming posts but today, let's stick to the project. Next step is uploading it to ATtiny microcontroller.





Then interface RGB led as presented schematic:

Then interface LM35 temperature sensor to PB4 pin of ATtiny, it's an analog pin in ATtiny which we are using. Refer the pin diagram of ATtiny 13 microcontroller for information.



LM35's output voltage is proportional to Celsius temperature and provides resolution of 10mV. According to analysis, I got the data that output voltage is 1500mV at 150 degree Celsius, 250mV at 25 degree Celsius and goes to negative at lower than 0 temperatures. We can deduce that when sensor provides 100mV output, temperature would be 10 degree Celsius. Keeping in mind the resolution of ADC and sensor, the following algorithm has been derived. However we will try to derive much improved sensor calculation and implement in one of the upcoming posts. float voltage = (sensor / 1024.0) * 5.0; float tempC = (voltage - .5) * 100; float tempF = (tempC * 1.8) + 32;

This completes our project. Good luck building it.

Thanks for reading.





I recently made a cool flashing RGB led indication based on temperature. It is built around ATtiny 13, RGB LED, and an LM35 temperature sensor. This flashing circuit has a unique flashing rate which is adjusted by delays in Arduino code. So, let's try to build it!