Introduction
Our project is about helping and locating homeless people under extreme cold weather condition. This tutorial aims to make the RGB light changes its color when the temperature changes. The RGB light is a warning signal for homeless people who sleep on the street. Blue indicates the weather is very cold and may threaten their health. and the purple means the weather is extremely cold, and to an extent that is emergent for them to find a shelter or a warm place.
Parts List
- Arduino Uno Board
- Temperature Sensor TMP 36 GZ
- RGB light
- 3 330 ohm resistors
- wires
The circuit
The circuit is pretty straightforward. The 5v pin is supplying power to the temperature sensor. For the temperature sensor, the pin on row 7 is the input of the power, and the pin on row 5 is the output of the power. A0 is the analog read pin to read the temperature detected by the temperature sensor. As for the RGB, the digital pin is responsible for controlling it. The pin 9, 10, and 11 is responsible for the input of blue, green and red pin. The pin on row 16 is the common pin for the output of the electricity that is connected to the ground.
When the temperate is above 40 degrees, the digital pins will send signals to turn off the RGB. When the temperature is between 20 and 40 degrees, the digital pins 9 will send the “high” signal to the blue pin, so that the RGB will show a blue color. When the temperature dropped below 20 degrees, the digital pin 9 and 11 is “high”, and the RGB will show a purple color.
Video
For the sake of the video, I set the threshold of the temperatures for changing the light at 75, 70 and 68 degrees. Because it is very hard to have a temperature below 40 degrees indoor.
The code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
//CPLN 571. 11/14/2018 This tutorial is about how to change the light of RGB when temperature changes. // The project extends code form USK circuit 3 and 7. const int RED_PIN = 9;//the digital pin for red pin const int GREEN_PIN = 10;//the digital pin for green pin const int BLUE_PIN = 11;//the digital pin for blue pin const int temperaturePin = 0;//the analog read pin that is used to reat the temperature void setup() { pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); Serial.begin(9600);//the bound rate for serial monitor } void loop() { float voltage, degreesC, degreesF;//get numbers with decimals voltage = getVoltage(temperaturePin);//get voltage from the temperature pin degreesC = (voltage - 0.5) * 100.0;//calculate the celcius degree degreesF = degreesC * (9.0/5.0) + 32.0;// calculate the Fahrenheit degree Serial.print("voltage: ");//print volrage in serial monitor Serial.print(voltage); Serial.print(" deg C: ");//print the celcious degree in serial monitor Serial.print(degreesC); Serial.print(" deg F: ");//print the farenheit degree in serial monitor Serial.println(degreesF); delay(1000); if (degreesF > 40) //if the temperature is greather than 40 degree, turn off the RGB { // Off (all LEDs off): digitalWrite(RED_PIN, LOW); digitalWrite(GREEN_PIN, LOW); digitalWrite(BLUE_PIN, LOW); } else if (degreesF >= 20) // Blue (turn just the blue LED on): // if the temperature is larger than 20 degrees and smaller than 40 degrees, show blue color { digitalWrite(RED_PIN, LOW); digitalWrite(GREEN_PIN, LOW); digitalWrite(BLUE_PIN, HIGH); } if (degreesF < 20)//if the temperature is below 20 degrees, show purple color { digitalWrite(RED_PIN, HIGH); digitalWrite(GREEN_PIN, LOW); digitalWrite(BLUE_PIN, HIGH); } } float getVoltage(int pin)//get voltage { return (analogRead(pin) * 0.004882814);// conver 0 to 1023 value to 0 to 5 value (the true voltage) } |