Newbie looking for program debugging-motion sensor

Howdy,
I am wanting my arduino to control a small vibrating motor and led number display based on data received from a ping ultrasonic sensor… problem is that I can’t get any voltage to pin 13 (the pin to control motor relay) when I use the following program:

unsigned long echo = 0;
int ultraSoundSignal = 9; // Ultrasound signal pin
unsigned long ultrasoundValue = 0;

int motorPin = 13; // select the pin for the motort

int ledPinA = 8;
int ledPinB = 2;
int ledPinC = 6;
int ledPinD = 5;
int ledPinE = 4;
int ledPinG = 3;

void setup()
{
Serial.begin(9600);
pinMode(motorPin, OUTPUT); // declare the ledPin as an OUTPUT

pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, OUTPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinG, OUTPUT);

pinMode(ultraSoundSignal,OUTPUT);
}

unsigned long ping(){
pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
digitalWrite(ultraSoundSignal, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff
pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
digitalWrite(ultraSoundSignal, HIGH); // Turn on pullup resistor
echo = pulseIn(ultraSoundSignal, HIGH); //Listen for echo
ultrasoundValue = (echo / 58.138) * .39; //convert to CM then to inches
return ultrasoundValue;

}

void loop()
{
int x = 0;
x = ping();

// read the analog input into a variable:

//val = (1024-val1) + 1000;

// print the result:
Serial.println(x);
// wait 10 milliseconds for the analog-to-digital converter
// to settle after the last reading:
delay(10);

if (x < 6) {
digitalWrite(motorPin,LOW);
}

if ((x > 6) && (x < 18) ) {
digitalWrite(motorPin,HIGH);
delay(3000);
digitalWrite(motorPin,LOW);
delay(3000);

lightUpOne();

}

if (x > 18 ) {
digitalWrite(motorPin,HIGH);
delay(6000);
digitalWrite(motorPin,LOW);
delay(3000);

lightUpTwo();

}
}

void lightUpOne(){

digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, HIGH);

digitalWrite(ledPinA, LOW); // set the LED on
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinG, LOW);

}

void lightUpTwo(){

digitalWrite(ledPinA, HIGH); // set the LED on
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinG, HIGH);

digitalWrite(ledPinC, LOW);

}

If I upload test programs, such as arduino blink & vary the delay, I get voltage to pin 13, so I am guessing it has something to do with the sensor data in my programming?

I would be grateful if anyone could help me figure this out, it was working before with an IR sensor. Problems started when I switched to an ultrasonic sensor.
Thanks,
Crystal Keesey

There's a guy over at software/troubleshooting with exactly this problem.

Hi! Thanks for the quick response :)

Serial.println(x) is printing the distance values from the us sensor in inches...

Yes AWOL that guy in the software forum is this girl in the hardware interfacing forum :). I wasn't sure where to post since I've got both hardware interface and software issues ...

Yes I am getting values >6 and < 18, the sensor seems pretty accurate within it’s range

If x is printing out that it is in the range of the if tests, add some Serial.print statements in each if block, to verify that the block is entered.

If the block is entered, and the pin is set HIGH and the motor does not start, it's a hardware issue. You've provided virtually no details about the hardware.

Hi Paul, Thank you for responding. About the hardware:

It is a sculpture, a drum machine of sorts. A piece of sheet metal hung from the wall is sounded by a 48vdc vibrating massage motor mounted to a piece of flat stock steel mounted on a post. The motor is connected to ac relay and power supply. The motion sensor range values define the pulse of the motor (and therefore the drum beat). Finally a numeric lcd display mounted on the sheet metal tells the viewer which beat they are producing...so that the viewer can dance and make the beat at the same time.

Pin 13, the one that doesn't seem to work with my coding, is the motor relay pin.

I uploaded a simple lcd blink program to test the voltage of the arduino pin and it is working. So I have isolated it either to my coding or a bad relay. Tonight I troubleshoot the relay.

Could you please explain how to add a println(x) to each if block? I am unclear how I could see the values for each block on the serial monitor.

Thanks for your help. Cheers, Crystal

i mean Serial.print statements

if (x < 6) {
[glow]  Serial.println("X is less than 6");[/glow]
  digitalWrite(motorPin,LOW);
}

if ((x > 6) && (x < 18) ) {
[glow]  Serial.println("X is between 6 and 18");[/glow]
  digitalWrite(motorPin,HIGH);
  delay(3000);
  digitalWrite(motorPin,LOW);
  delay(3000);

  lightUpOne();

}

if (x > 18 ) {
[glow]  Serial.println("Whoa, X is big!");[/glow]
  digitalWrite(motorPin,HIGH);
  delay(6000);
  digitalWrite(motorPin,LOW);
  delay(3000);

  lightUpTwo();

}

Tell us about the relay. Perhaps it needs more current to activate it than the Arduino can supply.