zackrothmann
Published

Pot temperature sensor

This device will show you how hot your pot is with an RGB LED

IntermediateShowcase (no instructions)58
Pot temperature sensor

Things used in this project

Hardware components

SparkFun RedBoard
SparkFun RedBoard
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
5 mm LED: Red
5 mm LED: Red
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Temperature Sensor
Temperature Sensor
×1
Slide Switch
Slide Switch
×1
Buzzer
Buzzer
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Resistor 330 ohm
Resistor 330 ohm
×4
Jumper wires (generic)
Jumper wires (generic)
×1
4xAA battery holder
4xAA battery holder
×1

Story

Read more

Schematics

Schematic

The Schematic

Code

Code

Arduino
The Code
// set up the playing field to let the computer know
// what pin does what and so that you can use informal
// language to refer to components.

const int Buzz = 2;

const int Trig = 3;
const int Echo = 4;
float Distance = 0;

const int R = 9;
const int G = 10;
const int B = 11;

const int LEDG = 5;
const int LEDR = 6;

const int Therm = A0;
float Vol = 0;

const int numReadings = 10;

int readings[numReadings];
int readIndex= 0;
int total = 0;

const int Switch = 7;



void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

for (int thisReading = 0; thisReading < numReadings; thisReading++){
  readings[thisReading] = 0;
}

pinMode (Buzz, OUTPUT);

pinMode (Trig, OUTPUT);
pinMode (Echo, INPUT);

pinMode (R, OUTPUT);
pinMode (G, OUTPUT);
pinMode (B, OUTPUT);

pinMode (LEDG, OUTPUT);
pinMode (LEDR, OUTPUT);

pinMode (Therm, INPUT);

pinMode (Switch, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
 Distance = getDistance();
 Serial.print (Distance);
 Serial.print ("in  ");
 Serial.print (Vol);
 Serial.println ("v  ");
 
 total = total - readings[readIndex];
 readings[readIndex] = analogRead (A0);
 total = total + readings[readIndex];
 readIndex = readIndex + 1;
 
 if (readIndex >= numReadings) {
  readIndex = 0;
 }
float average = 1.0 * total / numReadings;
delay (1);
 
 Vol = average * 0.004882813;
 if (digitalRead(Switch) == LOW){
 if (Distance < 14 && Distance > 10){
  digitalWrite (LEDG, HIGH);
  digitalWrite (LEDR, LOW);
  delay (50);
 } else {
  digitalWrite (LEDG, LOW);
  digitalWrite (LEDR, HIGH);
  delay (50);
 }
 if (Vol <= 0.85){
  analogWrite (R, 0);
  analogWrite (G, 230);
  analogWrite (B, 255);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.85 && Vol < 0.86){
   analogWrite (R, 18);
  analogWrite (G, 214);
  analogWrite (B, 237);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.86 && Vol < 0.87){
   analogWrite (R, 36);
  analogWrite (G, 197);
  analogWrite (B, 219);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.87 && Vol < 0.88){
   analogWrite (R, 55);
  analogWrite (G, 181);
  analogWrite (B, 200);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.88 && Vol < 0.89){
   analogWrite (R, 73);
  analogWrite (G, 164);
  analogWrite (B, 182);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.89 && Vol < 0.90){
   analogWrite (R, 91);
  analogWrite (G, 148);
  analogWrite (B, 164);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.90 && Vol < 0.91){
   analogWrite (R, 109);
  analogWrite (G, 131);
  analogWrite (B, 146);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.91 && Vol < 0.92){
   analogWrite (R, 128);
  analogWrite (G, 115);
  analogWrite (B, 128);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.92 && Vol < 0.93){
   analogWrite (R, 146);
  analogWrite (G, 99);
  analogWrite (B, 109);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.93 && Vol < 0.94){
   analogWrite (R, 164);
  analogWrite (G, 82);
  analogWrite (B, 91);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.94 && Vol < 0.95){
   analogWrite (R, 182);
  analogWrite (G, 66);
  analogWrite (B, 73);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.95 && Vol < 0.96){
   analogWrite (R, 200);
  analogWrite (G, 49);
  analogWrite (B, 55);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.96 && Vol < 0.97){
   analogWrite (R, 219);
  analogWrite (G, 33);
  analogWrite (B, 36);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.97 && Vol < 0.98){
   analogWrite (R, 237);
  analogWrite (G, 16);
  analogWrite (B, 18);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 0.98 && Vol < 0.99){
   analogWrite (R, 255);
  analogWrite (G, 0);
  analogWrite (B, 0);
  noTone (Buzz);
  delay (50);
 }else if (Vol > 1.00){
   analogWrite (R, 255);
  analogWrite (G, 0);
  analogWrite (B, 0);
  tone (Buzz, 272);
  delay (50);
  analogWrite (R, 0);
  analogWrite (G, 0);
  analogWrite (B, 0);
  tone (Buzz, 136);
  delay (50);
 }
 } else {
  digitalWrite (LEDR, LOW);
  digitalWrite (LEDG, LOW);
  analogWrite (R, 0);
  analogWrite (G, 0);
  analogWrite (B, 0);
  noTone (Buzz);
  delay (200);
 }
}
 


float getDistance()
{
  float echoTime;                   //variable to store the time it takes for a ping to bounce off an object
  float calculatedDistance;         //variable to store the distance calculated from the echo time

  //send out an ultrasonic pulse that's 10ms long
  digitalWrite(Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig, LOW);

  echoTime = pulseIn(Echo, HIGH);      //use the pulsein command to see how long it takes for the
                                          //pulse to bounce back to the sensor

  calculatedDistance = echoTime / 148.0;  //calculate the distance of the object that reflected the pulse (half the bounce time multiplied by the speed of sound)

  return calculatedDistance;              //send back the distance that was calculated
}

Credits

zackrothmann
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.