Lleg.attach(7); // attaches the servo on pin x to the servo object Rleg.attach(10); // attaches the servo on pin x to the servo object Lfoot.attach(8); // attaches the servo on pin x to the servo object Rfoot.attach(9); // attaches the servo on pin x to the servo object Neck.attach(11); // attaches the servo on pin x to the servo object

pinMode(EnableServo,OUTPUT); digitalWrite(EnableServo,HIGH); //this turns on the power to the servos CenterServos(); //center the servos delay(500); digitalWrite(EnableServo,LOW); //turn power off after centering

void loop(){ //check for obstacles, if none, go Forward, if found, turn the other way CheckObstacle();}

void CheckDistance(){ // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

// convert the time into a distance

cm = microsecondsToCentimeters(duration); obstacleDistance = cm;}

long microsecondsToCentimeters(long microseconds){ // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2;}

void CenterServos() // center the servos on powerup{ Lleg.write(LLcenter); // tell servo to go to position in variable 'center' Rleg.write(RLcenter); // tell servo to go to position in variable 'center' Lfoot.write(LFcenter); // tell servo to go to position in variable 'center' Rfoot.write(RFcenter); // tell servo to go to position in variable 'center' Neck.write(Neckcenter); // tell servo to go to position in variable 'center' delay(100); // waits 100ms for the servos to reach the position }

Lleg.attach(7); // attaches the servo on pin x to the servo object Rleg.attach(10); // attaches the servo on pin x to the servo object Lfoot.attach(8); // attaches the servo on pin x to the servo object Rfoot.attach(9); // attaches the servo on pin x to the servo object Neck.attach(11); // attaches the servo on pin x to the servo object

pinMode(EnableServo,OUTPUT); digitalWrite(EnableServo,HIGH); //this turns on the power to the servos CenterServos(); //center the servos delay(500); digitalWrite(EnableServo,LOW); //turn power off after centering

void CheckDistance(){ // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delay(2); digitalWrite(pingPin, HIGH); delay(5); digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

long microsecondsToCentimeters(long microseconds){ // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2;}

void CenterServos() // center the servos on powerup{ Lleg.write(LLcenter); // tell servo to go to position in variable 'center' Rleg.write(RLcenter); // tell servo to go to position in variable 'center' Lfoot.write(LFcenter); // tell servo to go to position in variable 'center' Rfoot.write(RFcenter); // tell servo to go to position in variable 'center' Neck.write(Neckcenter); // tell servo to go to position in variable 'center' delay(100); // waits 100ms for the servos to reach the position }

So the single threaded original code works as expected, the bot walks until it sees an obstacle, stops turns it head and checks how to go around the obstacle or if it's too close to back up.

The idea of the mutithread is that it could check for obstacle while walking and adjust without stopping. The problem being that my sensor values are returning as 0 iun the multi thread version. I've been at this for some hours now, and any input on how to fix it would be MUCH appreciated.

Lleg.attach(7); // attaches the servo on pin x to the servo object Rleg.attach(10); // attaches the servo on pin x to the servo object Lfoot.attach(8); // attaches the servo on pin x to the servo object Rfoot.attach(9); // attaches the servo on pin x to the servo object Neck.attach(11); // attaches the servo on pin x to the servo object

pinMode(EnableServo,OUTPUT); digitalWrite(EnableServo,HIGH); //this turns on the power to the servos CenterServos(); //center the servos delay(500); digitalWrite(EnableServo,LOW); //turn power off after centering

void CheckDistance(){ // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delay(2); digitalWrite(pingPin, HIGH); delay(5); digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

long microsecondsToCentimeters(long microseconds){ // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2;}

void CenterServos() // center the servos on powerup{ Lleg.write(LLcenter); // tell servo to go to position in variable 'center' Rleg.write(RLcenter); // tell servo to go to position in variable 'center' Lfoot.write(LFcenter); // tell servo to go to position in variable 'center' Rfoot.write(RFcenter); // tell servo to go to position in variable 'center' Neck.write(Neckcenter); // tell servo to go to position in variable 'center' delay(100); // waits 100ms for the servos to reach the position }

Lleg.attach(7); // attaches the servo on pin x to the servo object Rleg.attach(10); // attaches the servo on pin x to the servo object Lfoot.attach(8); // attaches the servo on pin x to the servo object Rfoot.attach(9); // attaches the servo on pin x to the servo object Neck.attach(11); // attaches the servo on pin x to the servo object

pinMode(EnableServo,OUTPUT); digitalWrite(EnableServo,HIGH); //this turns on the power to the servos CenterServos(); //center the servos delay(500); digitalWrite(EnableServo,LOW); //turn power off after centering

void CheckDistance(){ // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delay(2); digitalWrite(pingPin, HIGH); delay(5); digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

long microsecondsToCentimeters(long microseconds){ // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2;}

It looks like its missing the sensor reading sometime. I could add a 5th case where if any of the readings is 0 it continues forward, but it would not be very accurate for obstacle avoidance. There has to be something I'm missing here.

Or it could also be that while my 9v 170mAh rechargeable is providing enough current to drive 1 servo and the ping, 5 servos or 6 servos (and 2 RGB LEDs... It is not providing enough current to run 6 servos, the ping and 2RGB LEDs concurrently