0

Good afternoon dear community,

I am trying to built a WiFi communication with Arduino using ESP8266 module. There is one servo, one step motor connected to Arduino and whenever the ESP8266 Wi-Fi module receives a signal, the voltage level on the motor and servo fluctuate dramatically, which causes inaccurate results on how motor and servo behaves. I have connected the ESP8266 module using SoftwareSerial, and even when the signal is not transferred into motor or sevo, the voltage levels change whenever a data is received by the WiFi module.

Below is my code,

#include <Servo.h>
#include "SoftwareSerial.h"
SoftwareSerial softSerial(10, 11); // RX, TX

// Components:
Servo servo1;
Servo firstESC;

// Motor:
const int MAX_SPEED = 1850;
const int MIN_SPEED = 1200;
int armValue = 1500;
int speedIncrease = 20;
int speedDecrease = speedIncrease * 3;

// Direction:
int currentPos;
const int MAX_ANGLE = 120;
const int MIN_ANGLE = 60;
const int MID_ANGLE = 90;

void setup() {
   Serial.begin(9600);
   Serial.setTimeout(10);

   softSerial.begin(9600);
   // softSerial.setTimeout(10);

   // Setup servo:
   servo1.attach(9);
   servo1.write(90);

   // Setup direction:
   Serial.println("The motor is arming in 2 seconds, please wait.");
   firstESC.attach(8);

   // Arm the motor after 2 seconds:
   delay(2000);
   firstESC.writeMicroseconds(armValue);

   Serial.println("Serial is setting up, wait time: 3000 ms.");
   delay(3000);

   // Check board communication:
   softSerial.println("AT");
   delay(1000);
   while (softSerial.available()) {
     String message = softSerial.readString();
     Serial.println(message);
     delay(1000);
   }

   // Connect to WIFI:
   Serial.println("Connecting to wifi, wait time 4000 ms.");
   softSerial.println(--- COMMAND TO CONNECT WIFI ---);
   delay(4000);
   while (softSerial.available()) {
     String message = softSerial.readString();
     Serial.println(message);
     delay(1000);
   }

   // Wait for connection to be stable:
   delay(2000);

   // Get IP address:
   Serial.println("Requesting IP Address.");
   softSerial.println("AT+CIFSR");
   delay(2000);
   softSerial.println("AT+CIPMUX=1"); // Set multiple connection available.
   while (softSerial.available()) {
     String message = softSerial.readString();
     Serial.println(message);
     delay(1000);
   }

   delay(2000);

   // Set up server:
   Serial.println("Connecting to server..");
   softSerial.println("AT+CIPSTART=3,\"TCP\",\"192.168.1.67\",1235");
   delay(2000);
   while (softSerial.available()) {
     String message = softSerial.readString();
     Serial.println(message);
     delay(1000);
   }

   Serial.println("Set up is complete, loop started.");

}

String inString = "";
bool reading = false;

void loop() {

   while (softSerial.available() > 0)
   {
    char inChar = softSerial.read();

    if(inChar == 'O') {
      reading = false;
    }

    if(reading) {
      if (inChar == ','){
        Serial.println(inString);
        int val = inString.toInt();

        //Motor input
        if (val >= MIN_SPEED && val <= MAX_SPEED){
          setSpeed(val);
        }

        //Direction input
        else if (val >= MIN_ANGLE && val <= MAX_ANGLE ){
          setRotation(val);
        }
        inString = "";
      }
      else{
        if(inChar !='\0' && inChar != '\n' ){
          inString += inChar;
        }  
      }
    }

    if(inChar == ':') {
      reading = true;
    }

   }

   if (Serial.available())
   {
      String message = Serial.readString();
      // Serial.print(message);
      setSpeed(message.toInt());
   }
}

void setSpeed(int customSpeed){
  firstESC.writeMicroseconds(customSpeed);
}

void setRotation(int angles){
  servo1.write(angles);
}

closed as unclear what you're asking by per1234, VE7JRO, gre_gor, Greenonline, MatsK Aug 9 '18 at 18:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • This might be an issue with having a weak (or not stabilized) power supply. When system momentarily draws to much current it drops the voltage. What do you use to power your circuit? – Filip Franik Aug 7 '18 at 11:03
  • When it is connected to USB or a 7.5 V power supply, creates the same issue. – Uğur Kaya Aug 7 '18 at 11:12
3

The ESP8266 is notoriously noisy, chiefly because the cheap boards the ESP8266 is commonly sold on don't implement any form of power filtering.

So you really have to add your own. As I had to recently when adding an ESP8266 board to an audio system.

For that I came up with this schematic:

enter image description here

VCCA is your main incoming power. VCCD feeds the power into the ESP8266. The motors are connected to the same point as VCCA.

  • Are you planning on marketing this as a kit? – Code Gorilla Aug 7 '18 at 11:44
  • I wasn't, no. I guess I could though... – Majenko Aug 7 '18 at 12:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.