For this assignment we were required to apply the concepts and components used so far to create a project involving an analog sensor, a digital sensor and two LEDs. I decided to explore the functioning of the TMP36 Temperature sensor and have used it as the analog sensor to develop a simple temperature detection model that may be employed in beverage holders to warn the people of the temperature of the contents of the glass.
Using the RGB LED, I have depicted temperature ranges from hot to cold by changing the colors from red to green to blue. Apart from this I have used a switch along with a yellow LED which may be turned on or off. As the program runs, the corresponding temperature value is printed in the Serial Monitor.
I have demonstrated the working of this circuit using glasses containing water of different temperatures ranging from ice cold to boiling hot and was able to achieve the desired color code.
I particularly enjoyed figuring out the connections and coding for the temperature sensor through a video and the datasheet provided.
Overall, I believe the assignment helped me delve deeper into creating simple circuits and the commands of Arduino IDE.
int RED=9; int GREEN=10; int BLUE=11; int PIN=A0; void setup() { Serial.begin(9600); pinMode(RED,OUTPUT); pinMode(BLUE,OUTPUT); pinMode(GREEN,OUTPUT); } void loop() { int sensorValue=analogRead(PIN); delay(200); //delays the frequency of temperature readings float mv = sensorValue*4.9; //converts the analog input into mV float temp = (mv-500)/10; //calculates the final temperature value Serial.print("Temperature: "); Serial.print((mv-500)/10); Serial.print("°C\n"); if (temp>27){ digitalWrite(RED,HIGH); digitalWrite(GREEN,LOW); digitalWrite(BLUE,LOW); } else if (temp>21){ digitalWrite(GREEN,HIGH); digitalWrite(RED,LOW); digitalWrite(BLUE,LOW); } else if (temp>16){ digitalWrite(BLUE,HIGH); digitalWrite(GREEN,LOW); digitalWrite(RED,LOW); } }