Story
Have you ever imagined controlling the light bulb in your house with your voice commands? This project does that. You can "Turn On" or "Turn Off" the light bulb with your voice commands!
This project is built using Edge Impulse. The public repository can be found here. You may clone the project and collect your own voice data. I have collected 10 seconds of data for each class.
I used three classes for labelling data:
- light_on - to Turn On Light
- light_off - to Turn Off Light
- nocmd - when no command should be sent
After the data is collected you need to split it.
![](https://hackster.imgix.net/uploads/attachments/1487525/data_split_IAG1ml1oYE.png?auto=compress%2Cformat&w=740&h=555&fit=max)
You will then get 1s of sample data for each voice.
![](https://hackster.imgix.net/uploads/attachments/1487523/data-collection_AZqALnlgdm.png?auto=compress%2Cformat&w=740&h=555&fit=max)
You can find step-by-step tutorial on how collecte and split data here. Here's how the data for each class/label looks like
![](https://hackster.imgix.net/uploads/attachments/1487740/data-label_NMaKqzMeZs.png?auto=compress%2Cformat&w=740&h=555&fit=max)
Remember that the class nocmd is important, as the NN will detect this class most of the time when no command is sent. This class may have audio data with no and little background noice.
Now create impulse as follows
![](https://hackster.imgix.net/uploads/attachments/1487527/create-impulse_u0VNi4C6qU.png?auto=compress%2Cformat&w=740&h=555&fit=max)
and generate features
![](https://hackster.imgix.net/uploads/attachments/1487529/features_8g8l3B3o77.png?auto=compress%2Cformat&w=740&h=555&fit=max)
then train your model. I achieved 100% training accuracy
![](https://hackster.imgix.net/uploads/attachments/1487530/training-accuracy_ImiWEqiGnv.png?auto=compress%2Cformat&w=740&h=555&fit=max)
and 92% testing accuracy
![](https://hackster.imgix.net/uploads/attachments/1487532/classification-result_ydAjoASpXm.png?auto=compress%2Cformat&w=740&h=555&fit=max)
Finally export model as Arduino library and build device using attached Arduino code (firmware) and by following the circuit diagram (attached).
The following two variables needs to be declared in the beginning:
int RelayPin = 6;
int on_off_flag = 2; //no command (nocmd)
And the following code in loop() function controls the light bulb.
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
ei_printf(" %s: %.5f\n", result.classification[ix].label, result.classification[ix].value);
if((strcmp(result.classification[ix].label, "light_on")==0) && result.classification[ix].value > 0.6 ){
on_off_flag = 1; //light_on
} else if((strcmp(result.classification[ix].label, "light_off")==0) && result.classification[ix].value > 0.6 ){
on_off_flag = 0; //light_off
}else{
on_off_flag = 2; //nocmd
}
}
if(on_off_flag==1){
digitalWrite(RelayPin, HIGH);
Serial.println("***** ON *****");
}else if (on_off_flag==0){
digitalWrite(RelayPin, LOW);
Serial.println("***** OFF *****");
}else{
Serial.println("***** No Command Detected *****");
}
Following are the results when I run my project
![](https://hackster.imgix.net/uploads/attachments/1487538/img20220828131930_kdxToFGQMd.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)
Figure 1 "Light Off"
![](https://hackster.imgix.net/uploads/attachments/1487537/img20220828132005_e5S9nJRl4k.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)
Figure 2 "Light On"
Here's the short video of working project.
You can follow this project and control any AC appliences at your home with your voice commands.
Happy making!
References
Circuit Diagram
![](/storage/ProjectSection/Projects/7424/voice-controlled-light-bulb-using-tinyml/detailed-description/circuit-diagram_nSl3Hdx76V.png)