I have just finished building a DIY controller as part of a home-brewed antenna rotator project. The controller allows simple clockwise and counterclockwise movement of the stepper motor using 4 buttons. The motor may be replaced with a larger one depending on the intended load. I have added an optional speaker for audible feedback.
To view the circuit diagram, head directly to Stepper Motor Controller using Arduino.
I have posted the sketch below:
//DIY Rotator Controller Sample Sketch
//November 30, 2019
//DIY Rotator Controller
//du1au@nightskyinfocus.com
#include <Stepper.h>
//initialize Azimuth motor
const int stepperPin1 = 9; //Stepper pin
const int stepperPin2 = 10; //Stepper pin
const int stepperPin3 = 11; //Stepper pin
const int stepperPin4 = 12; //Stepper pin
Stepper AZstepper(6330, stepperPin1, stepperPin2, stepperPin3, stepperPin4);
int motorSpeed = 3; //Motor speed
const int Button1 = 2; //Button pin
const int Button2 = 3; //Button pin
const int Button3 = 4; //Button pin
const int Button4 = 5; //Button pin
int speakerPin = 6; //Tones feedback
void setup() {
Serial.begin(9600);
pinMode(stepperPin1, OUTPUT); //AZStepper pin
pinMode(stepperPin2, OUTPUT); //AZStepper pin
pinMode(stepperPin3, OUTPUT); //AZStepper pin
pinMode(stepperPin4, OUTPUT); //AZStepper pin
AZstepper.setSpeed(motorSpeed); //AZStepper speed
playLongHighBeep();
}
void loop() {
if(digitalRead(Button3) == HIGH){ //Orange
playHighTone();
AZstepper.step(1582);
playHighTone();
}
if(digitalRead(Button4) == HIGH){ //Yellow
playHighTone();
AZstepper.step(-1582);
playHighTone();
}
while(digitalRead(Button1) == HIGH){ //Red
AZstepper.step(1);
playLowTone();
}
while(digitalRead(Button2) == HIGH){ //Green
AZstepper.step(-1);
playLowTone();
}
}
void playHighTone()
{
tone(speakerPin, 7040, 50); //High tone
}
void playLongHighBeep()
{
tone(speakerPin, 2000, 2000); //Long high tone
}
void playLowTone()
{
tone(speakerPin, 55, 50); //Low tone
}
To view all posts on amateur radio, click here.
Related link: Stepper Motor Controller
Night Sky in Focus
Astronomy and Amateur Radio
© Anthony Urbano (Manila, Philippines)