Pot temperature sensor
This device will show you how hot your pot is with an RGB LED
Components and supplies
1
Ultrasonic Sensor - HC-SR04 (Generic)
1
Solderless Breadboard Half Size
1
Jumper wires (generic)
1
Buzzer
1
5 mm LED: Red
1
Temperature Sensor
1
SparkFun RedBoard
4
Resistor 330 ohm
1
Slide Switch
1
RGB Diffused Common Cathode
1
4xAA battery holder
Project description
Code
Code
arduino
The Code
1// set up the playing field to let the computer know 2// what pin does what and so that you can use informal 3// language to refer to components. 4 5const int Buzz = 2; 6 7const int Trig = 3; 8const int Echo = 4; 9float Distance = 0; 10 11const int R = 9; 12const int G = 10; 13const int B = 11; 14 15const int LEDG = 5; 16const int LEDR = 6; 17 18const int Therm = A0; 19float Vol = 0; 20 21const int numReadings = 10; 22 23int readings[numReadings]; 24int readIndex= 0; 25int total = 0; 26 27const int Switch = 7; 28 29 30 31void setup() { 32 // put your setup code here, to run once: 33Serial.begin(9600); 34 35for (int thisReading = 0; thisReading < numReadings; thisReading++){ 36 readings[thisReading] = 0; 37} 38 39pinMode (Buzz, OUTPUT); 40 41pinMode (Trig, OUTPUT); 42pinMode (Echo, INPUT); 43 44pinMode (R, OUTPUT); 45pinMode (G, OUTPUT); 46pinMode (B, OUTPUT); 47 48pinMode (LEDG, OUTPUT); 49pinMode (LEDR, OUTPUT); 50 51pinMode (Therm, INPUT); 52 53pinMode (Switch, INPUT_PULLUP); 54} 55 56void loop() { 57 // put your main code here, to run repeatedly: 58 Distance = getDistance(); 59 Serial.print (Distance); 60 Serial.print ("in "); 61 Serial.print (Vol); 62 Serial.println ("v "); 63 64 total = total - readings[readIndex]; 65 readings[readIndex] = analogRead (A0); 66 total = total + readings[readIndex]; 67 readIndex = readIndex + 1; 68 69 if (readIndex >= numReadings) { 70 readIndex = 0; 71 } 72float average = 1.0 * total / numReadings; 73delay (1); 74 75 Vol = average * 0.004882813; 76 if (digitalRead(Switch) == LOW){ 77 if (Distance < 14 && Distance > 10){ 78 digitalWrite (LEDG, HIGH); 79 digitalWrite (LEDR, LOW); 80 delay (50); 81 } else { 82 digitalWrite (LEDG, LOW); 83 digitalWrite (LEDR, HIGH); 84 delay (50); 85 } 86 if (Vol <= 0.85){ 87 analogWrite (R, 0); 88 analogWrite (G, 230); 89 analogWrite (B, 255); 90 noTone (Buzz); 91 delay (50); 92 }else if (Vol > 0.85 && Vol < 0.86){ 93 analogWrite (R, 18); 94 analogWrite (G, 214); 95 analogWrite (B, 237); 96 noTone (Buzz); 97 delay (50); 98 }else if (Vol > 0.86 && Vol < 0.87){ 99 analogWrite (R, 36); 100 analogWrite (G, 197); 101 analogWrite (B, 219); 102 noTone (Buzz); 103 delay (50); 104 }else if (Vol > 0.87 && Vol < 0.88){ 105 analogWrite (R, 55); 106 analogWrite (G, 181); 107 analogWrite (B, 200); 108 noTone (Buzz); 109 delay (50); 110 }else if (Vol > 0.88 && Vol < 0.89){ 111 analogWrite (R, 73); 112 analogWrite (G, 164); 113 analogWrite (B, 182); 114 noTone (Buzz); 115 delay (50); 116 }else if (Vol > 0.89 && Vol < 0.90){ 117 analogWrite (R, 91); 118 analogWrite (G, 148); 119 analogWrite (B, 164); 120 noTone (Buzz); 121 delay (50); 122 }else if (Vol > 0.90 && Vol < 0.91){ 123 analogWrite (R, 109); 124 analogWrite (G, 131); 125 analogWrite (B, 146); 126 noTone (Buzz); 127 delay (50); 128 }else if (Vol > 0.91 && Vol < 0.92){ 129 analogWrite (R, 128); 130 analogWrite (G, 115); 131 analogWrite (B, 128); 132 noTone (Buzz); 133 delay (50); 134 }else if (Vol > 0.92 && Vol < 0.93){ 135 analogWrite (R, 146); 136 analogWrite (G, 99); 137 analogWrite (B, 109); 138 noTone (Buzz); 139 delay (50); 140 }else if (Vol > 0.93 && Vol < 0.94){ 141 analogWrite (R, 164); 142 analogWrite (G, 82); 143 analogWrite (B, 91); 144 noTone (Buzz); 145 delay (50); 146 }else if (Vol > 0.94 && Vol < 0.95){ 147 analogWrite (R, 182); 148 analogWrite (G, 66); 149 analogWrite (B, 73); 150 noTone (Buzz); 151 delay (50); 152 }else if (Vol > 0.95 && Vol < 0.96){ 153 analogWrite (R, 200); 154 analogWrite (G, 49); 155 analogWrite (B, 55); 156 noTone (Buzz); 157 delay (50); 158 }else if (Vol > 0.96 && Vol < 0.97){ 159 analogWrite (R, 219); 160 analogWrite (G, 33); 161 analogWrite (B, 36); 162 noTone (Buzz); 163 delay (50); 164 }else if (Vol > 0.97 && Vol < 0.98){ 165 analogWrite (R, 237); 166 analogWrite (G, 16); 167 analogWrite (B, 18); 168 noTone (Buzz); 169 delay (50); 170 }else if (Vol > 0.98 && Vol < 0.99){ 171 analogWrite (R, 255); 172 analogWrite (G, 0); 173 analogWrite (B, 0); 174 noTone (Buzz); 175 delay (50); 176 }else if (Vol > 1.00){ 177 analogWrite (R, 255); 178 analogWrite (G, 0); 179 analogWrite (B, 0); 180 tone (Buzz, 272); 181 delay (50); 182 analogWrite (R, 0); 183 analogWrite (G, 0); 184 analogWrite (B, 0); 185 tone (Buzz, 136); 186 delay (50); 187 } 188 } else { 189 digitalWrite (LEDR, LOW); 190 digitalWrite (LEDG, LOW); 191 analogWrite (R, 0); 192 analogWrite (G, 0); 193 analogWrite (B, 0); 194 noTone (Buzz); 195 delay (200); 196 } 197} 198 199 200 201float getDistance() 202{ 203 float echoTime; //variable to store the time it takes for a ping to bounce off an object 204 float calculatedDistance; //variable to store the distance calculated from the echo time 205 206 //send out an ultrasonic pulse that's 10ms long 207 digitalWrite(Trig, HIGH); 208 delayMicroseconds(10); 209 digitalWrite(Trig, LOW); 210 211 echoTime = pulseIn(Echo, HIGH); //use the pulsein command to see how long it takes for the 212 //pulse to bounce back to the sensor 213 214 calculatedDistance = echoTime / 148.0; //calculate the distance of the object that reflected the pulse (half the bounce time multiplied by the speed of sound) 215 216 return calculatedDistance; //send back the distance that was calculated 217} 218
Downloadable files
Schematic
The Schematic
Schematic
Schematic
The Schematic
Schematic
Comments
Only logged in users can leave comments