Schrittmotor Steuerung für Antennen Rotor - AZ-Delivery

For the reception of satellite television in the motorhome you can buy an expensive automatic satellite antenna or a simple inexpensive satellite antenna on a tripod and align manually. This is usually very time-consuming and since the antenna is outside the TV receiver but inside, you can observe the success of the tuning only poorly.

A much more convenient and still cheap solution is the antenna rotor with stepper motor control presented here. The stepper motor is controlled by a NodeMCU LUA Amica VS module with ESP8266 12F so that the operation can be done via WLAN. For this purpose the ESP8266 is operated as an access point. With a smartphone you can then easily control the antenna rotor.

In this operating mode the ESP8266 always receives the IP address 192.168.4.1.

The presented program creates a WLAN with the SSID "antenna" and the password "womo12345". Of course, this can be changed by making changes in the program.

If the antenna rotor is powered, you can find a WLAN with the name "Antenna" in the WLAN list of the smart phone. We now connect to this WLAN and start a browser app. As URL we enter 192.168.4.1.

We should now see the following homepage in the browser:

When we click on one of the buttons the antenna should rotate in the desired direction.


Parts list:

 

 



/*
 * Copyright (c) 2015, Majenko Technologies
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * 
 * * Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 * 
 * * Neither the name of Majenko Technologies nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* Create a WiFi access point and provide a web server on it. */

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

/*HTML Code für die Homepage der Steuerung
 * Es handelt sich dabei um ein einfaches Formular mit einem
 * Eingabefeld für die Geschwindigkeit und drei Knöpfen
 * Rechts, Links und Stop
 */
const char INDEX_HTML[] =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<meta name = \"viewport\" content = \"width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=0\">"
"<title>Antennenrotor</title>"
"<style>"
"body { background-color: #d2f3eb; font-family: Arial, Helvetica, Sans-Serif; Color: #000000; }"
"input { font-size:16pt; }"
"</style>"
"</head>"
"<body>"
"<h1>Antennenrotor</h1>"
"<FORM action=\"/data\" method=\"post\">"
"<P>"
"<INPUT type=\"submit\" name=\"LINKS\" value=\"Links\">&nbsp;"
"<INPUT type=\"submit\" name=\"STOP\" value=\"Stop\">&nbsp;"
"<INPUT type=\"submit\" name=\"RECHTS\" value=\"Rechts\"><br><br>"
"Geschwindigkeit (1 - 10):<br>"
"<INPUT type=\"text\" value=\"%i\" name=\"SPEED\">" 
"</P>"
"</FORM>"
"</body>"
"</html>";

//Globale Variablen
const char *ssid = "Antenne"; //Name des WLAN 
const char *password = "womo12345"; //Passwort für das WLAN

const int stp = 12; //Pin Nummer für den Step Anschluss des Motor Treibers
const int dir = 13; //Pin Nummer für den Richtungs Anschluss des Motor Treibers
int richtung = 0; //aktuelle Richtung
int dly = 100; //Verzögerung für Motor Schritte
int spd = 1; //aktuelle Geschwindigkeit

ESP8266WebServer server(80); //Web-Server starten auf Port 80

//Diese Funktion wird aufgerufen wenn der Request an den Web-Server = "/" ist
void handleRoot() {
  char html[1000];//Buffer für Request
  //Sende die Homepage an den Browser wobei die Geschwindigkeitseingabe
  //mit derv aktuellen Geschwindigkeit vorbesetzt wird
  sprintf(html, INDEX_HTML,spd); 
  server.send(200, "text/html", html );
}

//Diese Funktion wird aufgerufen wenn der Request "/left" ist
void handleLeft() {
  richtung = 1;//Richtung auf links und mit Homepage antworten
  handleRoot();
}

//Diese Funktion wird aufgerufen wenn der Request "/right" ist
void handleRight() {
  richtung = 2; //Richtung auf rechts und mit Homepage antworten
  handleRoot();
}

//Diese Funktion wird aufgerufen wenn der Request "/stop" ist
void handleStop() {
  richtung =0; //Richtung auf stop und mit Homepage antworten
  handleRoot();
  
}

//Diese Funktion wird aufgerufen wenn der Request "/data?..." ist
void handleData() {

  String sspd;
  //Abhängig von den Argumenten des Requests werden Richtung und
  //Geschwindigkeit gesetzt. Geschwindigkeit zwischen 1 und 10
  if (server.hasArg("LINKS")) richtung = 1;
  if (server.hasArg("RECHTS")) richtung = 2;
  if (server.hasArg("STOP")) richtung = 0;
  if (server.hasArg("SPEED")) {
    sspd = server.arg("SPEED");
    spd = sspd.toInt();
    if (spd < 1) spd = 1;
    if (spd > 10) spd = 10;
    dly = (11-spd)*10; //Schrittabstand 100 bei Geschwindigkeit 1
                       //und 10 bei Geschwindigkeit 10
  }
  handleRoot(); //Mit Homepage antworten
}

void setup() {
  //Pins vorbereiten
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  digitalWrite(stp,HIGH);
  digitalWrite(dir,HIGH);
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  //ip ist immer 192.168.4.1
  //Definition der Antwortfunktionen
  server.on("/", handleRoot);
  server.on("/left", handleLeft);
  server.on("/right", handleRight);
  server.on("/stop", handleStop);
  server.on("/data", handleData);
  //Web Server starten
  server.begin();
  Serial.println("HTTP server started");
}

//Hauptschleife
void loop() {
  //Auf Request prüfen
  server.handleClient();
  //je nach Richtung den Richtungs Pin setzen
  //und einen Schritt am Step Pin ausgeben 
  //Schrittlänge in ms ist durch dly bestimmt
  if (richtung == 1) {
    Serial.println("links");
    digitalWrite(dir,LOW);
    digitalWrite(stp,LOW);
    delay(dly);
    digitalWrite(stp,HIGH);
    delay(dly);
  }
  if (richtung == 2) {
    Serial.println("rechts");
    digitalWrite(dir,HIGH);
    digitalWrite(stp,LOW);
    delay(dly);
    digitalWrite(stp,HIGH);
    delay(dly);
  }
}

          
Esp-8266Projekte für fortgeschrittene

8 comments

Heinz K.

Heinz K.

Danke, hat soweit funktioniert. Falls jemand wissen möchte wozu ich das benutze kann das unter youtu.be/x0KHGZSZVEE eingesehen werden.

Andreas Wolter

Andreas Wolter

@Heinz K.: Sie könnten einen Counter einsetzen. Dafür bräuchten Sie zwei globale Variablen. Am besten oberhalb direkt unter int spd = 1; //aktuelle Geschwindigkeit

int counter = 0;
int maxCounter = 20;

counter ist der Zähler und maxCounter Ihre Grenze. Welcher Wert den 4,5cm entspricht, müssten Sie testen.

in die if-Anweisung fügen Sie dann den Code ein, der dafür sorgt, dass nach den festgelegten Schritten der stop-Befehl aufgerufen wird:
if (richtung == 1) {
Serial.println(“links”);
digitalWrite(dir,LOW);
digitalWrite(stp,LOW);
delay(dly);
digitalWrite(stp,HIGH);
delay(dly);
counter++;
if (counter > maxCounter) {
counter = 0;
handleStop();
}
}

Das wäre eine Lösung. Wenn ich das richtig verstanden habe, brauchen Sie nur einen Start Button. Daher könnte man das gesamte Programm weiter verschlanken.

Grüße,
Andreas Wolter
AZ-Delivery Blog

Heinz K.

Heinz K.

Hallo,
ich bin mit der Programmierung leider nicht so bewandert. Gibt es eine Möglichkeit das man mit den Tasten links und rechts immer eine bestimmte Anzahl der Drehungen anstösst und dann automatisch wieder stehen bleibt? Hintergrund: beim Luftgewehrschiessen gibt es 10er Schiessscheiben als Streifen auf dem die 10 Spiegel nebeneinander liegen. Diese müssen manuell weiter gezogen werden – immer ca. 4,5 cm. Ich würde aber gerne die Scheibe einspannen und nach jedem Schuss ein Knöpfchen drücken damit automatisch der nächste Spiegel erscheint. Das mit der Mechanik bekomme ich hin, nur an der Programmierung hakt es.

Andreas Wolter

Andreas Wolter

This Example shows the azimuth controll (left and right). For Elevation (up and down) any changes are needed. First you need a second stepper and second driver modul. Two more input fields in the HTML form. For example:
up
left stop right
down

Then you can duplicate the functions for direction handling and connect them to the left and right fields in this form.
The command
if (server.hasArg(“RECHTS”)) richtung = 2;
could expanded with 3 and 4 for up and down.
For the stepper controll you need one more variable: stp2
and you have to check if the variable dir is 3 or 4 then send the commands to the second stepper. Otherwise the first stepper will be moved.

Regards,
Andreas Wolter
AZ-Delivery Blog

Alberto

Alberto

Cool; It’s what I’ve been looking for for a long time.
If I want to control two motors (Azimuth and Elevation), what should I add to the code?
Thanks a lot

ani

ani

Und woher bekomme ich das Getriebe? Ohne Mechanik, sprich Getriebe, ist das alles Makulatur. Und wie ist es mit der Vertikalsteuerung Gibt es dafür auch Ideen? So werden z. Bsp. in anderen Bereichen der Funktechnik der Mond, Meteorschwärme, Flugzeuge oder Wolken angesteuert.

Jörg Mehring

Jörg Mehring

Hallo,
die Stromversorgung könnte man vielleicht der Phantomspeisung des LNBs entnehmen, da die Polarisation über eine Schaltspannung von 14 bis 18 Volt eingestellt wird. Je nach Strombedarf der o.g. Schaltung sollte das gehen.

Frank Jetzschmann

Frank Jetzschmann

Hallo,
bei Verwendung von (größeren) Schrittmotoren ist zwingend ein (mindestens) 100µF Elko direkt an der Schrittmotorsteuerplatine (+12V Anschluss) notwendig. Sonst wird die Schrittmotorsteuerplatine zerstört. Hinweise zu diesem Phänomen finden sich in diversen Applikationsschaltungen im Internet.

Sonst eine wirklich clevere Lösung mit Potential für eigene Verbesserungen :-)

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery