Post your code. I can't tell anything from from your vague post. You probably know what sensors you have, and how you have them connected, and how you are reading them, but I don't. You might know what 'glitches out and spits out nothing' means, but I don't. I've never seen the serial monitor 'glitch out', and 'spits out nothing' doesn't make sense, unless you can see nulls arriving.
const int anPin = A5;
int ledPin = 9; // LED connected to digital pin 9
int cmDist;
int ledPin2 = 10;
int ledPin3 = 11;
int fadeValue;
int avRead;
const int pingPin = 7;
void setup() {
Serial.begin(9600); // nothing happens in setup
pinMode(anPin, INPUT);
}
void loop() {
avRead = analogRead(anPin); //11-25 values
Serial.println(avRead);
//
//delay(10);
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, 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
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
cmDist = cm;
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
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;
if(avRead <=17 && avRead >= 15 ){//thesehold within a range
fadingFunction();
fadingFunction4();
}
if(avRead >= 20 && avRead <=23){
fadingFunction2();
fadingFunction3();
}
}
///these are fading up functions
int fadingFunction(){
int faderUp;
for (fadeValue = 0 ; fadeValue <=255; fadeValue +=5) { //<< need a bracket here
analogWrite(ledPin, fadeValue);
faderUp = fadeValue;
delay(30);
}
}
int fadingFunction2(){
int faderUp2;
for (fadeValue = 0 ; fadeValue <=255; fadeValue +=5) { //<< need a bracket here
analogWrite(ledPin2, fadeValue);
faderUp2 = fadeValue;
delay(30);
}
}
int fadingFunction5(){
int faderUp2;
for (fadeValue = 0 ; fadeValue <=255; fadeValue +=5) { //<< need a bracket here
analogWrite(ledPin3, fadeValue);
faderUp2 = fadeValue;
delay(30);
}
}
///these are fading down functions for the led loop
int fadingFunction3(){
int faderUp3;
for (fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { //<< need a bracket here
analogWrite(ledPin, fadeValue);
faderUp3 = fadeValue;
delay(10);
}
}
int fadingFunction4(){
int faderUp4;
for (fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { //<< need a bracket here
analogWrite(ledPin2, fadeValue);
faderUp4 = fadeValue;
delay(10);
}
}
int fadingFunction6(){
int faderUp2;
for (fadeValue = 0 ; fadeValue <=255; fadeValue +=5) { //<< need a bracket here
analogWrite(ledPin3, fadeValue);
faderUp2 = fadeValue;
delay(30);
}
}