sensors??????????

hi guys im running this sketch and was wondering if the EZ0 ultrasonic range finder will work with this type of system ?

#define N_LEDS 4

// LEDs connected to these digital pins
const int ledPin [N_LEDS] =
{
3, 5, 6, 9
};
// sensors connected to these digital pins
const int sensorPin [N_LEDS] =
{
2, 3, 4, 5
};

int outputValue = 0; // value output to the PWM (analog out)
int analogValue = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
int counter = 0;
while (counter < N_LEDS)
{
// read the analog input
analogValue = analogRead(sensorPin[counter]);
// map analog value
outputValue = map(analogValue, 250, 900, 0, 255);
// output
if (outputValue < 5)
{
analogWrite(ledPin[counter], 0);
}
else
{
analogWrite(ledPin[counter], outputValue);
}
counter = counter + 1;
}

// print the result to the serial monitor
Serial.print(analogValue);
Serial.print(" : “);
Serial.print(outputValue);
Serial.println(”----");

// wait 10 milliseconds for the analog-to-digital converter
delay(10);
}

Your pin numbers overlap (3, 5, 6, 9 and 2, 3, 4, 5).

hi guys im running this sketch and was wondering if the EZ0 ultrasonic range finder will work with this type of system ?

Are you asking if you can use the EZ0 ultrasonic range finder as the sensor being read by this sketch?

If so, you can. But, you might have interference between the sensors when using more than one at a time. You could power the range finders using digital pins (with transistors, if necessary), then turn only one sensor at a time on, if interference is an issue.

int counter = 0;
 while (counter < N_LEDS)
 {
   // some code in here
   counter = counter + 1;
 }

For this sort of construct, C/C++ has the “for” loop.

for (int counter = 0; counter < N_LEDS; counter++) {
  // some code in here
}

BTW, if you turn your keyboard upside down and shake it, you may be able to free whatever it is that is causing your question mark key to stick.