Linkit One Control a Servo

Introduction: Linkit One Control a Servo

In this instructable I'm going to show you how to control an servo with the Linkit One board. I'm going to show you how to control it both locally and over the internet since the Linkit One has a built in WiFi module. For this instructable I will be using a 5V arduino compatible servo along with the Linkit One as the Linkit One is very similar to an arduino.

Step 1: Components

Here is a list of all the components required to get started, make sure you collect all the components first before proceeding to other steps-





Step 2: Schematics

The schematics for both the local control and the web control are the same, it only changes that has to be made is in the program. The schematics can be found in the picture above, I had to use an arduino to represnt the linkit one as Fritzing doesn't have a library for the Linkit one yet.

Step 3: Local - Program

Here is the local program, it is a test program which rotates the servo in opposite directions.

To upload the program you need to install the Linkit one plugin along with the arduino IDE. You can find instructions on how to do that in the official website. You can also download the IDE with the Linkit One plugin pre-installed from GitHub.


Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }

void loop() { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }

Step 4: Web Program

Here is the web program, this will let you set the angle of the servo in a web application, the web server is hosted on the Linkit one and you need to enter in your WiFi credentials in the program. The IP address of the server will be displayed on a serial monitor once the board is connected to the WiFi network.

#include #include #include #include Servo myservo; #define WIFI_AP "SSID" #define WIFI_PASSWORD "PASSWORD" #define WIFI_AUTH LWIFI_WPA

int serverPort = 80; LWiFiServer server(serverPort); int LED = 13; int val;

void setup() { pinMode(LED, OUTPUT); myservo.attach(9); LWiFi.begin(); Serial.begin(115200); // keep retrying until connected to AP Serial.println("Connecting to AP"); while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) { digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(600);

} digitalWrite(LED, HIGH); printWifiStatus(); Serial.println("Start Server"); server.begin(); Serial.println("Server Started"); digitalWrite(LED, LOW); }

int loopCount = 0;

void loop() { // put your main code here, to run repeatedly: String str = ""; String url = ""; int i; delay(500); loopCount++; LWiFiClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { // we basically ignores client request, but wait for HTTP request end char c =; Serial.print(c); if(c != '\n') str += c; if(c == '\n') { //Serial.println(str); if(str.startsWith("GET ")) { url = str.substring(4, str.lastIndexOf(" ")); Serial.print("URL:"); Serial.print(url); Serial.println(":"); } str = ""; }

if (c == '\n' && currentLineIsBlank) { Serial.println("send response"); // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println(); if(url != String("favicon.ico")) { client.println(""); client.println(" \n \n


"); IPAddress ip = LWiFi.localIP(); client.println("

"); client.println("

Enter the servo angle, any value between 0 - 180"); client.println("


"); url.toLowerCase(); val = url.substring(4).toInt(); myservo.write(val); client.println("Current Servo Angle"); client.println(val); client.println("


"); client.println(); break; } } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(50);

// close the connection: Serial.println("close connection"); client.stop(); Serial.println("client disconnected"); } }

void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(LWiFi.SSID());

// print your WiFi shield's IP address: IPAddress ip = LWiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);

Serial.print("subnet mask: "); Serial.println(LWiFi.subnetMask());

Serial.print("gateway IP: "); Serial.println(LWiFi.gatewayIP());

// print the received signal strength: long rssi = LWiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }

Be the First to Share


    • Pocket-Sized Speed Challenge

      Pocket-Sized Speed Challenge
    • Audio Challenge 2020

      Audio Challenge 2020
    • Maps Challenge

      Maps Challenge