Electro BOY
Published © GPL3+

Possible! Smart Home without IoT

With DF2301 DF robot offline voice recognition module now controlling the GPIOs of a microcontroller over voice commands is possible.

IntermediateFull instructions provided1 hour119
Possible! Smart Home without IoT

Things used in this project

Software apps and online services

JLCPCB
Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Gerber files

Schematics

Circuit diagram

TEST

Code

TEST CODE

Arduino
#include "DFRobot_DF2301Q.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define light 2 // relay is connected to the digital pin D4


//I2C communication
DFRobot_DF2301Q_I2C asr; // activates the I2C mode of the voice recognition module

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


void setup() {
  Serial.begin(115200);  
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  
  pinMode(light, OUTPUT);    //Init light pin to output mode
  digitalWrite(light, LOW);  //Set light pin to low 
  
  // Init the sensor
  while (!(asr.begin())) {
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");
 
  /**
   * @brief Set voice volume
   * @param voc - Volume value(1~7)
   */
  asr.setVolume(7);
 
  /**
     @brief Set mute mode
     @param mode - Mute mode; set value 1: mute, 0: unmute
  */
  asr.setMuteMode(0);
 
  /**
     @brief Set wake-up duration
     @param wakeTime - Wake-up duration (0-255)
  */
  asr.setWakeTime(20);
 
  /**
     @brief Get wake-up duration
     @return The currently-set wake-up period
  */
  uint8_t wakeTime = 0;
  wakeTime = asr.getWakeTime();
  Serial.print("wakeTime = ");
  Serial.println(wakeTime);
 
   asr.playByCMDID(1);   // Wake-up command
 
  /**
     @brief Play the corresponding reply audio according to the ID
     @param CMDID - command word ID
  */
  //asr.playByCMDID(23);  // Command word ID
}
 
void loop() {
  /**
     @brief Get the ID corresponding to the command word 
     @return Return the obtained command word ID, returning 0 means no valid ID is obtained
  */
  uint8_t CMDID = asr.getCMDID();
  Serial.println(CMDID);
  switch (CMDID) {
    case 103:   //If the command is Turn on the light
      digitalWrite(light, HIGH);  //Turn on the light
      break;
 
    case 104:  //If the command is Turn off the light
      digitalWrite(light, LOW);  //Turn off the light
      break;

      case 52: // Display number zero
      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.print("NUMBER");
      display.setCursor(50,40);
      display.print("0");     
      display.display();
      break;
      
      case 53: // Display number zero
      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.print("NUMBER");
      display.setCursor(50,40);
      display.print("1");     
      display.display();
      break;
      
      case 54: // Display number zero
      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.print("NUMBER");
      display.setCursor(50,40);
      display.print("2");     
      display.display();
      break;
           
    default:
      if (CMDID != 0) {
        Serial.print("CMDID = ");  //Printing command ID
        Serial.println(CMDID);
      }
  }
  delay(300);
}

Solid state relay code

Arduino
#include "DFRobot_DF2301Q.h"
#define relay1 2 // relay is connected to the digital pin D2
#define relay2 3 // relay is connected to the digital pin D3
#define relay3 4 // relay is connected to the digital pin D4
#define relay4 5 // relay is connected to the digital pin D5

//I2C communication
DFRobot_DF2301Q_I2C asr; // activates the I2C mode of the voice recognition module


void setup() {
  Serial.begin(115200);  
  
  pinMode(relay1, OUTPUT);    //Init relay pin to output mode
  pinMode(relay2, OUTPUT); 
  pinMode(relay3, OUTPUT); 
  pinMode(relay4, OUTPUT); 

  digitalWrite(relay1, LOW);  //Set light pin to low 
  digitalWrite(relay2, LOW);
  digitalWrite(relay3, LOW);
  digitalWrite(relay4, LOW);
  
  // Init the sensor
  while (!(asr.begin())) {
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");
 
  /**
   * @brief Set voice volume
   * @param voc - Volume value(1~7)
   */
  asr.setVolume(7);
 
  /**
     @brief Set mute mode
     @param mode - Mute mode; set value 1: mute, 0: unmute
  */
  asr.setMuteMode(0);
 
  /**
     @brief Set wake-up duration
     @param wakeTime - Wake-up duration (0-255)
  */
  asr.setWakeTime(20);
 
  /**
     @brief Get wake-up duration
     @return The currently-set wake-up period
  */
  uint8_t wakeTime = 0;
  wakeTime = asr.getWakeTime();
  Serial.print("wakeTime = ");
  Serial.println(wakeTime);
 
   asr.playByCMDID(1);   // Wake-up command
 
  /**
     @brief Play the corresponding reply audio according to the ID
     @param CMDID - command word ID
  */
  //asr.playByCMDID(23);  // Command word ID
}
 
void loop() {
  /**
     @brief Get the ID corresponding to the command word 
     @return Return the obtained command word ID, returning 0 means no valid ID is obtained
  */
  uint8_t CMDID = asr.getCMDID();
  Serial.println(CMDID);
  switch (CMDID) {
    //relay1 for fan
    case 75:   // turn on the fan
      digitalWrite(relay1, HIGH);  
      break;
 
    case 76:  // turn off the fan
      digitalWrite(relay1, LOW);  
      break;
      
     //relay2 for light
    case 103:  // turn on the light 
      digitalWrite(relay2, HIGH);  
      break;
     
    case 104: // turn off the light
      digitalWrite(relay2, LOW);  
      break;
      
      //relay3 for ac 
      //(max limit 100-200watt mini cooling system can run)
    case 124:     // turn on ac
      digitalWrite(relay3, HIGH);  
      break;
 
    case 125:  // turn off ac 
      digitalWrite(relay3, LOW);  
      break;
      
      //relay4 for mini home theater system 
    case 90:   // turn on the speaker
      digitalWrite(relay4, HIGH);  
      break;
 
    case 91:  // turn off the speaker
      digitalWrite(relay4, LOW);  
      break;
 
           
    default:
      if (CMDID != 0) {
        Serial.print("CMDID = ");  //Printing command ID
        Serial.println(CMDID);
      }
  }
  delay(300);
}

Credits

Electro BOY

Electro BOY

57 projects • 54 followers
Electronics is my passion. I am not professional, Always learning something new. I am good at soldering, designing pcb, Arduino programing.

Comments