Stepper motor code troubleshooting.

I am have some trouble with the code I am currently working on. The project is reading different DS18B20 temperature sensors then have a stepper motor move a fan to which ever temperature sensor is the highest. My current void loop() code successfully calls the startup() and then the start01() functions but after that it does nothing. If anyone could take a look at my code and see what might be the problem, or know of better, and more efficient ways to go about doing this, it would be useful. I am using the Arduino Uno, R3 Motor Shield, 5x DS18B20 temperature sensors, and an Adafruit 200 stepper motor.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Stepper.h> 

// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

int temp01 = 0;
int temp02 = 0;
int temp03 = 0;
int temp04 = 0;
int temp05 = 0;

//steps by 28, 56, 84, 112

const int STEPS = 200; //steps in a 360 degree revoltion
Stepper myStepper(STEPS, dirA, dirB); //initalize stepper class

#define ONE_WIRE_BUS 2 /*-(Connect to Pin 2 )-*/
OneWire ourWire(ONE_WIRE_BUS);
DallasTemperature sensors(&ourWire);

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0x86, 0x66, 0x67, 0x04, 0x00, 0x00, 0x43 }; 
DeviceAddress Probe02 = { 0x28, 0x49, 0x36, 0x67, 0x04, 0x00, 0x00, 0x6D };
DeviceAddress Probe03 = { 0x28, 0xC7, 0x6B, 0x67, 0x04, 0x00, 0x00, 0xED };
DeviceAddress Probe04 = { 0x28, 0x56, 0x40, 0x67, 0x04, 0x00, 0x00, 0xE3 };
DeviceAddress Probe05 = { 0x28, 0xCB, 0x3D, 0x68, 0x04, 0x00, 0x00, 0x03 };

void setup()   /****** SETUP: RUNS ONCE ******/
{
// start serial port to show results
  Serial.begin(9600);
  Serial.print("Initializing Temperature Control Library Version "); 
  Serial.println(DALLASTEMPLIBVERSION);
  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  
    // Set the RPM of the motor
  myStepper.setSpeed(30);

  // Turn on pulse width modulation
  pinMode(pwmA, OUTPUT);
  digitalWrite(pwmA, HIGH);
  pinMode(pwmB, OUTPUT);
  digitalWrite(pwmB, HIGH);

  // Turn off the brakes
  pinMode(brakeA, OUTPUT);
  digitalWrite(brakeA, LOW);
  pinMode(brakeB, OUTPUT);
  digitalWrite(brakeB, LOW);

  // Log some shit
  Serial.begin(9600);
  
}//--(end setup )---

void loop(){                                                                                                                   
  startup();
  start01();
}


void start01()
{
sensors.requestTemperatures();
temp01 == (sensors.getTempC(Probe01));
temp02 == (sensors.getTempC(Probe02));
temp03 == (sensors.getTempC(Probe03));
temp04 == (sensors.getTempC(Probe04));
temp05 == (sensors.getTempC(Probe05));
if (temp01 > (temp02 || temp03 || temp04 || temp05))
  {
   myStepper.step(STEPS*0);
   delay(1000);
   start01();
  }
else if (temp02 > (temp01 || temp03 || temp04 || temp05))
  {
   myStepper.step(STEPS*1);
   delay(2000);
   start02();
  }
else if (temp03 > (temp01 || temp02 || temp04 || temp05))
  {
   myStepper.step(STEPS*2);
   delay(3000);
   start03();
  }
else if (temp04 > (temp01 || temp02 || temp03 || temp05))
  {
   myStepper.step(STEPS*3);
   delay(4000);
   start04();
   }
else 
  {
    myStepper.step(STEPS*4);
    delay(5000);
    start05();
  }
}

void start02()
{
sensors.requestTemperatures();
temp01 == (sensors.getTempC(Probe01));
temp02 == (sensors.getTempC(Probe02));
temp03 == (sensors.getTempC(Probe03));
temp04 == (sensors.getTempC(Probe04));
temp05 == (sensors.getTempC(Probe05));
if (temp01 > (temp02 ||temp03 || temp04 || temp05))
  {
   myStepper.step(-STEPS*1);
   delay(1000);
   start01();
  }
else if (temp02 > (temp01 || temp03 || temp04 || temp05))
  {
   myStepper.step(STEPS*0);
   delay(2000);
   start02();
  }
else if (temp03 > (temp01 || temp02 || temp04 || temp05))
  {
   myStepper.step(STEPS*1);
   delay(3000);
   start03();
  }
else if (temp04 > (temp01 || temp02 || temp03 || temp05))
  {
   myStepper.step(STEPS*2);
   delay(4000);
   start04();
   }
else 
  {
    myStepper.step(STEPS*3);
    delay(5000);
    start05();
  }
}

void start03(){
sensors.requestTemperatures();
temp01 == (sensors.getTempC(Probe01));
temp02 == (sensors.getTempC(Probe02));
temp03 == (sensors.getTempC(Probe03));
temp04 == (sensors.getTempC(Probe04));
temp05 == (sensors.getTempC(Probe05));
if (temp01 > (temp02 || temp03 || temp04 || temp05))
  {
   myStepper.step(-STEPS*2);
   delay(1000);
   start01();
  }
else if (temp02 > (temp01 || temp03 || temp04 || temp05))
  {
   myStepper.step(-STEPS*1);
   delay(2000);
   start02();
  }
else if (temp03 > (temp01 || temp02 || temp04 || temp05))
  {
   myStepper.step(STEPS*0);
   delay(3000);
   start03();
  }
else if (temp04 > (temp01 || temp02 || temp03 || temp05))
  {
   myStepper.step(STEPS*1);
   delay(4000);
   start04();
   }
else 
  {
    myStepper.step(STEPS*2);
    delay(5000);
    start05();
  }
}

void start04(){
sensors.requestTemperatures();
temp01 == (sensors.getTempC(Probe01));
temp02 == (sensors.getTempC(Probe02));
temp03 == (sensors.getTempC(Probe03));
temp04 == (sensors.getTempC(Probe04));
temp05 == (sensors.getTempC(Probe05));
if (temp01 > (temp02 || temp03 || temp04 || temp05))
  {
   myStepper.step(-STEPS*3);
   delay(1000);
   start01();
  }
else if (temp02 > (temp01 || temp03 || temp04 || temp05))
  {
   myStepper.step(-STEPS*2);
   delay(2000);
   start02();
  }
else if (temp03 > (temp01 || temp02 || temp04 || temp05))
  {
   myStepper.step(-STEPS*1);
   delay(3000);
   start03();
  }
else if (temp04 > (temp01 || temp02 || temp03 || temp05))
  {
   myStepper.step(STEPS*0);
   delay(4000);
   start04();
   }
else 
  {
    myStepper.step(STEPS*1);
    delay(5000);
    start05();
  }
}


void start05()
{
sensors.requestTemperatures();
temp01 == (sensors.getTempC(Probe01));
temp02 == (sensors.getTempC(Probe02));
temp03 == (sensors.getTempC(Probe03));
temp04 == (sensors.getTempC(Probe04));
temp05 == (sensors.getTempC(Probe05));

if (temp01 > (temp02 || temp03 || temp04 || temp05))
  {
   myStepper.step(-STEPS*4);
   delay(1000);
   start01();
  }
else if (temp02 > (temp01 || temp03 || temp04 || temp05))
  {
   myStepper.step(-STEPS*3);
   delay(2000);
   start02();
  }
else if (temp03 > (temp01 || temp02 || temp04 || temp05))
  {
   myStepper.step(-STEPS*2);
   delay(3000);
   start03();
  }
else if (temp04 > (temp01 || temp02 || temp03 || temp05))
  {
   myStepper.step(-STEPS*1);
   delay(4000);
   start04();
   }
else 
  {
    myStepper.step(STEPS*0);
    delay(5000);
    start05();
  }
}

void startup()
  {
    myStepper.step(-STEPS*2);
    delay(8000);
    
  }

Haven't worked with them but this seems odd:
temp01 == (sensors.getTempC(Probe01));
OR
temp01 = (sensors.getTempC(Probe01));

Hi, how do you know where your stepper is pointing when you start the program.
A servo would have been easier.
You read the sensors and which ever is highest you give the position to the servo and it turns there.
At the moment you have no idea, that I can see, as to what direction the fan is pointing initially.
It seems like a lot of code to find highest sensor and point a fan.
Also from inside start01 you call start02 and from in start02 you call etc etc. If you are looking for a temperature drop due to the fan to see if it is pointed in the right place, good luck.
Do you know if the you are getting valid readings from the sensors first.
If you don't know, then I suggest you start by programming a step at a time, get the sensor readings right first, then the sorting of which is highest, then the stepper control.
Have you made sure that the motor shield is not using pins that you have for the temp sensors?

If you are sure you want to use the stepper you will have to have a sensor/switch that tells you when the stepper is in its initial position. Then step to the required position pointing at the hottest sensor.

Tom... :slight_smile:

The startup() function sets the stepper to the initial point (probe01). The slide I have constructed allows for the small base I have to spin freely and not damage anything even if it is up against one of the ends. So that is how I know where the motor is positioned on start up.

A servo is not an option at this time.

Is there a better way that you know of to find the highest sensor, compare it to other values then move it?

How would I not see the temperature drop? I am not sure what the problem is, or am not understanding what the problem is.

I have already tested, and just now retested the code for the sensors. Each is able to be read and gives a unique value, as well as changes when applying heat.

Yes the motor shield and pins are on different pins, no conflict there.

if (temp01 > (temp02 || temp03 || temp04 || temp05))

Inventing syntax hasn't worked for anyone else. There is no reason to believe that it will work for you. This is not how to compare one temperature to 4 others.

How would I go about doing so? I am sure the answer is obvious but I can't think of it at the moment. (Off to google for me)

Check testing it out it seems that it just goes from The start01() function to start05() function and constantly repeats the last else statement in it.

Could I possibly put those temp01 ... temp05 values into an array then use the max(x.y) function then use cases to tell my motor where to go?

How would I go about doing so?

if(temp01 > temp02 || temp01 > temp03 || temp01 > temp04 || temp01 > temp05)
{
   // temp01 is highest
}

Putting the 5 values in an array, and writing a function that returns the index of the largest value in the array would make for simpler code, overall.