Introduction: Linkit One and RGB LEDs

This is my first instructable and in this instructable I'm going to show you how to control a RGB LED using a Linkit One wireless (WiFi).

Step 1: List of Parts

  • Linkit One
  • RGB LEDs (Common Anode)
  • Bread Board
  • Wires
  • PC

Step 2: RGB LED

I used a RGB LED in common cathode configuration, the cathodes of the Red, blue and green go to pin 1, pin 2 and pin 3.

Step 3: Micro USB

Next you need to connect a micro USB between the Linkit One and your PC, and install the necessary drivers from the Linkit One official site.

Step 4: Code

Use the arduino IDE to upload the code to the board, you need to modify the IDE to make it support the Linkit One board. Also enter your network ssid and password.

<p>/*<br>  WiFi Web Server</p><p> Change the macro WIFI_AP, WIFI_PASSWORD and WIFI_AUTH to your own router settings.</p><p> */
#include 
#include 
#include 
#include </p><p>#define WIFI_AP "ssid"
#define WIFI_PASSWORD "password"
#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration
//I would try LWIFI_WPA first
//if that fails LWIFI_WEP
//if that fails LWIFI_OPEN (and find out why you are giving WiFi to the neighbours!)</p><p>int serverPort = 80;
LWiFiServer server(serverPort);
int LED = 13;</p><p>void setup()
{
  pinMode(LED, OUTPUT);
  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);</p><p>  }
  digitalWrite(LED, HIGH);
  printWifiStatus();
  Serial.println("Start Server");
  server.begin();
  Serial.println("Server Started");
  digitalWrite(LED, LOW);
}</p><p>int loopCount = 0;</p><p>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 = client.read();
        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 = "";
        }</p><p>        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
</p><p>\n</p><p>");
            IPAddress ip = LWiFi.localIP();
            client.println("
</p>");
            client.println("
Tell your device what to do!<br><br>Turn the LED on.<br>Turn the LED off.<br><br><p>");
            //i = digitalRead(LED);
            url.toLowerCase();
            if(url == String("/?q=on"))
            {
              digitalWrite(LED, HIGH);
              client.println("LED on<br>");
            }
            else if(url == String("/?q=off"))
            {
              digitalWrite(LED, LOW);
              client.println("LED off<br>");
            }
            else
            {
              client.println("Doing nothing<br>");
            }
            
            client.println("</p><p>\n</p><p>");
            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);</p><p>    // close the connection:
    Serial.println("close connection");
    client.stop();
    Serial.println("client disconnected");
  }
}</p><p>void printWifiStatus()
{
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(LWiFi.SSID());</p><p>  // print your WiFi shield's IP address:
  IPAddress ip = LWiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);</p><p>  Serial.print("subnet mask: ");
  Serial.println(LWiFi.subnetMask());</p><p>  Serial.print("gateway IP: ");
  Serial.println(LWiFi.gatewayIP());</p><p>  // print the received signal strength:
  long rssi = LWiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}</p>

Step 5: Run Time

Now open up a web browser and connect to the Linkit One's IP address and you should get controls to control the RGB LED.