0

I am new to Arduino, some how I have put this code together to run stepper motor using LDR(kind of solar tracker program) I searched on net and tried using servo motor circuit to run stepper motor, assuming just replacing servo motor with stepper motor would work. I guess that is not the case (because servo motor is not moving according to LRD inputs). Please help me with circuit diagram.

Here is the code I am using


const int dirPin  = 5;
const int stepPin = 4;
const int enPin   = 6;
const int SensorPin1 = A0;
const int SensorPin2 = A1;
int sensorValue1 = 0;
int sensorValue2 = 0;

void setup() {

  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);

  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,LOW);
  Serial.begin(9600); 

}
void loop() {
  sensorValue1 = analogRead(SensorPin1); 
  Serial.println(sensorValue1);
  sensorValue2 = analogRead(SensorPin2); 
  Serial.println(sensorValue2);

  if(sensorValue1 < 40 && sensorValue2 < 400){
    Serial.print("No sun Detected");
    digitalWrite(dirPin,LOW);
    digitalWrite(stepPin,LOW);
  }
  else if(sensorValue1 > 400){

    digitalWrite(dirPin,HIGH);
    digitalWrite(stepPin,HIGH);

 }
else if(sensorValue2 > 400){
    digitalWrite(dirPin,LOW);
    digitalWrite(stepPin,HIGH);
}
}

Hardware Used:

  • Bipolar stepper motor- NEMA 23 20Kg torque
  • Stepper driver: TB6600
  • Power supply: SMPS 12V, 5amp
  • LDR: 2
  • Resistors: 2, 10K resistors
  • 1 Arduino Uno
  • Breadboard

Circuit Diagram

  • 1
    With most stepper drivers the stepper will move 1 (!) step when you put 1 pulse on the input (meaning a transition low-high-low or invers). Your code will at most drive the motor 1 step, most likely not enough to see it. Generate more pulses – chrisl Apr 6 at 21:56
  • Change digitalWrite(stepPin,LOW); to digitalWrite(stepPin,LOW);delay(1);digitalWrite(stepPin,HIGH); – Gerben Apr 7 at 15:07
  • Thanks @chrisl ..will try and let you know...but I am still looking for circuit digram – Adwaiot Sakarde Apr 9 at 16:12
  • For the circuit diagram: Have you seen for example this User Guide on the TB6600? There it is mentioned, how the driver has to be connected to the Arduino and to the motor. You can even download the more detailed user guide as pdf. – chrisl Apr 10 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.