Build a Voice Controlled Car with Arduino: A DIY Coding Guide

Are you fascinated by smart car technology and eager to build your own voice-activated vehicle? This comprehensive guide will walk you through the exciting process of creating a voice control car using Arduino, leveraging the power of voice commands for a truly interactive project. Perfect for DIY enthusiasts and coding beginners alike, this project combines electronics, coding, and voice recognition to bring a futuristic element to your home projects.

Components You’ll Need for Your Voice Controlled Car

Before diving into the coding and construction, gather these essential components to bring your voice-controlled car to life:

  • Arduino Board with Wi-Fi: The brain of your operation. An Arduino Nano 33 IoT is excellent for its compact size and integrated Wi-Fi, crucial for cloud connectivity.
  • Motor Driver: Like the L293D or L298N, this component is essential for controlling the car’s motors, allowing precise movement.
  • Robot Chassis: The base of your car. Choose a chassis that suits your project size and motor requirements.
  • Power Source: A 9V battery is a standard choice for powering your Arduino and motors. Consider battery life for extended operation.
  • Smartphone with Alexa App: To integrate voice control, you’ll need a smartphone capable of running the Alexa app.

For this tutorial, we recommend the Arduino Nano 33 IoT due to its seamless integration with cloud services and compact form factor, ideal for mobile robots.

Step-by-Step Guide to Voice Control Car Coding with Arduino

Let’s break down the process into manageable steps, making it easy to follow along and build your voice-controlled car.

Step 1: Setting Up the Circuit

The first crucial step is to assemble the circuit. You can start with a breadboard for prototyping and testing. Once you’re confident with the circuit, consider designing a Printed Circuit Board (PCB) for a more robust and professional finish. PCBs reduce wiring clutter and enhance the durability of your project.

Altium schematic diagram illustrating the voice control car circuit.

For designing the schematic and PCB layout, tools like Altium Designer are incredibly useful. Altium offers a comprehensive environment for circuit design, from simple projects to complex industrial applications. Consider exploring the trial version to experience its capabilities.

A custom PCB layout simplifies mounting the Arduino Nano 33 IoT, motor driver ICs (like L293D), and other components, eliminating messy wiring. Powering the circuit effectively is key. A 12V LiPo battery connected to a 7805 regulator can provide a stable 5V supply for your Arduino and peripherals. Indicator LEDs at key points can aid in troubleshooting. Remember to check the voltage requirements of your specific Arduino board; some, like the Nano 33 IoT, can handle 12V on their Vin pin, but others might require voltage regulation to prevent damage.

Custom PCB designed for the Arduino voice controlled car project, showcasing component layout.

Step 2: Arduino IoT Cloud Setup

For seamless Voice Control Car Coding, the Arduino IoT Cloud is invaluable. Begin by logging into the Arduino IoT Cloud console. Ensure your Arduino Nano 33 IoT is added to your device list. If you’re new to this, Arduino provides tutorials to guide you through device setup and cloud integration.

Step 3: Creating a New “Thing” for Your Voice Controlled Car

Within the Arduino IoT Cloud, create a new project, referred to as a “Thing”. Navigate to the “Things” section and click “create thing”. Name your project something descriptive like “Voice Controlled Robot” or “Alexa Car”. This project page will be your central hub for managing variables, network settings, and the code sketch.

Screenshot of the Arduino IoT Cloud interface for creating a new “Thing” for voice control projects.

Step 4: Defining Variables for Car Control

Next, define the variables that will control your car’s movements. For directional control (forward, backward, left, right), boolean variables are ideal. Add four boolean variables in your Arduino IoT Cloud project: forward, backward, left, and right. These variables will be toggled via voice commands to maneuver your car.

Interface for defining control variables within the Arduino IoT Cloud platform for voice commands.

Step 5: Building a Dashboard for Manual Control (Optional)

While voice control is the main goal, creating a dashboard in Arduino IoT Cloud with buttons for each direction is helpful for testing and manual override. Add four buttons to your dashboard, linking each button to the corresponding boolean variable (forward, backward, left, right). This allows you to control the car directly from the cloud dashboard, useful for debugging and ensuring your basic motor controls are functioning correctly.

Step 6: Linking Your Arduino Board to the Project

Associate your newly created “Thing” with your physical Arduino Nano 33 IoT board. This step connects your cloud project to your hardware, enabling data exchange and command execution.

Step in Arduino IoT Cloud to link the virtual project to the physical Arduino Nano 33 IoT board.

Step 7: Setting Up Network Configuration

Configure the Wi-Fi network settings for your project. In the network section of your “Thing” settings, input your Wi-Fi network name (SSID) and password. This ensures your Arduino can connect to the internet and communicate with the Arduino IoT Cloud and Alexa.

Arduino IoT Cloud interface to configure Wi-Fi credentials for connecting the voice control car project.

Step 8: Coding Your Voice Controlled Car in Arduino IoT Cloud

The Arduino IoT Cloud simplifies coding by automatically generating a skeleton code based on your project setup. This code includes variable declarations and essential functions for cloud communication. You’ll need to add the motor control logic to this auto-generated code.

Here’s the code structure to implement voice control for your car:

#include "thingProperties.h"

void setup() {
  Serial.begin(9600);
  delay(1500);
  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
}

void onForwardChange() {
  if (forward == true) {
    mforward();
    delay(1000);
    mstopp();
    forward = false;
  }
}

void onLeftChange() {
  if (left == true) {
    mleft();
    delay(500);
    mstopp();
    left = false;
  }
}

void onRightChange() {
  if (right == true) {
    mright();
    delay(500);
    mstopp();
    right = false;
  }
}

void onBackwardChange() {
  if (backward == true) {
    mbackward();
    delay(1000);
    mstopp();
    backward = false;
  }
}

void mforward() {
  analogWrite(2, 155);
  analogWrite(3, 150);
  digitalWrite(5, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
}

void mbackward() {
  analogWrite(2, 155);
  analogWrite(3, 150);
  digitalWrite(5, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(6, HIGH);
  digitalWrite(7, LOW);
}

void mleft() {
  analogWrite(2, 100);
  analogWrite(3, 180);
  digitalWrite(5, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
}

void mright() {
  analogWrite(2, 150);
  analogWrite(3, 70);
  digitalWrite(5, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
}

void mstopp() {
  analogWrite(2, 20);
  analogWrite(3, 254);
  digitalWrite(5, LOW);
  digitalWrite(4, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
}

Code Explanation:

  • Libraries and Setup: The code begins by including necessary libraries and initializing serial communication and Arduino Cloud connectivity in the setup() function.
  • Variable Change Functions: Functions like onForwardChange(), onLeftChange(), etc., are triggered when their corresponding variables in the Arduino IoT Cloud are changed (via voice command through Alexa).
  • Motor Control Functions: Functions like mforward(), mbackward(), mleft(), mright(), and mstopp() control the motors using analogWrite() and digitalWrite() commands to drive the motor driver IC. These functions are called within the variable change functions to move the car in the desired direction. Ensure you are familiar with how motor driver ICs function, especially if you’re new to motor control with Arduino.

This code structure ensures that when Alexa sends a command to change a variable (e.g., setting forward to true), the onForwardChange() function is executed, which in turn calls mforward() to move the car forward.

Step 9: Integrating Alexa Voice Commands

To enable voice control, you need to integrate Alexa with your Arduino project. Install the Arduino Skill for Alexa on your smartphone’s Alexa app and link it with your Arduino Cloud account.

Screenshot of the Alexa app interface showing the Arduino Skill for voice control integration.

Once the skill is enabled, use the “Discover devices” option in the Alexa app. Alexa will scan for and detect the variables you created in your Arduino IoT Cloud project. These variables will appear as controllable devices in your Alexa app. Complete the device setup within the Alexa app.

Alexa app recognizing Arduino variables as controllable devices for voice commands.

Start Driving with Voice Commands!

With all steps completed, your voice control car is ready to roll! Use voice commands like “Alexa, turn on forward” to move your car forward, “Alexa, turn on left” to turn left, and so on. Experiment with different commands to get comfortable with voice control.

The completed voice controlled car project, ready for operation via voice commands.

This project demonstrates the exciting intersection of voice control car coding and DIY electronics. By following this guide, you’ve not only built a fun, interactive toy, but also gained valuable experience in IoT, Arduino programming, and voice integration. Explore further enhancements, like adding sensors for obstacle avoidance or integrating more complex voice commands for an even smarter vehicle.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *