Voice activated Baby swing

Hi, I am attempting to create a voice activated baby swing, but I'm having an error with the Speak Up click. First, the speak up Click doesnt process my commands right away. Takes me a few tries till it reads my command.
Second, once it does catch the command it doesn't process the code that i set up to read?
Is there any advice you can give me?
Attached is a photo of my wiring. Im using a Elegoo mega2560

#include <HardwareSerial.h>
#include <Arduino.h>
#include <Wire.h>
extern HardwareSerial Serial1;
extern HardwareSerial Serial2;
char incomingByte;
char incomingByte1;

int Speaker = 15;
int Swing = 16;
int RedLED = 12;
//Swing Motor (Big motor)
const int motorPin1  = 5;  // Pin 14 of L293
const int motorPin2  = 6;  // Pin 10 of L293
//Toy Motor (Small Motor)
const int motorPin3  = 10; // Pin  7 of L293
const int motorPin4  = 9;  // Pin  2 of L293

int EN1 = 3;                 // Pin 1 of L293D IC, D6 Pin of NodeMCU (controls the speed)

void setup() {

  //Set motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);

  pinMode(EN1, OUTPUT); //Where the motor is connected to

  Serial.println("Ready for commands");

void loop() {

  if (Serial2.available() > 1) {
    // read the incoming byte:
    incomingByte = Serial2.read();
    incomingByte1 = Serial2.read();
    Serial.print ("Received data = ");
    Serial.print(int(incomingByte) , DEC);
    Serial.println(int(incomingByte1) , DEC);


  if (incomingByte == 0) { // Turn the swing ON
    Serial.println ("Command: Power On");
    digitalWrite(Swing, HIGH);

  if (incomingByte == 1) { // Turn the swing off
    Serial.println ("Command: Power Off");
    digitalWrite(Swing, LOW);
  if (incomingByte == 2) { // Turn the music on
    Serial.println ("Command: Music ON");
    digitalWrite(Speaker, HIGH);

  if (incomingByte == 3) { // Turn the music off
    Serial.println ("Command: Music off");
    digitalWrite(Speaker, LOW);

  if (incomingByte == 4) { // Make swing faster
    Serial.println ("Command: Swing Fast");
    digitalWrite(RedLED, 255);

  if (incomingByte == 5) { // Make the swing slower
    Serial.println ("Command: Swing SLOW");
    digitalWrite(RedLED, 0);

  if (incomingByte == 6) { // Turn swinging motion on
    Serial.println ("Command: Swing On");
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
  if (incomingByte == 7) { // Turn swinging motion off
    Serial.println ("Command: Swing OFF");
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);

  if (incomingByte == 8) { // Turn the mobile toys on
    Serial.println ("Command: Toys ON");
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);

  if (incomingByte == 9) { //Turn mobile toys off
    Serial.println ("Command: Toys OFF");
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);


The first problem is normal I suspect - voice recognition is notoriously unreliable - just look at Alexa :wink:

For the second, have you got the high and low bytes the right way round? What does your serial output show you?

Do u mean on the speak up software or in the code?
My serial output will show this:
Command: Swing On
Received data = 60

So it eventually manages to understand what you said, but the swing doesn't move?

Did you try a less complex program to prove to yourself that you can move it?

Yes i operated the motors without the speak up click and it works but when i use the speak up it doesn't move

Could be power perhaps, or wiring disturbed when you attached the speak up board.

I'd try running the earlier code with the power & wiring as is. Might also be worth starting one of the motors in setup in the code you posted.

what earlier code?
but the problem is that I need it to be voice commanded

Whatever you used to test the motors standalone. From the serial output it looks like the voice command was recognized, so the issue is that the motors don't run. I'm suggesting that for debugging purposes you try the old code that you know works to figure out whether your wiring/power are still ok.

When i use this code the big motor spins
//Swing Motor (Big motor)
const int motorPin1 = 5; // Pin 14 of L293
const int motorPin2 = 6; // Pin 10 of L293
//Toy Motor (Small Motor)
const int motorPin3 = 10; // Pin 7 of L293
const int motorPin4 = 9; // Pin 2 of L293

//This will run only one time.
void setup(){
    //Set pins as outputs
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(motorPin3, OUTPUT);
    pinMode(motorPin4, OUTPUT);
    //Motor Control - Motor A: motorPin1,motorpin2 & Motor B: motorpin3,motorpin4

    //This code  will turn Motor A clockwise for 2 sec.
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);

Is it possible you can figure it out from the photo of my wiring.
Also, now it keeps reading different commands. Like if I say toys off, it says power off

So this turns the (swing?) motor on:

    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);

Try putting that in your "Swing on" section. Right now, you have it the other way round.

As to the commands being wrong, I suspect it's because voice recognition is hard and thirty bucks doesn't get you much. It hears "something off" and struggles to tell whether that something was toys or power. You may want to consider changing the command set to use phrases that are more different.

The high low doesn't matter it just controls the direction of clockwise or counterclockwise. But i have seen many videos where they use similar commands and it processes it. But it takes commands that don't even sound alike and switches them.

My point is that the motor isn't working and you need to figure out why. I would use the working code to try and eliminate possible causes.

The voice recognition is a separate issue: it may be that it has trouble with your accent. Perhaps there's background noise (I assume that there's a baby around) or you're not facing the microphone.

Also, I wouldn't be surprised to learn that the videos you saw were each the best of fifteen attempts. If Alexa, with her millions of dollars worth of cloud computers, AI and machine learning algorithms can't understand me, I don't expect that little thing to be foolproof.

So what would you suggest i do for the voice recognition. This is the youtube video i watched: Voice Control Your Arduino! SpeakUp Click Test - YouTube
I got the code from here an how to wire it and everything.

It depends. If you intend to use this with an actual baby, you may want to think about whether it's reasonable to use VR at all - it just isn't all that reliable. An IR remote might be a better choice.

If you're building something for fun or as a demo for school, it looks like the VR works some of the time and commands get through to the Arduino. So you need to spend some quality time debugging to find out why the motor doesn't spin up. Divide and conquer would be a useful way to go there. But it will never be flawless - you could find that the best thing you can do is to train yourself to speak more clearly when giving commands.

There are Arduino projects on-line using Alexa as the VR component and I expect there's stuff for the Google version too. Those would likely get you better accuracy, but I still expect you'll find yourself repeating what you said, sometimes multiple times. I certainly did before I turned Alexa off.

Whatever route you choose, there's going to be debugging though. If you're expecting it to be plug and play, I suspect you'll be disappointed.

I know it won't be like that. Its just for my senior project. And its all online so i need just one video of it all working and thats all
What option would you say is my best bet?

Is it possible that the swing doesn't work because the speak up needs 3.3v and the swing needs 12v or that has no connection?


Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Sorry, i didnt mean to cross post just had a new issue that came up so i posted my info agian with a new question

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.