Go Down

Topic: Controlling Servo over Wifi (Read 3249 times) previous topic - next topic



I just bought a WiFiShield for my arduino UNO. I came up with this idea to control a servo from a website but also from an app on my windows phone. From the website i can type in a value between 0-180 degree and then submit. It works fine! BUT! The app i wrote for my windows phone uses a slide that goes from 0-180. Each time the slide "slides" it sends the value to my server (arduino). The servo starts moving but after a while it stops, seems like the arduino crashes or something. I think its because of the large amount of data that is sent from my phone and somehow the arduino cant keep up.

Is there anyone that knows what the problem is?

Does the WiFiShield have any supports for UDP packets? Maybe it could be a solution for the bad response time.


#include <SPI.h>
#include <WiFi.h>
#include <Servo.h>

char ssid[] = "???";
char pass[] = "???";
int keyIndex = 0;
String buffer;
int status = WL_IDLE_STATUS;

WiFiServer serverTCP(1005);
Servo servo;

void setup()
   //config servo
   pinMode(8, OUTPUT);
   while (status != WL_CONNECTED)
      Serial.print("Attempting to connect to SSID: ");
      status = WiFi.begin(ssid, pass);


void loop()
   // listen for incoming clients
   WiFiClient client = serverTCP.available();
   digitalWrite(8, HIGH);
   if (client)
      String buffer = ""; 
      while (client.connected())
         if (client.available())
            char c = client.read();
            buffer += c;
            if(c == '\r')
               buffer = "";
               //client.flush();   ??????????????



There is a bug in the memory allocation routines that are used in the implementation of the String class that can cause a crash over time. Use a plain old C array of char instead - may help.


Thanks a lot! It helped! Never gonna use String again!

Go Up