Remote control for antenna rotor

The antenna rotor described in the last post can be controlled via WLAN. If you don't want to use your smartphone to do this, you can also use the remote control described in this article.

This remote control has two buttons and a potentiometer. A NodeMCU LUA module with ESP8266 working as a web client sends every change to the buttons to a web server. In addition, a value between 1 and 10 is always sent, depending on the potentiometer position.

Circuit:

Whenever the status of the two buttons changes, a request is sent to the server.

 

Parts list:

Arduino sketch:

/**
  * BasicHTTPClient.ino
 *
  * Created on: May 24th, 2015
 *
 */

#include <Arduino.H>

#include <ESP8266WiFi.H>
#include <ESP8266WiFiMulti.H>

#include <ESP8266HTTPClient.H>


//Global variables
const char *ssid = "Antenna";
const char *password = "womo12345";
String message; // message for request
int speed; // current speed 1 to 10
int btn; // current button value
int lastBtn = 0; // button value for last action

ESP8266WiFiMulti WiFiMulti;

// This function sends a request to the web server
void sendRequest( String cmd, int spd) {   Serial.println("Start request");
 if((WiFiMulti.run() == WL_CONNECTED)) {      HTTPClient http;    // Declare object of class HTTPClient        http.begin("http://192.168.4.1/data");     // URL to send form data to the web server    http.addHeader("Content type", "text / plain");  // Specify content-type header    message = "SPEED ="+String(spd)+"&"+cmd+"=1"; // arguments for the HTTP request    Serial.println("Start Post");      int httpCode = http.POST OFFICE(message);   // Send the request    String payload = http.getString();   // Hole response can be ignored      Serial.println(httpCode);   // Print HTTP return code      http.end();  // end connection
 
 }  else {   Serial.println("connection problem");
 }    }

void set up() {     Serial.begin(115200);   // Prepare pins   pinMode(D6,INPUT_PULLUP); // D6 is a button for the left   pinMode(D7,INPUT_PULLUP); // D7 is button for right   // wait until ESP8266 is ready     for(uint8_t t = 4; t > 0; t--) {         Serial.printf("[SETUP] WAIT% d ... \ n", t);         Serial.flush();         delay(1000);     }     // connect to the WiFi antenna     WiFi.Fashion(WIFI_STA);     WiFiMulti.addAP(ssid,password);


}

// main loop
void loop() {   // read potentiometer value of A0   // value is between 0 and 1024   // divided by 100 gives 0 to 10   speed = analogRead(A0)/100;   Serial.println(speed);   // Set the minimum value to 1   if (speed < 1) speed = 1;   // Read both buttons into one variable   // left = 1;   // right = 2;   // none = 3;   // both = 0;   btn = digitalRead(D6) + 2 * digitalRead(D7);   // Only if the button value has changed   if (btn != lastBtn) {     // Note the key value and send the corresponding request     lastBtn = btn;     switch(btn) {       case 0: Serial.println("STOP");         sendRequest("STOP",speed);         break;       case 1: Serial.print("LEFT ");         Serial.println(speed);         sendRequest("LEFT",speed);         break;       case 2: Serial.print("RIGHT ");         Serial.println(speed);         sendRequest("RIGHT",speed);         break;       case 3: Serial.println("STOP");         sendRequest("STOP",speed);         break;     }   }   Wait //0.1 s   delay(100);
}
Projects for advanced

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN