Main Concept:
I was always curious about using a temperature sensor because I could never imagine how such a tiny device can detect human temperature and convert it into volts. Therefore, I used this homework to experiment with the temperature sensor. I also decided to use the slider switch because I love the feeling of opening and closing it. I learned how to use the temperature sensor through an online tutorial (tutorial) since we have not yet covered it in class. It works quite simply. We supply electricity through the +VS pin to measure temperature internally, and the measured analog voltage is then sent back to the Arduino through the GND pin.
Figure 1 : temperature sensor + slide switch
Code I’m proud of:
This is the part of the code that I’m most proud of. First, I read the sensor value from pin A0 and convert it into millivolts since the temperature sensor calculates the corresponding voltage in millivolts. Then, I crafted this formula based on what I learned from the tutorial: each degree Celsius corresponds to 10 millivolts. Because the output voltage increases by 10 millivolts per degree Celsius, starting from 500 millivolts at 0°C, I subtracted 500 from the measured millivolts and divided the result by 10 to map the temperature to its corresponding voltage value. Converting Celsius to Fahrenheit was quite easy since I had already learned that in chemistry class.
//read the volatge from analogPin A0 sensorValue = analogRead(A0); //convert digital numbers (0 to 1023) into voltage values volts = sensorValue * maxVoltage / 1023.0; //convert volts into millivolts millivolts = 1000 * volts; //convert into temperature in celsius celsius = (millivolts - 500)/10; //convert into temperature in fahrenheit fahrenheit = (celsius * 9/5) + 32;
Reflections & Future Improvements:
Overall, I loved learning how to use the temperature sensor since I have always been fascinated by how such a tiny component can capture environmental variables. I was especially curious about why it has three pins, and I was able to understand the internal mechanism where we supply electricity to measure temperature, convert it into analog voltage, and send that voltage back to the Arduino. It was a bit challenging to find the right thresholds for each LED light to turn on and off smoothly. Sometimes I set the threshold of the last LED too high, so it never turned on. However, I was able to adjust them correctly through multiple experiments. For future improvements, I would like to combine the slider switch and temperature sensor so that they work together to control shared LED lights seamlessly. I tried doing this, but I had so many wires and LEDs that I struggled to find a proper way to connect them. Next time, I will spend more time figuring this out.
