Components and supplies
Jumper wires (generic)
NeoPixel Ring - 12x 5050 RGB LED
Arduino UNO
Temperature Sensor - TMP36
Project description
Code
Code
c_cpp
1#include <Adafruit_NeoPixel.h> 2#ifdef __AVR__ 3 #include <avr/power.h> 4#endif 5// named constant for the pin the sensor is connected to 6#define PIN 6 7 8// How many NeoPixels are attached to the Arduino? 9#define NUMPIXELS 12 10 11// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. 12// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest 13// example for more information on possible values. 14Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 15 16const int sensorPin = A0; 17// room temperature in Celcius 18const float baselineTemp = 20.0; 19 20void setup() { 21 // open a serial connection to display values 22 Serial.begin(9600); 23 pixels.begin(); 24 // set the LED pins as outputs 25 // the for() loop saves some extra coding 26 for (int pinNumber = 2; pinNumber < 5; pinNumber++) { 27 pinMode(pinNumber, OUTPUT); 28 digitalWrite(pinNumber, LOW); 29 } 30} 31 32void loop() { 33 34 // read the value on AnalogIn pin 0 35 // and store it in a variable 36 int sensorVal = analogRead(sensorPin); 37 38 39 float voltage = (sensorVal / 1024.0) * 5.0; 40 41 42 Serial.print(", degrees C: "); 43 float temperature = (voltage - .5) * 100; 44 Serial.print(temperature); 45 46 if (temperature > 11 && temperature < 12.5 ) { 47 Serial.println("cold-01"); 48 for(int i=0;i<2;i++){ 49 50 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 51 pixels.setPixelColor(i, pixels.Color(49,0,225)); // Moderately bright green color. 52 53 pixels.show(); // This sends the updated pixel color to the hardware. 54 55 } 56 } 57 58 if (temperature > 12.6 && temperature < 14 ) { 59 Serial.println("cold"); 60 for(int i=0;i<2;i++){ 61 62 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 63 pixels.setPixelColor(i, pixels.Color(0,106,225)); // Moderately bright green color. 64 65 pixels.show(); // This sends the updated pixel color to the hardware. 66 67 } 68 } 69 if (temperature > 14.1 && temperature < 15.5 ) { 70 Serial.println("cold1"); 71for(int i=0;i<3;i++){ 72 73 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 74 pixels.setPixelColor(i, pixels.Color(0,203,225)); // Moderately bright green color. 75 76 pixels.show(); // This sends the updated pixel color to the hardware 77 78 } 79 } 80 if (temperature > 15.6 && temperature < 17 ) { 81 Serial.println("cold2"); 82for(int i=0;i<4;i++){ 83 84 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 85 pixels.setPixelColor(i, pixels.Color(0,225,148)); // Moderately bright green color. 86 87 pixels.show(); // This sends the updated pixel color to the hardware. 88 89 } 90 } 91 if (temperature > 17.1 && temperature < 18.5 ) { 92 Serial.println("cold3"); 93for(int i=0;i<5;i++){ 94 95 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 96 pixels.setPixelColor(i, pixels.Color(0,225,21)); // Moderately bright green color. 97 98 pixels.show(); // This sends the updated pixel color to the hardware. 99 100 101 } 102 } 103 if (temperature > 18.6 && temperature < 20 ) { 104 Serial.println("cold4"); 105for(int i=0;i<6;i++){ 106 107 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 108 pixels.setPixelColor(i, pixels.Color(115,225,0)); // Moderately bright green color. 109 110 pixels.show(); // This sends the updated pixel color to the hardware. 111 112 113 } 114 } 115 if (temperature > 21.1 && temperature < 22.5 ) { 116 Serial.println("cold5"); 117for(int i=0;i<7;i++){ 118 119 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 120 pixels.setPixelColor(i, pixels.Color(216,225,0)); // Moderately bright green color. 121 122 pixels.show(); // This sends the updated pixel color to the hardware. 123 124 125 } 126 } 127 if (temperature > 22.6 && temperature < 24 ) { 128 Serial.println("cold6"); 129for(int i=0;i<8;i++){ 130 131 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 132 pixels.setPixelColor(i, pixels.Color(225,179,0)); // Moderately bright green color. 133 134 pixels.show(); // This sends the updated pixel color to the hardware. 135 136 137 } 138 } 139 if (temperature > 24.1 && temperature < 25.5 ) { 140 Serial.println("cold7"); 141for(int i=0;i<9;i++){ 142 143 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 144 pixels.setPixelColor(i, pixels.Color(225,62,0)); // Moderately bright green color. 145 146 pixels.show(); // This sends the updated pixel color to the hardware. 147 148 149 150 } 151 } 152 if (temperature > 25.6 && temperature < 27 ) { 153 Serial.println("cold8"); 154for(int i=0;i<10;i++){ 155 156 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 157 pixels.setPixelColor(i, pixels.Color(225,0,0)); // Moderately bright green color. 158 159 pixels.show(); // This sends the updated pixel color to the hardware. 160 161 162 163 } 164 } 165 if (temperature > 27.1 && temperature < 28.5 ) { 166 Serial.println("cold9"); 167for(int i=0;i<11;i++){ 168 169 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 170 pixels.setPixelColor(i, pixels.Color(225,0,0)); // Moderately bright green color. 171 172 pixels.show(); // This sends the updated pixel color to the hardware. 173 174 175 } 176 } 177 if (temperature > 28.6 && temperature <30) { 178 Serial.println("cold10"); 179for(int i=0;i<12;i++){ 180 181 // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 182 pixels.setPixelColor(i, pixels.Color(225,0,0)); // Moderately bright green color. 183 184 pixels.show(); // This sends the updated pixel color to the hardware. 185 186 187 188 } 189 } 190delay(5000); 191pixels.clear(); 192 193} 194
Downloadable files
Measure Sheet
Measure Sheet
Schematics of project
Useful to know how to wiring the parts
Schematics of project
Schematics of project
Useful to know how to wiring the parts
Schematics of project
Measure Sheet
Measure Sheet
Comments
Only logged in users can leave comments
fmattiussi
0 Followers
•0 Projects
Table of contents
Intro
2
0