Help me with this big problem i got

I am confused about something. I need to porgramm a Stepper Motor so that if the temperature's at a certain degree the Motor has to start moving clockwise or counterclockwise. The Problem is that I literally cannot programm this with my current skills.

Here's the code which is already spinning in bouth direktions.

  //STEPPER
  #define dirPin 2 //5
  #define stepPin 5 //2
  #define enablePin 8 
  #define stepsPerRevolution 200


  #define UP true      
  #define DOWN false   
  #define StepperON LOW 
  #define StepperOFF HIGH
  
  //TEMP
  
  #include "DHT.h"

  int DHTPIN = 12;
  #define DHTTYPE DHT11
  DHT dht(DHTPIN, DHTTYPE);
  
void setup() {
  // Declare pins as output:
  Serial.begin(9600);
  
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enablePin, OUTPUT);

  Serial.println(F("DHTxx test!"));
  dht.begin(); 
}



void loop() {
  //TEMP

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(t);
  Serial.println(F("C"));
  
 

  // Spin the stepper motor 1 revolution slowly:
  for (int i = 0; i < 25 * stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(2000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(2000);
  }
  digitalWrite(enablePin, StepperOFF);

  delay(10);


  // Set the spinning direction counterclockwise:
  digitalWrite(dirPin, LOW);
  digitalWrite(enablePin, StepperON);

  // Spin the stepper motor 1 revolution quickly:
  for (int i = 0; i < stepsPerRevolution; i++) {
    
    
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(10);
  }
  digitalWrite(enablePin, StepperOFF);

  delay(10);
}

If anyone could help me with this problem i'd be thrilled.

Hello luigi19
Run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.
Have a nice day and enjoy coding in C++.

I already watched so many tutorials but i just can't figure it out :frowning:

so many tutorials are definitive enough. now you can give up.

the specification of your problem is vauge
when the temperature reaches a certain level do you
spin clockwise
or spin anticlockwise
or spin clockwise then anticlockwise

where does the

 // Spin the stepper motor 1 revolution slowly:

come in?

that is why you have no success, Stepper motor is not able to be programed.

If the Temperature reaches a certain level (for example 20°C) the Motor has to spin in one direction if it exceeds this in like 40°C it should spin in the other direktion
All i have to do now is to make an "if sentence" which defines it but i guess i can't get it to work.

something along the lines of

void loop() {
    int temperature = readTemperature();
   if(temperature >= 20 && themperature < 40)
        spin clockwise one stp
  else
   if (temperature >=40)
       spin anticlockwise one step
}

Hello
Did you think about to use a servo as temperature indicator?

my understanding of the purpose of thi user-forum is:
giving support to learn to code. Not posting ready to use code.

well 95% of all video-tutorial on youtube are of questionable quality.
One way is to ask for high-quality introductional tutorials.

If you have searched for "turn steppermotor if temperature" or something similar it is very likely that you get all kinds of results that do NOT help.
The chance is as low as 1 in a billion that somebody has made a video that fits exactly to your exercise.

programming i like Lego. some basic bricks that can be combined in million ways to perform milions of different things.
stay realxed. The basic set of "lego-bricks" = functions is small.
If you have understood the basic functionality you can start to vary the usage.
So any high-quality tutorial about if-conditions is useful.
You may ask how can I judge the quality of a video without having experience?

Very easy:
start watching the first 30 seconds of the video. If there are already 2 or 3 things you don't understand, skip the entire video. Quality and/ or niveau of the video don't fit to you.

what is your personal prefered learning style?
if you are more on reading give this tutorial a try
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

Make a first attempt how your if-condition might look like.
Your code doesn't even have to compile. Just write the first attempt and post a specific question. In this way the forum can be your very personal tutorial to whatever.

imagine learning to perform a backflip on a BMX-bike in the halfpipe.
You don't start with the backflip. You start with much easier things.
Same thing for programming. Start with something easier than "make stepper-motor spin clockwise if temperature is below 20°C.

I haven't done a intensive resaerch for good turorials. This one seems to be quite OK so if you are more on videos give it a try

best regards Stefan

bevor reading pls translate from german to english thx

Hi,
ich danke Ihnen für ihre Zeit die Sie aufgewendet haben um mir eine so ausführliche Nachricht zu schreiben um mir mitzuteilen das ich im Grunde genommen nichts über Arduino kenne. Was ich natürlich auch verstehen kann, da ich eigentlich eine ziemlich dumme Frage gestellt habe was das an geht. Da ich aber schon vor ca. 2 Jahren mit dem Programmieren angefangen habe und schon einiges gelernt und auch selbst Programmieren durfte ist es nicht notwendig mir eine Anfänger Tutorial zu zeigen und damit abzuschließen. Mein Problem liegt dabei eigentlich nur bei dem Stepper Motor mit dem ich bis zu diesem Zeitpunkt noch gar nicht arbeiten konnte. Da ich diesen jetzt aber für meine Abschlussprojekt benötige muss ich diesen nun Programmieren. Leider stellte es sich heraus das es ziemlich schwer ist einen Stepper Motor vernünftig zu Programmieren was leider zur Folge hat das ich in einem Arduino Forum um Hilfe gebeten habe. Aber anscheinend sind hier auch alle genauso Hilflos wie ich. Dennoch bedanke ich mich für ihre Aufmerksamkeit und den versuch mir Anfänger Tutorials unter die Nase schieben zu wollen. Weiteres habe ich einen Bekannten gefunden welcher mir bei meinem Problem sehr gut helfen kann womit ich mein Problem ganz gut lösen kann.

best regards Simon

Hi Simon,

first of all this forum is for support. Writing such a short description and a so much generalised question makes it very probable that you are real beginner.

we (the other users) in this forum only know what you have told us.
From the few things that you have posted I had to make a lot of assuming decisions about you. Especially about your knowledge-level.

You have written that you started two years ago with programming.
Still just very few information. What shall I assume?

The program you posted does not contain a single if-condition.

In combination with the title "big problem"

If you think about this:
which assumption is most likely?

The more you describe about your programming skills, the more specific you ask
the better the anwers will be adapted to your situation.

Or if you would ask: "can somebody post a link to a stepper-motor demo I can learn with"

With what I write below I do not claim that this is the truth. It is just one out of many possabilities

The pretty generalised question you have posted has a probability to have this intention:

I keep my question generalised for hoping somebody will post a ready to use code
so I don't have to learn it.

Just a probability. Not the truth. The only one who knows the truth are you.

As soon as you show own effort by trying it and by writing

specific questions about one detail of the code

the support will rush in.

So my final advice is:
tips how to improve your posting style

best regards Stefan

wir sind genauso hilflos und faul wie du.

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