Voice Controller for Lights, Fan, and Robot – The Ultimate Smart Control Solution 2025

Introduction: Unleashing the Power of Voice Controller for Lights, Fan, and Robot

Imagine a world where your voice commands control everything—say “lights on,” and they illuminate; command “fan spin,” and it hums to life; instruct “move forward,” and your robot glides across the room. With a voice controller for lights, fan, and robot, automation becomes effortless. In this guide, I’ll show you how to build the ultimate smart control system using Arduino, covering everything from component testing and coding to seamless control via your smartphone. Let’s bring your ideas to life!

Voice Controller for Lights, Fan, and Robot with the BlueBot Controller app. Use voice commands for effortless automation

Step 1: Test Your Components for the Voice Controller for Lights, Fan, and Robot

Before assembling your voice controller for lights, fan, and robot, test each component to ensure they work. Here are simple test codes for the ultrasonic sensor, L293D motor driver with AFMotor, servo, HC-05 Bluetooth, and an LED (simulating relay control).

Test Code 1: Ultrasonic Sensor (HC-SR04)

#define Echo A0
#define Trig A1

void setup() {
  Serial.begin(9600);
  pinMode(Trig, OUTPUT);
  pinMode(Echo, INPUT);
  Serial.println("Ultrasonic Test...");
}

long getDistance() {
  digitalWrite(Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig, LOW);
  return pulseIn(Echo, HIGH) / 58; // Distance in cm
}

void loop() {
  long distance = getDistance();
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(500);
}
  • How It Works: Connect Trig to A1 and Echo to A0. Open the Serial Monitor (9600 baud) to see distance readings.

Test Code 2: L293D Motor Driver with AFMotor.h

#include <AFMotor.h>

AF_DCMotor motor(1); // Motor on M1 port

void setup() {
  Serial.begin(9600);
  motor.setSpeed(200); // Set speed (0-255)
  Serial.println("Motor Test...");
}

void loop() {
  motor.run(FORWARD);
  Serial.println("Motor Forward");
  delay(2000);
  motor.run(RELEASE);
  Serial.println("Motor Stop");
  delay(2000);
  motor.run(BACKWARD);
  Serial.println("Motor Backward");
  delay(2000);
}
  • How to Add AFMotor.h: Download it from GitHub. In Arduino IDE, go to Sketch > Include Library > Add .ZIP Library, then select the downloaded file.
  • How It Works: Connect a motor to M1 on the L293D shield. Watch it spin forward, stop, and reverse.

Test Code 3: Servo Motor (SG90)

#include <Servo.h>

Servo servo;

void setup() {
  Serial.begin(9600);
  servo.attach(9); // Servo on pin 9
  Serial.println("Servo Test...");
}

void loop() {
  servo.write(0);   // Move to 0 degrees
  Serial.println("Servo at 0");
  delay(1000);
  servo.write(90);  // Move to 90 degrees
  Serial.println("Servo at 90");
  delay(1000);
  servo.write(180); // Move to 180 degrees
  Serial.println("Servo at 180");
  delay(1000);
}
  • How It Works: Connect the servo to pin 9. It rotates to 0, 90, and 180 degrees.

Test Code 4: HC-05 Bluetooth Module

void setup() {
  Serial.begin(9600); // HC-05 default baud rate
  Serial.println("HC-05 Test...");
}

void loop() {
  if (Serial.available()) {
    char data = Serial.read();
    Serial.print("Received: ");
    Serial.println(data);
  }
}
  • How It Works: Connect HC-05 TX to Arduino RX (pin 0) and RX to TX (pin 1). Use a Bluetooth terminal app to send characters and see them echoed.

Test Code 5: LED On/Off (Simulating Relay)

#define LED_PIN 13 // Built-in LED

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  Serial.println("LED Test...");
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  Serial.println("LED ON");
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  Serial.println("LED OFF");
  delay(1000);
}
  • How It Works: The built-in LED on pin 13 blinks, mimicking relay control.

These tests confirm your components are ready for the voice controller for lights, fan, and robot. Next, let’s tackle relay control!

Step 2: Sample Code for Turning On/Off 5 Relays

For your voice controller for lights, fan, and robot, a 5-channel relay module controls lights, fan, and more. Here’s a sample code:

#define RELAY1 2 // Light 1
#define RELAY2 3 // Light 2
#define RELAY3 4 // Fan
#define RELAY4 5 // Extra appliance
#define RELAY5 6 // Extra appliance

void setup() {
  Serial.begin(9600);
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  pinMode(RELAY5, OUTPUT);
  Serial.println("Relay Test...");
}

void loop() {
  digitalWrite(RELAY1, HIGH); // Light 1 ON
  Serial.println("Light 1 ON");
  delay(1000);
  digitalWrite(RELAY1, LOW);  // Light 1 OFF
  delay(1000);

  digitalWrite(RELAY3, HIGH); // Fan ON
  Serial.println("Fan ON");
  delay(1000);
  digitalWrite(RELAY3, LOW);  // Fan OFF
  delay(1000);
}
  • How It Works: Connect relays to pins 2-6. This code toggles two relays; expand it for all five as needed.

Step 3: Voice Controlled Robot Circuit and Code Explanation

Now, let’s build the robot part of your voice controller for lights, fan, and robot. Here’s the circuit and code.

Circuit Diagram

  • Arduino Uno: Base board.
  • L293D Shield: Plugs onto Arduino. Connect 4 DC motors to M1-M4.
  • HC-SR04: Trig to A1, Echo to A0. Mount on servo.
  • SG90 Servo: Signal to pin 10.
  • HC-05: TX to RX (pin 0), RX to TX (pin 1).
  • Relays: Pins 2-6 for 5 relays (e.g., 2 for light, 3 for fan).

Voice Controlled Robot Code

#include <AFMotor.h>  // Include Adafruit Motor Shield library
#include <Servo.h>    // Servo library

#define Echo A0
#define Trig A1
#define SERVO_PIN 10
#define MOTOR_SPEED 200  // Define motor speed as a constant
#define TURN_DURATION 3000  // Turn duration for regular turns

// Motor Definitions
AF_DCMotor M1(1); 
AF_DCMotor M2(2); 
AF_DCMotor M3(3); 
AF_DCMotor M4(4); 

Servo servo;
bool automaticModeEnabled = false;

void setup() {
    Serial.begin(9600);  // Serial for Bluetooth communication
    pinMode(Echo, INPUT);
    pinMode(Trig, OUTPUT);
    servo.attach(SERVO_PIN);
    servo.write(90);  // Start with servo facing front
    
    // Initialize motors
    M1.setSpeed(MOTOR_SPEED);
    M2.setSpeed(MOTOR_SPEED);
    M3.setSpeed(MOTOR_SPEED);
    M4.setSpeed(MOTOR_SPEED);
    
    Serial.println("Bluetooth communication started...");
    Serial.println("Waiting for messages...");
}

// Ultrasonic distance measurement
long getDistance() {
    digitalWrite(Trig, LOW);
    delayMicroseconds(2);
    digitalWrite(Trig, HIGH);
    delayMicroseconds(10);
    digitalWrite(Trig, LOW);
    long distance = pulseIn(Echo, HIGH) / 58; // Convert time to cm
    return distance;
}

// Forward Motion with Obstacle Detection
void moveForward() {
    // Before moving, check if there's an obstacle
    long currentDistance = getDistance();
    
    if (currentDistance < 15) {  // Check if obstacle is too close
        Serial.println("Obstacle detected ahead! Cannot move forward.");
        return;  // Don't move forward
    }
    
    Serial.println("Moving Forward");
    M1.run(FORWARD);
    M2.run(FORWARD);
    M3.run(FORWARD);
    M4.run(FORWARD);
    
    // Continuous detection happens in loop() not here
}

// Backward Motion
void moveBackward() {
    Serial.println("Moving Backward");
    M1.run(BACKWARD);
    M2.run(BACKWARD);
    M3.run(BACKWARD);
    M4.run(BACKWARD);
}

// Turn Left
void turnLeft() {
    Serial.println("Turning Left");
    M1.run(FORWARD);
    M3.run(FORWARD);
    M2.run(BACKWARD);
    M4.run(BACKWARD);
}

// Turn Right
void turnRight() {
    Serial.println("Turning Right");
    M1.run(BACKWARD);
    M3.run(BACKWARD);
    M2.run(FORWARD);
    M4.run(FORWARD);
}

// Stop Movement
void stopMotors() {
    Serial.println("Stopping");
    M1.run(RELEASE);
    M2.run(RELEASE);
    M3.run(RELEASE);
    M4.run(RELEASE);
}

// Look in a specific direction and get distance
long lookAndMeasure(int angle) {
    servo.write(angle);
    delay(300);  // Reduced delay for smoother operation
    return getDistance();
}

// Performs a detailed scan in 20-degree increments and returns the best angle to turn
int preciseScan() {
    long distances[10]; // Array to store distances at different angles
    int angles[10];     // Array to store corresponding angles
    int readings = 0;   // Counter for valid readings
    
    Serial.println("Performing precise scan...");
    
    // Scan from 0 to 180 degrees in 20-degree increments
    for (int angle = 0; angle <= 180; angle += 20) {
        long distance = lookAndMeasure(angle);
        delay(200); // Allow time for stable reading
        
        Serial.print("Angle: "); Serial.print(angle);
        Serial.print(", Distance: "); Serial.print(distance);
        Serial.println(" cm");
        
        // Store this reading
        distances[readings] = distance;
        angles[readings] = angle;
        readings++;
    }
    
    // Return servo to center
    servo.write(90);
    delay(300);
    
    // Find the best direction
    long maxDistance = 0;
    int bestAngle = 90; // Default to forward if no good option
    
    // First, check right side (90-180 degrees) as it has priority
    for (int i = 0; i < readings; i++) {
        if (angles[i] > 90 && distances[i] > maxDistance && distances[i] > 15) {
            maxDistance = distances[i];
            bestAngle = angles[i];
        }
    }
    
    // If no good path found on right, check left side (0-90 degrees)
    if (maxDistance == 0) {
        for (int i = 0; i < readings; i++) {
            if (angles[i] < 90 && distances[i] > maxDistance && distances[i] > 15) {
                maxDistance = distances[i];
                bestAngle = angles[i];
            }
        }
    }
    
    // Report the best angle found
    Serial.print("Best angle: "); Serial.print(bestAngle);
    Serial.print(", with distance: "); Serial.print(maxDistance);
    Serial.println(" cm");
    
    return bestAngle;
}

// Automatic Obstacle Avoidance Mode with Precise Scanning
// Modified Automatic Obstacle Avoidance Mode
void automaticMode() {
    static bool isCurrentlyMoving = false;
    
    // First, check if there's an obstacle in front
    long frontDistance = getDistance();
    
    // If obstacle detected in front, perform precise scanning
    if (frontDistance <= 15) {
        // Stop immediately
        stopMotors();
        isCurrentlyMoving = false;
        Serial.println("Obstacle detected ahead! Stopping");
        delay(200);
        
        // Perform precise scanning
        int bestAngle = preciseScan();
        
        // If front is still blocked, back up and scan again
        frontDistance = lookAndMeasure(90);  // Look forward
        if (frontDistance <= 15) {
            Serial.println("Front still blocked. Moving backward");
            moveBackward();
            delay(800); // Move back for 800ms (1 step)
            stopMotors();
            delay(200);
            
            // Perform another precise scan after backing up
            bestAngle = preciseScan();
        }
        
        // Turn to the best direction with increased turn duration
        if (bestAngle < 90) {
            // Turn left
            Serial.print("Turning left based on best angle: ");
            Serial.println(bestAngle);
            turnLeft();
            
            // Calculate turn duration based on how far from center
            int turnTime = map(bestAngle, 0, 90, TURN_DURATION * 1.5, TURN_DURATION * 0.75);
            
            Serial.print("Turn duration: ");
            Serial.print(turnTime);
            Serial.println(" ms");
            
            delay(turnTime);
            stopMotors();
            delay(200);
            
            // After turning, move forward but don't stop
            Serial.println("Turn complete, moving forward");
            moveForward();
            isCurrentlyMoving = true;
            
        } else if (bestAngle > 90) {
            // Turn right
            Serial.print("Turning right based on best angle: ");
            Serial.println(bestAngle);
            turnRight();
            
            // Calculate turn duration based on how far from center
            int turnTime = map(bestAngle, 90, 180, TURN_DURATION * 0.75, TURN_DURATION * 1.5);
            
            Serial.print("Turn duration: ");
            Serial.print(turnTime);
            Serial.println(" ms");
            
            delay(turnTime);
            stopMotors();
            delay(200);
            
            // After turning, move forward but don't stop
            Serial.println("Turn complete, moving forward");
            moveForward();
            isCurrentlyMoving = true;
            
        } else {
            // No good direction (shouldn't happen often)
            Serial.println("No clear path. Backing up more and making a full turn");
            moveBackward();
            delay(1200);
            stopMotors();
            delay(200);
            
            // Make a full turn to try to find new path
            turnRight();
            delay(TURN_DURATION * 1.5); // Full 180-degree turn
            stopMotors();
            delay(200);
            
            // After turning, move forward but don't stop
            Serial.println("Turn complete, moving forward");
            moveForward();
            isCurrentlyMoving = true;
        }
    } else {
        // No obstacle ahead, continue moving forward
        // Check if we're not already moving forward
        if (!isCurrentlyMoving) {
            Serial.println("Path clear. Moving forward");
            moveForward();
            isCurrentlyMoving = true;
        }
        // No need to stop since we want continuous movement
    }
    
    // A short delay is still good for system stability
    delay(100);
}

void loop() {
    // Continuous distance checking for manual forward movement
    static bool isMovingForward = false;
    static long lastDistance = 100;  // Initialize with a safe value
    
    // Check if motors are running in forward mode
    if (isMovingForward) {
        long currentDistance = getDistance();
        
        // If obstacle detected while moving forward, stop
        if (currentDistance < 15) {
            Serial.println("Obstacle detected while moving forward! Stopping");
            stopMotors();
            isMovingForward = false;
        }
    }
    
    // Check for automatic mode
    if (automaticModeEnabled) {
        automaticMode();
        
        // Check if there's a command to exit automatic mode
        if (Serial.available()) {
            String stopCommand = Serial.readString();
            stopCommand.trim();
            
            if (stopCommand.equals("stop")) {
                Serial.println("Exiting Automatic Mode");
                automaticModeEnabled = false;
                stopMotors();
            }
        }
    } 
    // Normal command processing
    else if (Serial.available()) {
        String receivedMessage = Serial.readString();
        receivedMessage.trim();  // Clean up spaces/newlines

        Serial.print("Received command: ");
        Serial.println(receivedMessage);

        // Movement Controls
        if (receivedMessage.equals("move forward")) {
            moveForward();
            isMovingForward = true;  // Mark that we're moving forward
        } else if (receivedMessage.equals("move back")) {
            moveBackward();
            isMovingForward = false;  // Not moving forward
        } else if (receivedMessage.equals("turn left")) {
            turnLeft();
            // For manual turning, run for a duration then stop
            delay(TURN_DURATION);
            stopMotors();
            isMovingForward = false;  // Not moving forward
        } else if (receivedMessage.equals("turn right")) {
            turnRight();
            // For manual turning, run for a duration then stop
            delay(TURN_DURATION);
            stopMotors();
            isMovingForward = false;  // Not moving forward
        } else if (receivedMessage.equals("stop")) {
            stopMotors();
            isMovingForward = false;  // Not moving forward
        } else if (receivedMessage.equals("automatic mode")) {
            Serial.println("Automatic Mode Enabled");
            automaticModeEnabled = true;
            isMovingForward = false;  // Reset forward tracking when entering auto mode
        } else {
            Serial.println("Replied: I don't understand.");
        }
    }
    
    delay(100); // Small delay to avoid buffer overflow
}

Code Explanation

  • Setup: Initializes pins, servo, and motors.
  • getDistance: Measures distance using the ultrasonic sensor.
  • moveForward: Moves the robot if no obstacle is within 15 cm.
  • turnRight: Turns the robot right for a set duration.
  • loop: Listens for Bluetooth commands like “light on” or “auto mode” to control the voice controller for lights, fan, and robot.

What is the BlueBot Controller App?

The Ultimate Bluetooth LED Controller App is a mobile application designed to control Bluetooth-enabled devices. The Blue Bot Controller is an all-in-one Bluetooth app designed for controlling devices like LEDs, robots, and sensors. It offers advanced features tailored for hobbyists, students, and developers alike.

With support for gesture, voice, IoT, and custom controls, the app enables seamless device management. Its user-friendly interface makes exploring wireless communication and automation effortless and engaging for all users.

Controllers:

  1. LED Control
  2. Robot Control
  3. RGB Control
  4. Text Control
  5. IoT Control
  6. Matrix Control
  7. Voice Control
  8. Gesture Control
  9. Sensor Control
    • MPU6050 Sensor : Gesture and motion detection.
    • Potentiometer Sensor: Analog value adjustments.
    • PIR Sensor: Motion detection triggering.
    • Ultrasonic Sensor: Distance and proximity measurements.
  10. Custom Control
  11. Timed Control
  12. Servo Control
  13. Joystick Control
  14. Inauguration Control

How to Download the BlueBot Controller App

To get started, download the BlueBot Controller App from the official source:

Make sure you have a Bluetooth-enabled smartphone to pair with your project.

Applications of a Voice Controller

The versatility of a voice controller for lights, fan, and robot makes it ideal for numerous applications:

  • Home Automation: Control lights, fans, and other appliances with voice commands.
  • Robotics Projects: Guide robots wirelessly using simple voice instructions.
  • Assistive Technology: Help individuals with limited mobility control their surroundings.
  • Educational Projects: Teach students the basics of wireless communication and voice control.

Benefits of a Voice Controller for Lights, Fan, and Robot

  1. Convenience: Control devices without touching switches or buttons.
  2. Hands-Free Operation: Perfect for multitasking and accessibility.
  3. Real-Time Monitoring: Get instant feedback on the system’s status.
  4. Energy Efficiency: Turn off appliances remotely to save power.
  5. Customizable: Modify the code to suit specific requirements or add new functionalities.

Tips for Optimizing Your Voice Controller

  1. Ensure Clear Voice Commands: Use distinct phrases like “fan on” or “robot forward” to minimize errors.
  2. Test Bluetooth Range: Ensure the Bluetooth module has a stable connection within the operating range.
  3. Secure Your System: Implement authentication to prevent unauthorized access to your devices.
  4. Optimize Power Supply: Use a reliable power source to ensure uninterrupted operation.

Conclusion

A voice controller for lights, fan, and robot is more than just a convenience; it’s a step toward smarter living. With Bluetooth technology and simple programming, you can build an efficient system to control your appliances and robots wirelessly. The added feature of real-time data display makes it even more practical and user-friendly.

Whether you’re a hobbyist or a professional, this project offers endless possibilities. Start building your voice controller today and experience the power of seamless, hands-free control.

Download BlueBot Controller App and start your journey today!

Home Page