Arduino – WiFi controlled RGB Leds

Following on from yesterdays post, I’ve decided that the remote control is not the way to go… I think these RGB LEDs need to be controlled from Internet.  Had a dig around in my parts bin and found a WiFly Shield, wrote a simple Telnet server for it that parses the colour data from the input and updates the PWMs.

Arduino WiFly Shield and RGB LED controller

Arduino WiFly Shield and RGB LED controller

Then wrote a PHP application that uses a colour wheel (jQuery based, called Farbtastic) to get a set colour and transmit the colour code over our network to the Arduino.

Basic RGB LED control page

Basic RGB LED control page

It uses a very simple socket connection to get the data over to the Arduino.. Here is the set colour handler:

<?php

$colour = $_REQUEST["c"];

$fp = fsockopen("10.0.0.67", 23, $errno, $errstr, 30);
$rply = '';
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = $colour."\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        $rply .= fgets($fp, 16);
    }
    fclose($fp);
}

if ( substr( $rply, 0, 2) == 'OK' ) {
    header("location:./?d=y&c=".urlencode($colour) );
    exit();
    }

header("location:./?d=n&c=".urlencode($colour) );
?>

Work nice, now I can set the light colour over the web… cool!