RGB LED strip controlled by Voice

In this instructables, I will show you how to implement a voice controlled RGB LED strip. After we have built the project, we will be able to control the color of the RGB LED strip and its intensity by voice commands. It sound exciting, is not it? Let's see how it works!

We need to connect the RGB LED strip to Arduino Nano using a breadboard. To propel a strip, an external power supply is required connected to the strip. After we have attached the Arduino to Raspberry Pi via USB, we need to upload a control code to it. It allows to control the Arduino microcontroller for Ozeki 10 what is a messaging system that routes messages between entities installed on Raspberry Pi. We also need a microphone with a sound card attached to Raspberry. Finally, we need to compile and run a few lines of code in Robot Controller (that is a built-in app in Ozeki 10) and we will be able to get a voice controlled RGB LED strip. Let's look at these steps in more detail!

block diagram
Figure 1 - Block diagram



For this project, we need the following components exactly:

  • Raspberry Pi 2 or 3,
  • USB sound card with microphone,
  • Installing Ozeki 10 on Raspberry Pi,
  • Arduino Nano,
  • MOSFET NPN transistors,
  • LED strip,
  • Breadboard,
  • Jumper wires,
  • and a Power supply.

Let’s get started!


voice controlled rgb led strip
Figure 2 - Voice controlled RGB LED strip

Step 1: RGB LED strip control switch on breadboard

LED strips are very simple, so easy to use them with any microcontroller such as Arduino Nano. I suggest using PWM dimming techniques to control the strip. Each LED pin may end up requiring an Amp or more to sink to ground. Because of this, we need to use power transistors. Do not try to connect the pins directly to your microcontroller, they will burn out and/or not work!

control switch on breadboard
Figure 3 - Control switch on breadboard

However I use IRF540N MOSFET, you can use any power NPN or N-Channel MOSFET, but make sure the used transistor is rated to be able to pass as much current as you need. For example, since we draw about 0.2Amps per channel per meter, if you have a 5 meter strip you will need to pass up to 1 Ampere per transistor.

The diagram below shows how to connect with N-Channel MOSFETs where the Gate is pin 1, the Drain is pin 2 and the Source is pin 3.

To write this step I used the content of https://learn.adafruit.com/rgb-led-strips/usage website.

breadboard
Figure 4 - Breadboard

Step 2: Format Arduino Nano

Why should we format? Arduino microcontrollers have a built in memory called EEPROM whose values are kept when the board is turned off. When you get a new Arduino, this storage is often filled with garbage. So we need to clear this storage before uploading a control code to it.

For formatting, we need its own software called Arduino IDE that you can download at https://www.arduino.cc/en/Main/Software. After you have installed it, connect Arduino to your PC via USB. Before uploading, make sure you have properly set up the application: under Tools menu, you have selected Arduino Nano as a Board and have set the Port that the device connects to (it is COM6 for me).

selecting arduino nano as a board
Figure 5 - Selecting Arduino Nano as a Board in Arduino IDE

In this step, the last thing is to upload the formater code, that you can find below, to your microcontroller. Copy then paste it into Arduino IDE then click on Upload button.

#include <EEPROM.h>

int a;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  
  for (uint16_t i = 0; i < EEPROM.length(); ++i) {
    EEPROM.update(i, 0);
  }
  
  for (uint16_t i = 0; i < EEPROM.length(); ++i) {
    a+=EEPROM.read(i);
  }

  if (a == 0){
    Serial.println("EEPROM is null! The process was successfull!");
  } else if (a > 0) {
    Serial.println("EEPROM is not null, please upload the code again!");
  }
}

void loop() {
  if (a == 0){
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);                       // wait for a second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);
  }
}

Step 3: Install Ozeki 10

Before installing, let me say a few words about what this software is. Ozeki 10 is a messaging system that routes messages between real world entities. We can build up a communication between shared hardware such as Arduino Nano and software resources. It has a built-in software called Robot Controller that we will use for sending messages to the hardware. Thanks to this, we can implement easily our voice controlled RGB LED strip with a few lines of code after we have finished the configuration.
So, the guide to download and setup Ozeki 10 software on Raspbian OS is available at http://www.ozeki.hu/index.php?owpn=3095. After you have downloaded and installed it, connect with your PC to Raspberry via WiFi. I consider it important to mention that the Ozeki 10’s surface is only accessible through a web browser, because it runs as a service, so you need one in witch you can login into it and configure/manage the system.

By the way, you can build this system without using Raspberry Pi. In this case, you only need to install the Windows or Ubuntu Linux installer to your PC that you can download via http://www.ozeki.hu/index.php?owpn=3091.


Step 4: Upload control code to Arduino Nano

Ozeki 10, that we are talking about in the next step, will control this hardware using text messages. To enable for this hardware to understand these messages, it is necessary to upload the control code to it.

uploading control code
Figure 6 - Uploading control code

Like in the previous step, copy the following code into Arduino IDE then upload it to the hardware.

#include <OzIDManager.h>
#include <OzRGBLedController.h>

// global pointers
OzIDManager* manager;
OzRGBLedController* rgbController;

// please select PWM pins
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
const int pwm = 9;

void setup()
{
  // wait for serial port
  Serial.begin(115200);

  // instantiate objects
  manager = new OzIDManager;
  manager->_sendACK = true;
  manager->_checksum = true;

  OzCommunication::setIDManager(manager);

  rgbController = new OzRGBLedController(redPin, greenPin, bluePin);
  rgbController->setPWM(pwm);

  int x=1;
  manager->sendLinkSetup();
  manager->PrintWelcomeLine(rgbController, x++, "MyRGBLed");
}

void loop()
{
   OzCommunication::communicate();
}

Step 5: Login Into Ozeki 10

Connect with your PC to Raspberry via WiFi then open a web browser and navigate to the Raspberry's 9505 port. You will see the Ozeki 10 Login page. Enter your password that you specified during the installation then click on OK.

If you installed it to Windows or Ubuntu Linux and do not want to use Raspberry Pi, open localhost:9505 in your internet browser.

ozeki 10 login page
Figure 7 - Ozeki 10 Login page

Step 6: Open Robot Controller

Robot Controller is a built-in application in Ozeki 10 in witch we can control and manage all the entities connected to the system. We can send messages to the entities and of course, we can receive messages from them using Subscribe method (that we will talk about in Step 9).

The software detect all the entities connected to the system included Arduino Nano as an RGB LED connection.

ozeki 10 home page
Figure 8 - Ozeki 10 Home page

Step 7: Configure Speech to Text

Time to configure the Speech to Text connection. After we have created, we will be able to set words or a word set to detect using microphone. To do this, we need to open Connections and create a new one for the microphone as a Speech to Text type of connection.

First, navigate to Tools on manubar then select Connections item. In this Connection view, you can see all the connected entities. We will create a new one for the microphone. To start this, click on Create new Connection button. On the right side panel, you can choose what type of connection you would like to add, now we need AV (Audio or Video) then select Speech to Text. Then name it as My_Speech_to_Text_1, select your microphone as a recorder device and choose speech recognizer as English. Finally, set the accuracy level of the speech recognition to 80 percentage.

If you does not have English option, you need to install the English language pack to your system.

configure speech to text
Figure 9 - Configure Speech to Text

Step 8: Set Detectable Word Set

Then we need to create a detectable word set to load the color names to be detected. To do this, in the Connection view, select the My_Speech_to_Text_1 connection's Details button then navigate to Detect words tab and click on Create new Detectable word button. On the right-side panel, select the Word set then the Colors option. Finally, name it as Colors and click OK.

Click on Home button to return back to Robot Controller.

creating detectable word set
Figure 10 - Creating detectable word set

Step 9: Run the code in Robot Controller

Running the code below, it will turn the color of the RGB LED strip to green then red and vice versa 10 times. After that, it will subsribe to My_speech_to_Text_1 connection, that we had created before, using the Subscribe method. So, when we say a color name into the microphone, the Text to Speech connection will recognize it then convert it into a simple text message what we will catch throught Receive method using its Message parameter. In this method, we can filter the name of the connection using FromConnection function. If it comes from the configured mirophone, we will transmit this message to our Arduino microcontroller using the Send method. Finally, our RGB LED strip will light up and pick up the spoken color.

ozeki robot controller
Figure 11 - Ozeki Robot Controller

Copy this code then compile and run it. Now, you can use your microphone to control RGB LED strip’s color saying color names.

using System;
using System.Threading;

namespace Ozeki
{ 
    public class Program 
    { 
        public void Start()
        {
            for(int x=0; x<10; x++)
            {
                Send("MyRGBLed@localhost", "green");
                Thread.Sleep(500);
                Send("MyRGBLed@localhost", "red");
                Thread.Sleep(500);
            }
            
            Subscribe("My_speech_to_Text_1@localhost");
        }
      
        public void Receive(Message msg)
        {
            if(msg.FromConnection=="My_speech_to_Text_1@localhost")
            {
                Send("MyRGBLed@localhost", msg.Text);
            }  
        }
    }
};

Testing the solution

First, we will test the Speech to Text connection that you can see on Test 1.
After you have compiled and started to run the code, you will see a --- Subscribe My_speech_to_Text_1@localhost message on the console. Then you need to say a color name into your microphone, for example: red. In this case, a message should appear on the console: --> (My_speech_to_Text_1@localhost) Red. This means that the Robot Controller received a message containing a Red message from Speech to Text connection.

Finally, we will test the MyRGBLed connection that you can see on Test 2.
After the Robot Controller successfully received a message from Speech to Text connection, it should transmit a received message to MyRGBLed connection: <-- (MyRGBLed@localhost) Red. Then the RGB LED strip should light up and should change its color to red.

testing the solution
Figure 12 - Testing the solution

Further reading

More information