Advertisement
learnelectronics

Analogish Thermometer

Dec 26th, 2020
1,589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*-----------------------------------------------
  2.  *    Arduino Analog-ish Thermometer
  3.  *    www.youtube.com/learnelectronics
  4.  *    email: arduino0169@gmail.com
  5.  *    12/26/2020
  6.  *    You are free to use my code however you
  7.  *    want as long as you give me credit.
  8.  ------------------------------------------------*/
  9.  
  10.  #include "DHT.h"
  11.  #include <Servo.h>
  12.  
  13.  #define DHTPIN 8
  14.  #define DHTTYPE DHT11
  15.  
  16.  DHT dht(DHTPIN, DHTTYPE);
  17.  Servo myservo;
  18.  
  19.  int potpin = 0;
  20.  int val;
  21.  int Tred = 0;
  22.  
  23.  void setup() {
  24.   myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  25.   Serial.begin(9600);
  26.   Serial.println(F("DHTxx test!"));
  27.  
  28.   dht.begin();
  29. }
  30.  
  31. void loop(){
  32.  
  33. float f = dht.readTemperature(true);
  34. val = (int)f;
  35. Tred = map(val,-20,120,0,180);
  36.  
  37. Serial.println(f);
  38. Serial.println(val);
  39. Serial.println(Tred);
  40.  
  41. myservo.write(val);
  42.  
  43. delay(1000);
  44.  
  45.  
  46.  
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement