Maxsonar range sensor passing constant values..

Hi there Guys,

RE: Maxsonar range sensor passing constant values…

I recently purchased a nice little Maxsonar EZ4 sensor for an artwork and it sensed accurately with it’s first test.

Subsequently, I created a new project and the sensor is now reading as (raw data -i.e. no conversion - via serial monitor):

757
756
757
757
757
757
758
757
758
758
759 …

The Arduino microcontroller is reading the sensor’s AN output, powered off the +5v pin and ground pin.
I swapped out the microcontroller to test again and received the same results, even when moving a large book back and forth by a foot or three directly in front of the sensor.

The test sketch initializes the analog pin to 0 on start and loops every 500 ms for the reading.

Is there a way to re-set the sensor unit, or based on the constant readings has it been damaged?

Any advice much appreciated!

Thanks,

Rich.

// using the maxsonar quick start (from) http://www.adafruit.com

int sonarPin = 0; //pin connected to analog out on maxsonar sensor
int inchesAway = 0; 

void setup() {
//none
}

void loop() {
  inchesAway = analogRead(sonarPin);
    delay(500);
    Serial.begin(9600);
    Serial.println(inchesAway);
  
}

I`m not sure about the sensor readings, as I haven't used once of these before. Constant reading shouldn't be a problem for it though.

However, you shouldn't have Serial.begin(9600) in the loop. This only needs to be run once, so should go in the setup() function.

Hi Programmer, thanks for your help.

You're right about the Serial.begin! - thanks. I moved it into the setup so it initializes only once and re-tested.

The problem I see with the sensor is there's no change in the values read from the sensor, even when there should be. If it's removed, the Arduino analog in reads mostly constant around the 320 mark, so when connected I think the sensor is still circulating the +5 voltage OK, but not reacting to object detections.

Prior to this, the unit was part of a larger b/board project which started to run inconsistently, so I've isolated the sensor to test it...