Advertisement
pleasedontcode

Single Threshold Code

Aug 19th, 2024
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.60 KB | Source Code | 0 0
  1. const int sensorPin = A0;
  2. const int outputPin = 9;
  3.  
  4. const float threshold = 75.0; // Single threshold in degrees Celsius
  5.  
  6. void setup() {
  7.   pinMode(outputPin, OUTPUT);
  8.   digitalWrite(outputPin, LOW);
  9.   Serial.begin(9600);
  10. }
  11.  
  12. void loop() {
  13.   int sensorValue = analogRead(sensorPin);  
  14.   float temperature = (sensorValue * 5.0 / 1023.0) * 100.0;
  15.  
  16.   Serial.print("Temperature: ");
  17.   Serial.println(temperature);
  18.  
  19.   if (temperature >= threshold) {
  20.     digitalWrite(outputPin, HIGH);  // Turn on fan/LED
  21.   } else {
  22.     digitalWrite(outputPin, LOW);   // Turn off fan/LED
  23.   }
  24.  
  25.   delay(500);
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement