Bryan Morrison
Published © GPL3+

Making an Internet Controlled LED

Letting the internet socialize on a webcam pointed at an LED.

IntermediateFull instructions provided1 hour1,840
Making an Internet Controlled LED

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
For reading serial data and translating to PWM to drive the LED.
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
The brains of the bot. Takes websockets information in, streams TTS, music, and video to Remo.
×1
RGB LED
×1
Resistor 330 ohm
Resistor 330 ohm
×3
Logitech C270
Any USB webcam will do, this is just what I used.
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Remo.tv Controller

Story

Read more

Schematics

LED Bot Layout Diagram

How LED bot is wired

Code

led_bot.ino

Arduino
Code on the arduino to parse incoming serial coms from the raspberry pi
// Define the pins here, prefer PWM pins.
#define RED 6
#define GREEN 9
#define BLUE 10

#define MIN 0
#define MAX 255

int redVal = 0;
int greenVal = 0;
int blueVal = 0;
int brightnessStep = 25;  // This is how much the brightness changes for each event.

void setup() {
  Serial.begin(9600);
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
}

void loop() {
  // A standard incoming serial packet normally contains two characters.
  // "ru" would stand for "red up". It can handle multiple incoming, i.e.
  // "rurururugugugugububububu" would run red green and blue up 3 times.
  if (Serial.available() >= 2) {
    for (int i = 0; i < 2; i++) {
      command[i] = Serial.read();
    }
    switch(command[1]) {
      case 'd':
        switch(command[0]) {
          case 'r':
            redDown();
            break;
          case 'g':
            greenDown();
            break;
          case 'b':
            blueDown();
            break;
        }
        break;
      case 'u':
        switch(command[0]) {
          case 'r':
            redDown();
            break;
          case 'g':
            greenDown();
            break;
          case 'b':
            blueDown();
            break;
        }
        break;
      default:
        break;
    }
  }
  
  analogWrite(RED, redVal);
  analogWrite(GREEN, greenVal);
  analogWrite(BLUE, blueVal);
  
  // Clear the buffer if there's some odd amount of data.
  // Ideally this should never happen.
  if (Serial.available() % 2 == 1) {
    Serial.end();
    Serial.begin(9600);
  }
}

void redUp() {
  redVal = threshold(redVal + brightnessStep);
}

void greenUp() {
  greenVal = threshold(greenVal + brightnessStep);
}

void blueUp() {
  blueVal = threshold(blueVal + brightnessStep);
}

void redDown() {
  redVal = threshold(blueVal - brightnessStep);
}

void greenDown() {
  greenVal = threshold(greenVal - brightnessStep);
}

void blueDown() {
  blueVal = threshold(greenVal - brightnessStep);
}

int threshold(int val) {
  if(val < MIN) {
    return MIN;
  } else if (val > MAX) {
    return MAX;
  }
  return val;
}

Credits

Bryan Morrison

Bryan Morrison

1 project • 1 follower
Open Source developer for Remo.TV
Thanks to Jillian Ogle.

Comments