Hi all,
I am trying to find a power source for as listed above, 3 motors, a sensor, and a voice recognition module (Geeetech High Sensitivity). I am using a 4 cell 18650 Li-Ion battery with a step down dc to dc converter. When I test the separate parts, such as the Voice Recognition Module, it seems like it powers too little. The light on the Voice Recognition is very thin and no action whatsoever. If I replace the Li-Ion with 4 AAA batteries in a series, it works completely fine, for each part. What is the problem?
One Radioshack Micro servo and two Parallax continuous rotation servos
An Ultrasonic HC-SR04 Sensor
A Geeetech High Sensitivity Voice Recognition Module
I also have this code which is supposed to follow 3 commands and do separate actions for those commands. Does this code work?
There is a Stop command, Wander command, and Look Around command.
//Voice Recognition Code
#include <Servo.h>
const int RForward = 1000;
const int RBackward = 2000;
const int LForward = 1000;
const int LBackward = 2000;
const int RNeutral = 1500;
const int LNeutral = 1500; //constants for motor speed
const int trigpin = 7;
const int echopin = 3;
const int dangerThresh = 10; //threshold for obstacles (in cm)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;
Servo leftMotor;
Servo rightMotor; //declare motors
long duration; //time it takes to recieve PING))) signal
byte com = 0;
void setup (){
Serial.begin(9600);
delay(2000);
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);
delay(2000);
rightMotor.attach(11);
rightMotor.writeMicroseconds(1500);
leftMotor.writeMicroseconds(1500);
leftMotor.attach(10);
panMotor.attach(9);
delay(1000);
panMotor.write(90);
}
void loop ()
{
while(Serial.available())
{
com = Serial.read();
switch(com)
{
case 0x11:
{
loop();
{
int distanceFwd = ping();
if (distanceFwd>dangerThresh) //if path is clear
{
leftMotor.writeMicroseconds(LForward);
rightMotor.writeMicroseconds(RForward); //move forward
}
else //if path is blocked
{
leftMotor.writeMicroseconds(LNeutral);
rightMotor.writeMicroseconds(RNeutral);
panMotor.writeMicroseconds(1000);
delay(500);
rightDistance = ping(); //scan to the right
delay(500);
panMotor.writeMicroseconds(2000);
delay(700);
leftDistance = ping(); //scan to the left
delay(500);
panMotor.writeMicroseconds(1500); //return to center
delay(100);
compareDistance();
}
}
}
break;
case 0x12:
{
panMotor.writeMicroseconds(2000);
delay(1000);
panMotor.writeMicroseconds(1000);
delay(1000);
panMotor.writeMicroseconds(1500);
delay(1000);
leftMotor.writeMicroseconds(1500);
rightMotor.writeMicroseconds(1500);
}
break;
case 0x13:
{
panMotor.writeMicroseconds(1500);
leftMotor.writeMicroseconds(LNeutral);
rightMotor.writeMicroseconds(RNeutral);
}
break;
}
}
}
void compareDistance()
{
if (leftDistance>rightDistance) //if left is less obstructed
{
leftMotor.writeMicroseconds(LBackward);
rightMotor.writeMicroseconds(RForward); //turn left
delay(500);
}
else if (rightDistance>leftDistance) //if right is less obstructed
{
leftMotor.writeMicroseconds(LForward);
rightMotor.writeMicroseconds(RBackward); //turn right
delay(500);
}
else //if they are equally obstructed
{
leftMotor.writeMicroseconds(LForward);
rightMotor.writeMicroseconds(RBackward); //turn 180 degrees
delay(1000);
}
}
long ping()
{
// Send out PING))) signal pulse
pinMode(trigpin, OUTPUT);
pinMode(echopin,INPUT);
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
digitalWrite(trigpin, LOW);
//Get duration it takes to receive echo
duration = pulseIn(echopin, HIGH);
//Convert duration into distance
return duration / 29 / 2;
}