Hello again guys I came back here to say I got it working finally below is attached my updated code and I will attach two videos showing how it behaves I use a lighter and an ice cube to simulate the temperatures.
Vid 1 extension
Vid 2 retract
Code
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int Extend_pin = 10; //Connect to L298N Pin In1 or BTS7960 RPWM NOTE: You may have to switch pins 9 and 10 depending on your RC controller
const int Retract_pin = 3; //Connect to L298N Pin In2 or BTS7960 LPWM
int Position_pin = A1; //This pin will measure the position of the linear actuator
int actual_locationpot=50; //Used to keep track of the "actual" actuator position
int desired_position0 = 50;
int desired_position1 = 152; //Used to tell Actuator where to go
int desired_position2 = 304;
int desired_position3 = 456;
int desired_position4 = 560;
float Celsius = 0;
float Fahrenheit = 0;
void setup() {
sensors.begin();
Serial.begin(9600);
pinMode(10, OUTPUT); //Digital pin for extending the actuator
pinMode(3, OUTPUT); //Digital pin for retracting the actuator
digitalWrite(Extend_pin, LOW); //Start with the actuator turned off until the loop below
digitalWrite(Retract_pin, LOW);
}
void loop() {
sensors.requestTemperatures();
Celsius = sensors.getTempCByIndex(0);
Fahrenheit = sensors.toFahrenheit(Celsius);
actual_locationpot = analogRead(Position_pin);
Serial.println(actual_locationpot);
delay(1000);
Serial.print(Celsius);
Serial.print(" C ");
delay(100);
Serial.print(Fahrenheit);
Serial.println(" F");
delay(100);
if (Fahrenheit>=163.46) {
analogWrite(Extend_pin, 65);
}
if (actual_locationpot>= desired_position2) {
analogWrite(Extend_pin, 0);
}
if (Fahrenheit>=90 && actual_locationpot< desired_position3) {
analogWrite(Extend_pin, 55);
}
if (actual_locationpot>= desired_position3) {
analogWrite(Extend_pin, 0);
}
if (Fahrenheit<=57.54 && actual_locationpot>desired_position1) {
analogWrite(Retract_pin, 55);
}
if (actual_locationpot<=desired_position1) {
analogWrite(Retract_pin, 0);
}
}