[go: up one dir, main page]

0% found this document useful (0 votes)
133 views1 page

Love o Meter

The document defines constants and functions for a temperature sensor system with LED indicators. It sets an analog sensor pin and baseline temperature, then enters a loop to continuously read the sensor, convert it to voltage and temperature, and set LEDs based on whether the temperature is below or within 2-4, 4-6, or over 6 degrees above the baseline.

Uploaded by

Bruce Banner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views1 page

Love o Meter

The document defines constants and functions for a temperature sensor system with LED indicators. It sets an analog sensor pin and baseline temperature, then enters a loop to continuously read the sensor, convert it to voltage and temperature, and set LEDs based on whether the temperature is below or within 2-4, 4-6, or over 6 degrees above the baseline.

Uploaded by

Bruce Banner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

const int sensorPin = A0; // This signifies the system to be in

a Celsius degree.
const float baselineTemp = 20.0;
void setup(){ // This signifies the system to open up a serial connection to
showcase values.
Serial.begin(9600); // This signifies the
LED pins to be as outputs.
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber,LOW);
}
}
void loop(){ // This signifies to read the analog pin’s value for it to be
stored as a variable.
int sensorVal = analogRead(sensorPin);
Serial.println("Sensor Value: "); // This signifies to send the sensor values out
of the serial port.
Serial.println(sensorVal);
float voltage = (sensorVal/1024.0) * 5.0; // This signifies to convert the ADC
reading into voltage.
Serial.println(", Volts: "); // This signifies to send the voltage level out
to the serial port.
Serial.println(voltage);
Serial.println(", degrees C: ");
float temperature = (voltage - .5) * 100; // This signifies to convert the
voltage in a Celsius temperature reading.
Serial.println(temperature);
if(temperature < baselineTemp){ // This signifies if the current temperature is
lower than the baseline, turn off all the LEDs.
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
// This signifies if the temperature rises up to 2 – 4 degrees,
turn one LED on.
}else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
// This signifies if the temperature rises up to 4 – 6 degrees,
turn two LEDs on.

}else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){


digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
// This signifies if the temperature rises up moredegrees, turn
one LED on.
}else if(temperature >= baselineTemp+6){
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}
delay(1);
}

You might also like