Skip to content

Instantly share code, notes, and snippets.

@jpliew
Created March 30, 2020 04:51
Show Gist options
  • Save jpliew/f2adda682f8d487807fab04199c85c5c to your computer and use it in GitHub Desktop.
Save jpliew/f2adda682f8d487807fab04199c85c5c to your computer and use it in GitHub Desktop.
Tutorial 4 - 1D
int analogInPin = A0; // Analog input pin that the potentiometer is attached to
int btnPin = 2;
int buzzerPin = 6;
bool toggle =false;
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
}
void loop()
{
int rawvoltage= analogRead(analogInPin);
float millivolts= rawvoltage * (5000/1023.0);
float kelvin= (millivolts/10);
Serial.print(millivolts);
Serial.print(" mV\t");
Serial.print(kelvin);
Serial.print(" Kelvin\t");
float celsius= kelvin - 273.15;
float f = (celsius * 1.8) + 32;
if(digitalRead(btnPin) == HIGH) {
toggle=!toggle;
digitalWrite(buzzerPin, HIGH);
delay(500);
digitalWrite(buzzerPin, LOW);
}
if(!toggle) {
Serial.print(celsius);
Serial.println(" Celsius");
if (celsius>35) {
digitalWrite(buzzerPin, HIGH);
}
else {
digitalWrite(buzzerPin, LOW);
}
}
else {
Serial.print(f);
Serial.println(" Farenheit");
}
delay(300);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment