0

Maxbotix LV1 unstable readings
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Thu Jan 10, 2019 10:48 am

Hi,
I'm using the Maxbotix LV-1 ultrasonic sensor with the Wave Shield to play sounds when a person walks under its beam. I had it working totally fine for a while until the sensor started randomly outputting numbers that fell within the desired trigger range and would cause sounds to play when nobody was underneath the beam.
I looked it up, found this website https://www.maxbotix.com/articles/maxsonar-troubleshooting.htm and tried both of the troubleshooting options found there. The first one was to put a piece of tape over the sensor while powered off, then power back on and supposedly get more stable readings.
Well that didn't work so I proceeded to troubleshoot for electrical noise.
I've soldered a 100 uF capacitor between power and ground, keeping the proper polarity consistent, and now I'm getting a constant reading of around 511 inches (twice that of the maximum distance reported before soldering the cap) and it does not detect anything.

If anybody can help me with this, I'm willing to pay cash money for assistance because I'm a bit stumped as to what the solution is here.
Here's my functional code:
Code: Select all | TOGGLE FULL SIZE
/*
This code reads the Analog Voltage output from the
LV-MaxSonar sensors and produces audio on the Adafruit Wave Shield
*/
#include <WaveHC.h>
#include <WaveUtil.h>

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the volumes root directory
FatReader file;   // This object represent the WAV file
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time


#define playcomplete(x) ROM_playcomplete(PSTR(x))         // save RAM by using program memory strings


const int anPin1 = 0;
long distance1;

void setup() {
  Serial.begin(9600);  // sets the serial port to 9600
   Serial.println(F("Wave test!"));

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  if (!card.init()) {
    Serial.println(F("Card init. failed!")); return;
  }
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {   // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                           // we found one, lets bail
  }
  if (part == 5) {                     // if we ended up not finding one  :(
    Serial.println(F("No valid FAT partition!"));  // Something went wrong, lets print out why
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  Serial.print(F(", type is FAT"));
  Serial.println(vol.fatType(), DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    Serial.println(F("Can't open root dir!"));      // Something went wrong,
  }
 
  // Whew! We got past the tough parts.
  Serial.println(F("Files found (* = fragmented):"));

  // Print out all of the files in all the directories.
  root.ls(LS_R | LS_FLAG_FRAGMENTED); 
}

void read_sensors(){
  /*  Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in
  Arduino analog pin goes from 0 to 1024, so the value has to be divided by 2 to get the actual inches
  */
  distance1 = analogRead(anPin1)/2;
}

void print_all(){
  Serial.print("S1");
  Serial.print(" ");
  Serial.print(distance1);
  Serial.print("inches");
  Serial.println();
}

void loop() {
  read_sensors();
  print_all();
  delay(50);

  if(distance1<40 && distance1>20){ //adult height 5 feet or taller
  playcomplete("FART1.WAV");
  delay(2200);
  }
  if(distance1>40 && distance1<60){ //youth height under 5 feet but taller than 3 feet
  playcomplete("FART2.WAV");
  delay(2200);
  }
  if(distance1>60 && distance1<80){ //baby size under 3 feet taller than 10 inches
  playcomplete("FART3.WAV");
  delay(2200);
  }
  }

void ROM_playcomplete(const char *romname) {
  char name[13], i;
  uint8_t volume;
  int v2;
 
  for (i=0; i<13; i++) {
    name[i] = pgm_read_byte(&romname[i]);
  }
  name[12] = 0;
  Serial.println(name);
  playfile(name);
  while (wave.isplaying) {
   volume = 0;
   for (i=0; i<8; i++) {
     v2 = analogRead(1) - 512;
     if (v2 < 0)
        v2 *= -1;
     if (v2 > volume)
       volume = v2;
     delay(5);
   }
 
   //Serial.print(F("vol = ")); Serial.println(volume, DEC);
  }
  file.close();
}

void playfile(char *name) {

   if (!file.open(root, name)) {
      Serial.println(F(" Couldn't open file")); return;
   }
   if (!wave.create(file)) {
     Serial.println(F(" Not a valid WAV")); return;
   }
   // ok time to play!
   wave.play();
}

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by adafruit_support_bill on Thu Jan 10, 2019 3:11 pm

Please post some photos showing your soldering and connections. A view showing how your sensor is mounted and aimed may be helpful as well.

adafruit_support_bill
 
Posts: 73210
Joined: Sat Feb 07, 2009 10:11 am

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Thu Jan 10, 2019 4:42 pm

maxbotix sensor.jpg
maxbotix sensor.jpg (267.45 KiB) Viewed 167 times
The sensor is circled in white. Mounted roughly 9 feet in the air and was detecting people who walked under the sensor or slid down the slide.

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Thu Jan 10, 2019 4:44 pm

Here's the Wave Shield which is mounted atop an Arduino Uno. The blue/green sends power/ground to/from the sensor and the orange/white pin receives analog distance data on pin 0.
WaveShield circuit.jpg
WaveShield circuit.jpg (308.76 KiB) Viewed 167 times

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Thu Jan 10, 2019 4:44 pm

Wave Shield pins.jpg
Wave Shield pins.jpg (248.6 KiB) Viewed 167 times

Pins detail

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Thu Jan 10, 2019 4:46 pm

I can gather pictures of the sensor with the new smoothing cap I installed, but may have to wait until tomorrow. It was functioning normally for a little while and now it seems there is "electric noise" on the circuit because the distance readings are erratic which they weren't before, they were pretty stable until now.

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by adafruit_support_bill on Thu Jan 10, 2019 5:23 pm

How long is the wire run from the Arduino & wave shield to the sensor?

adafruit_support_bill
 
Posts: 73210
Joined: Sat Feb 07, 2009 10:11 am

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Fri Jan 11, 2019 12:19 pm

Approximately 50 feet at the most. Probably less than that.

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Fri Jan 11, 2019 12:25 pm

Also, here are pictures of the top and bottom of the sensor with the smoothing cap attached.
maxbotix sensor cap top.jpg
Maxbotix sensor cap top
maxbotix sensor cap top.jpg (235.26 KiB) Viewed 133 times

Maxbotix sensor cap bottom.jpg
Bottom of sensor with 100 uF smoothing cap
Maxbotix sensor cap bottom.jpg (193.7 KiB) Viewed 133 times


I spoke with a very nice fellow at Maxbotix who says it sounded like an open circuit if it's constantly reading 511 inches. However, I checked for shorts and couldn't find any. I'm going to do a current test on it to see how much amperage is feeding the sensor.
I might just have a bad capacitor, but I don't have a capacitance measurement tool.

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by adafruit_support_bill on Fri Jan 11, 2019 1:50 pm

I spoke with a very nice fellow at Maxbotix . . .

The maxbotix folks are quite helpful. :)
. . . who says it sounded like an open circuit if it's constantly reading 511 inches. However, I checked for shorts and couldn't find any

A short is the opposite of an open circuit. Check for continuity in all of your wiring.

Approximately 50 feet at the most. Probably less than that.

50 feet is quite a long run for an analog signal. Are you using shielded cable?

adafruit_support_bill
 
Posts: 73210
Joined: Sat Feb 07, 2009 10:11 am

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Fri Jan 11, 2019 6:03 pm

It's possible that I hooked it back up wrong...

I say this because I just brought the board + shield and sensor back to my workbench for testing and it worked normally. Either that or the cable run is too long, and it's definitely unshielded.
There are also a few pretty significant bends in the cable that could affect the signal. My original intent was to eliminate all of the severe bends from the cable, but the way it's been installed (zip ties along the ceiling conduit) we would have to redo the entire run (which is seeming likely anyhow)

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by adafruit_support_bill on Fri Jan 11, 2019 7:12 pm

Bends in the cable are generally not an issue. But proximity to other wiring and sources of electrical noise can be a problem with long runs. A long unshielded wire is basically an antenna for electrical interference.

Things like motors, relays, fluorescent or LED lighting all generate electrical noise. Running your signal wires close to that equipment, or the wires that supply power to them can result in noise picked up on your signal wires. That can cause random results and/or false triggering.

adafruit_support_bill
 
Posts: 73210
Joined: Sat Feb 07, 2009 10:11 am

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Mon Jan 14, 2019 6:05 pm

Sorry all, I had actually just wired it wrong and it works fine now *_^ MY BAD
Hopefully we won't need to replace the ethernet cable, but if there are more random noises going forward, I will push for shielded cabling to be installed.

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Re: Maxbotix LV1 unstable readings

by adafruit_support_bill on Mon Jan 14, 2019 6:29 pm

Good to hear you've got it working again.


Ethernet cable can also be pretty effective at rejecting noise. Each cable consists of 4 twisted pairs of wires. If you use one of the twisted pairs for the signal and GND and another pair for +5v and GND most of the noise should cancel out.

adafruit_support_bill
 
Posts: 73210
Joined: Sat Feb 07, 2009 10:11 am

Re: Maxbotix LV1 unstable readings

by 0hm_Mic_0dd on Tue Jan 15, 2019 3:59 pm

Thanks for this great advice! If the issue pops up again, I will try rewiring like this. There's only 1 ground pin on the sensor but perhaps I can splice them together.

0hm_Mic_0dd
 
Posts: 43
Joined: Thu Dec 06, 2018 2:51 pm

Please be positive and constructive with your questions and comments.