help.. why the motor doesn't run

i use 3 DS18B20, Nema 17 motor, Driver l298n.
i use this code but the motor can’t run.
i want the motor run in 1minute when reach 50C

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(5, 4); // RX, TX
#include <BlynkSimpleSerialBLE.h>
#include <TimeLib.h>
#include <WidgetRTC.h>   
#include <OneWire.h>
#include <Stepper.h>
const int stepsPerRevolution = 800;
OneWire  ds(2);  // on pin 7 (a 4.7K resistor is necessary) make sure you change this from the original pin 10 to an unused pin.
int adr;
float s1;
float s2;
float s3;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0;  // number of steps the motor has taken
//Dg-xL4X7Bi8pnGnIeE_GShZIwJ3i_FzO
//4rsZaSxJlLy9biW0PQk-znfcbsAGC2Rl
char auth[] = "4rsZaSxJlLy9biW0PQk-znfcbsAGC2Rl"; // Put your Auth Token here. (see Step 3 above)
SoftwareSerial SerialBLE(5, 4); // RX, TX
BlynkTimer timer;
WidgetRTC rtc;

  
// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}

BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
}


void setup()
{
   // set the speed at 60 rpm:
 // myStepper.setSpeed(100);
  Serial.begin(9600); // See the connection status in Serial Monitor
SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

   setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)

  // Display digital clock every 10 seconds
  timer.setInterval(10000L, clockDisplay);
}



void loop()
{
  Blynk.run(); // All the Blynk Magic happens here...
  timer.run();
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, -1000, 1000, -1500, -1500);
  // set the motor speed:
  
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
    byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  
//  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {           //we need to drop 8 bytes of data
  }
  adr = (addr[7]);

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad


  for ( i = 0; i < 9; i++) {           // we need 9 bytes to drop off
    data[i] = ds.read();
  }
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
 
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  if(adr == 229)  {         //replace ??? with value of sensor number 1    
    s1 = celsius;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  
  }

  if(adr == 235)  {         //replace ??? with value of sensor number 2
    s2 = celsius;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }

  if(adr == 16)  {         //replace ??? with value of sensor number 3
    s3 = celsius;           //change celsius to fahrenheit if you prefer output in Fahrenheit
  }
 if (s1 >= 50 && motorSpeed > 0){
  myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution /100);;
  
  }


Serial.print(" Sensor 1 = ");
Serial.println(s1);
Serial.print(" Sensor 2 = ");
Serial.println(s2);
Serial.print(" Sensor 3 = ");
Serial.println(s3);


  Blynk.virtualWrite(V5, s1);
  Blynk.virtualWrite(V6, s2);
  Blynk.virtualWrite(V7, s3);

  
 
}

gege.ino (5.16 KB)

i make a simple code for test my motor with ds18b20

  #include <OneWire.h>
#include <DallasTemperature.h>
 
#define ONE_WIRE_BUS 2
 
OneWire oneWire(ONE_WIRE_BUS);
 
DallasTemperature sensors(&oneWire);
DeviceAddress sensor1= { 0x28, 0xAA, 0x80, 0xDB, 0x49, 0x14, 0x1, 0xE5 };
DeviceAddress sensor2 = { 0x28, 0xAA, 0x9A, 0x17, 0x4A, 0x14, 0x1, 0xEB };
DeviceAddress sensor3 = { 0x28, 0xAA, 0xD7, 0xCD, 0x49, 0x14, 0x1, 0x10 };

 #include <Stepper.h>
const int stepsPerRevolution =800; // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0; // number of steps the motor has taken


void setup(void){
// set the speed at 60 rpm:
  myStepper.setSpeed(300);
  Serial.begin(9600);
  pinMode(2,OUTPUT);// for EN1
  digitalWrite(2,HIGH);// enable EN1
  pinMode(3,OUTPUT);// for EN1
  digitalWrite(3,HIGH); // enable EN2
  sensors.begin();
}
 
void loop(void){
  
  int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, -2000, 2000, -1000, 1000);

  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");
 
  Serial.print("Sensor 1(*C): ");
  Serial.println(sensors.getTempC(sensor1));
  if (sensor1 >= 20) {
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
//myStepper.step(stepsPerRevolution / 100);
myStepper.step(stepsPerRevolution / 800);
}

  }

  Serial.print("Sensor 2(*C): ");
  Serial.println(sensors.getTempC(sensor2));
    if (sensor1 >= 20) {
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
//myStepper.step(stepsPerRevolution / 100);
myStepper.step(stepsPerRevolution / 800);
}

  }
 
  Serial.print("Sensor 3(*C): ");
  Serial.println(sensors.getTempC(sensor3));
    if (sensor1 >= 20) {
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
//myStepper.step(stepsPerRevolution / 100);
myStepper.step(stepsPerRevolution / 800);
}

  }


}

  }
 int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, -2000, 2000, -1000, 1000);

analogRead(A0) returns values between 0 and 1023 (for uno) so this mapping would not work very well would it!

maybe try:

map(sensorReading, 0, 1023, -1000, 1000)

also did you try your code for your motor WITHOUT the temperature sensor (ie only with the analog input)? does the motor operate then?

PS: all you need to do to try that is to comment out "if (sensor1 >= 20) {" and the corresponding "}" in your code in reply #1 :wink: