Arduino+easyvr+servo motor

Dear ALL
I am doing my senor year project and I am working on an arduino uno and an easy vr board along with a servo motor HS755 .

i tried to turn servo motor but it refused to work and the COM window(serial monitor) of the arduino asks for command from group 0 and I give it but it stops right there.
However when I unplug the servo motor, the COM window (serial monitor )asks me to say the commands as it is supposed to do if servo motor is plugged ( asking for a command from group 0 then a command for group 1 ) and when i dont give it a command it keep asking for it the command on and on.
PS: I already tried a code on a LED and it worked perfectly .

this is the motor Code:

#include "Servo.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
#include "WProgram.h"
#include "NewSoftSerial.h"
NewSoftSerial port(12,13);
#endif

#include "EasyVR.h"

Servo myservo;
EasyVR easyvr(port);

//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};

enum Group0
{
G0_ARDUINO = 0,
};

enum Group1
{
G1_UN= 0,
G1_DEUX = 1,
};

EasyVRBridge bridge;
int servo_pos ;
int8_t group, idx;

void setup()

{

// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}
// run normally
Serial.begin(9600);
port.begin(9600);
myservo.attach(9);
if (!easyvr.detect())
{
Serial.println("EasyVR not detected!");
for (;;);
}

easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.print("EasyVR detected, version ");
Serial.println(easyvr.getID());
easyvr.setTimeout(5);
easyvr.setLanguage(0);
group = EasyVR::TRIGGER;

}

void action();

void loop()
{

easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)

Serial.print(" Say a command in Group ");
Serial.println(group);
easyvr.recognizeCommand(group);
do
{
// can do some processing while waiting for a spoken command
}
while (!easyvr.hasFinished());

easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

idx = easyvr.getWord();
if (idx >= 0)
{
// built-in trigger (ROBOT)
// group = GROUP_X; <-- jump to another group X
return;
}
idx = easyvr.getCommand();
if (idx>= 0)
{
// print debug message
uint8_t train = 0;
char name[32];
Serial.print("Command: ");
Serial.print(idx);
if (easyvr.dumpCommand(group, idx, name, train))
{
Serial.print(" = ");
Serial.println(name);
}
else
Serial.println();
easyvr.playSound(0, EasyVR::VOL_FULL);
// perform some action
action();
}
else // errors or timeout
{
if (easyvr.isTimeout())
Serial.println("Timed out, try again…");
int16_t err = easyvr.getError();
if (err >= 0)
{
Serial.print("Error ");
Serial.println(err, HEX);
}
}
}

void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_ARDUINO:
// write your action code here
group = GROUP_1;
// group = GROUP_X; <– or jump to another group X for composite commands
break;
}
break;
case GROUP_1:
switch (idx)
{
case G1_UN:
group = GROUP_0; //&lt;-- or jump to another group X for composite commands

servo_pos -= 8;
//servo_pos--;
myservo.write(servo_pos); // set the LED on
group = GROUP_0;
// write your action code here
// group = GROUP_X; <– or jump to another group X for composite commands
break;
case G1_DEUX:
group = GROUP_0; //&lt;-- or jump to another group X for composite commands
servo_pos+=1;
myservo.write(servo_pos);
group = GROUP_0;
// write your action code here
// group = GROUP_X; <– or jump to another group X for composite commands
break;
}
break;
}
}

Two things ...

Have you noticed there is a smiley in the middle of your code - not very helpful! That's because you did not read the How To Use The Forum and did not put your code in code tags. Please edit your post and correct this.

How are you powering the servo?. It should have its own power supply with a common ground with the Arduino. Servos draw too much current to be powered from the Arduino 5v connection and can cause the Arduino to reset with strange consequences - including possible loss of connection to the PC.

...R

I did notice the smily :wink: :stuck_out_tongue:
thank you

Mariem:
I did notice the smily :wink: :stuck_out_tongue:
thank you

But you seem to have decided to ignore my request to do something about it ....

...R

the problem is not with the code
so there is no need to fix it
i didnt mean to ignore you :slight_smile:

If you don't need advice on code, why post it?
If you post it why not do it properly?

The fact that you didn't post it properly distracted me from the rest of your message, wasting your time and mine.

It sounds like you are powering the servo from the Arduino and the Arduino can't provide enough current. Servos (and motors) should have a separate power supply (about 1 amp per servo) and a common ground with the Arduino.

...R

ii just wanted to double check :stuck_out_tongue: :stuck_out_tongue: