Servo position control using DS18B20 variable temperature

Hello guys.
I need to control the damper of the smokehouse and thereby control the temperature. The damper position is driven by a servo motor according to the temperature. 0° - 90°. In the code it is currently 180°, but in practice it will only be 90°. The code works, but I haven't tried it in practice yet. So far only a microservo. I don't know how to display the variable temperature Min and Max on the LCD and I also need to change these values ​​preferably with two potentiometers.
if (tempCelsius >= 10 and tempCelsius <= 60)
Thank you very much for any advice.

/*  Atmega 328  (Nano)
    sensor type DS18B20
    22/01/2024
*/

#include <Servo.h>
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>



#define ONE_WIRE_BUS 5

const int SERVO_PIN = 5;   // Arduino pin connected to Servo Motor's pin
const int SENSOR_PIN = 2;  // Arduino pin connected to DS18B20 sensor's DATA pin
const int i2c_addr = 0x27;
const float TEMPERATURE_THRESHOLD = 30;  // °C  20
//const float TOLERANCE             = 0.5; // °C

Servo servo;                         // create servo object to control a servo
OneWire oneWire(SENSOR_PIN);         // setup a oneWire instance
DallasTemperature sensor(&oneWire);  // pass oneWire to DallasTemperature library
LiquidCrystal_I2C lcd(0x27, 20, 4);

float tempCelsius;  // temperature in Celsius
float servoposraw;
float servopos;


void setup() {
  Serial.begin(9600);       // initialize serial
  servo.attach(SERVO_PIN);  // attaches the servo on pin 5 to the servo object,  pin 5?  servo.write(0);
  servo.write(0);
  sensor.begin();  // initialize the sensor
  lcd.init();      // initialize the lcd
  lcd.begin(20, 4);
  lcd.backlight();  // open the backlight
}

void loop() {
  delay(1000);
  sensor.requestTemperatures();             // send the command to get temperatures
  tempCelsius = sensor.getTempCByIndex(0);  // read temperature in Celsius
  if (tempCelsius >= 10 and tempCelsius <= 60) {
    servoposraw = (180. / 60.) * tempCelsius;
    //přidat mapování teploty a uhlu serva https://forum.arduino.cc/t/controlling-a-servo-position-using-a-temperature-sensor/374543/8
    servopos = 180 - servoposraw;
    servo.write(servopos);
    Serial.println(servopos);
    Serial.print("Temperature: ");
    Serial.print(tempCelsius);
    //Serial.print(tempC,1); // The 1 behind the tempC (second argument) defines the numbers of digits required
    Serial.print("°C => servo angle: ");
    lcd.clear();
    lcd.setCursor(0, 0);  // start to print at the first row
    lcd.print("Temperature: ");
    lcd.print(tempCelsius,0);  // print the temperature in Celsius
    lcd.print((char)223);    // print ° character
    lcd.print("C");
    lcd.setCursor(0, 1);     // start to print at the second row
    lcd.print("Angle   : ");  // print the temperature in Fahrenheit
    lcd.print(servopos,0);
    lcd.print((char)223);  // print ° character
    //lcd.print("°");
    lcd.setCursor(0, 2);
    lcd.print("Min: ");
    //lcd.print(???);  
    lcd.setCursor(0, 3);
    lcd.print("Max: ");
    // lcd.print(???);
  }
  //delay(150);
}

have a look at esp32-potentiomete
you should be able to print

lcd.print("Min: ");
lcd.print(minimum); 

or even

lcd.printf("Min: %f",minimum); 

Neither do we. Post an annotated Schematic showing exactly how you have wired it. Post links to all of the hardware items and indicate which Arduino you are using.

Arduino uno, LCD I2C 20x4, DC18b20. The wiring is the same as Wokwi.

I do not have one hence the request for a schematic. Good Luck!

[lcd servo - Wokwi ESP32, STM32, Arduino Simulator]

Yes it is obvious it will not work based on your picture (that is not a schematic). Try building it and let us know what you find.

Posting an annotated schematic showing exactly how you have wired it helps us help you. By showing all connections, power, components, ground and power sources you will save a lot of clarifying questions and time for all of us. Be sure to note any logic wires over 10/25 inches/cm in length. Post links to technical information on the hardware items including the motors, shield, and Arduino. This should include all component values or model numbers and details of all power supplies used (which could be USB power for example).

Posting the code following forum guidelines using code tags will also help. With this information we should be able to answer your question accurately. "How to get the best from this forum". How to get the best out of this forum

If you don't understand what a schematic is, please Google to find out. It is not the same thing as a wiring diagram. Hand-drawn is OK. Some bright, sharp photos of the circuit may also be useful.

The thing I see is many of the users do not want to draw schematics yet a large portion of there problems are in the connections, power etc. It appears they spend about a week or so with lots of questions and then maybe, give up, and some get lucky. It is amazing how many problems you find when doing a real labeled schematic including Technical links. That schematic makes them look like a pro. It appears to me that most of the time when a proper schematic is posted the solution is usually within day or so. Good schematic capture software can be gotten for the downloading. Months later a wire comes off, looking at the schematic and putting it back saves lots of headaches.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.