Shop OBEX P1 Docs P2 Docs Learn Events
PING))) triggers Sound Impact Sensor? — Parallax Forums

PING))) triggers Sound Impact Sensor?

oleskolesk Posts: 4
edited 2012-03-11 14:17 in Accessories
Hi!

I have a small rig with a Sharp Rangefinder, PING))) and a Parallax Sound Impact Sensor. The strange thing is this: whenever I run a sensor loop that triggers the PING))), the Sound Impact Sensor (SIS) triggers as well. Interestingly this happens without the LED on the SIS blinking. The SIS otherwise works very well.

I am testing this setup on an Arduino UNO, using this loop{} code:
void loop()
{
    uint16_t distance;
    
    Serial.println(F("*** Starting new sensor run ***"));
    
    detachInterrupt(1);
    distance = readSensor(0);
    Serial.print(F(" *** Final report for PING))) : "));
    Serial.println(distance);    
    attachInterrupt(1, readSensorSound, RISING);
}

Quick explanation for those not familiar with Arduino:
The loop{} is the main program loop, running forever. I have used attachInterrupt(1, readSensorSound, RISING); before initiating this loop to make a binary input pin on the Arduino trigger a hardware interrupt that calls the readSensorSound() function when the pin goes from low to high, whose only purpose is to print a message about a sound being detected to the serial port.

At first I thought that the SIS could hear ultrasound, so I put in the detachInterrupt before using the PING))) and then re-enabling the interrupt again after the PING))) was finished. This had no impact. Then I thought there might be echoes, so I build in three seconds pause before and after firing the PING))). Still I got a message from the SIS that it could hear something (all the while, no activity on the SIS LED).

The PING))) and the SIS sits about two inches apart. I haven not tried shielding the SIS in any way. They are attached to the same +5V and GND. I have double-checked that the sensor wires are not touching, and pulling the sensor wire from the SIS leads to nothing being reported, as expected (i.e. there isn't something else triggering the interrupt by raising the pin).

I do realize this might an Arduino specific issue, and in that case I'm probably in the wrong forum (and I humbly apologize). But perhaps someone would have an idea as why the PING))) could make the SIS go high without the LED blinking. A quick clap and the LED blinks and I get the message over the serial line, so it works well, minus the false positives every time the PING))) fires....

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-04 14:44
    My guess is the firing of the Ping causes a voltage dip that triggers the SIS. Try adding a capacitor to the Ping and/or SIS. I'd use a 0.1uF on both sensors plus a 1000uF on the Ping. This is probably overkill but once you get rid of the false trigger, you can scale back on the caps.
  • oleskolesk Posts: 4
    edited 2012-03-04 14:51
    Duane Degn wrote: »
    My guess is the firing of the Ping causes a voltage dip that triggers the SIS. Try adding a capacitor to the Ping and/or SIS. I'd use a 0.1uF on both sensors plus a 1000uF on the Ping. This is probably overkill but once you get rid of the false trigger, you can scale back on the caps.

    That does sound like a good thing to try. It's a bit late here at the moment, but I'll give it a shot tomorrow after work and see how it goes. Thanks for the idea.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-04 21:28
    Duane's hunch is probably right. If the LED on the Sound Impact Sensor isn't lighting then it likely didn't pick up anything. The trigger could be coming from noise induced somewhere in the Arduino. The Ping doesn't eat a lot of current, but be sure to test these kinds of sensors off batteries, or a wall transformer of adequate current, and not your USB. There can be added noise in USB power supplies on some computers, and some PC USB hubs inside the machine are under-rated. They don't deliver the recommended 500 mA for USB 2.0.

    You may also want to not attach and detach the interrupt the way you're doing it. That can cause some false triggers, too. If you need to ignore the SIS during a Ping read set a flag variable. If the variable is high, ignore the interrupt if it occurs. Depending on how you've coded the interrupt handler, you could so something like:
    if (!interruptFlag) {   // flag is false; go ahead and process the interrupt
      // process interrupt code here
    }
    

    Finally, keep in mind that those Sharp IRs draw a lot of current when they're triggering, and they are VERY noisy little critters. They can put a lot of hash on the Arduino's 5V line. Be sure to put big-o caps on its power rails, too.

    -- Gordon
  • oleskolesk Posts: 4
    edited 2012-03-05 00:56
    Thank you for the suggestions. I am currently at work, so I haven't been able to try it yet, but I will tonight and report back. There was one very interesting thing that I had no clue about though:
    You may also want to not attach and detach the interrupt the way you're doing it. That can cause some false triggers, too. If you need to ignore the SIS during a Ping read set a flag variable. If the variable is high, ignore the interrupt if it occurs.
    That's very interesting. Could you elaborate a little on the reason why this might cause issues? Is this because the attachInterrupt() or detachInterrupt() introduces brief noise/float/something on the pin (in this case binary 3)?
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-05 08:43
    I am unsure what causes the false signalling, but there's an open defect (bug) report on the Arduino Google code page regarding it. Altering some mask settings in the Arduino core supposedly fixes it, and the Arduino 1.0 IDE does not appear to have yet adopted the fix.

    I'm not sure if it's a universal issue. I recently encountered it when using switches pulled high by the internal pullups on pins 2 and 3. These are fairly weak, as pullups go, and I'm not sure if that has an effect. I added a "started" flag to the interrupt routines so that they wouldn't trigger in the setup function when the interrupts were attached. It's an easy enough fix in code, so you can quickly verify if that's your problem.

    -- Gordon
  • oleskolesk Posts: 4
    edited 2012-03-11 14:06
    Hi, and sorry I'm so slow in responding. Turns out that obsessing over electronics while planning your wedding can be rather hazardous ;)

    Anyway, Duane was indeed right. I set it up with capacitors and managed to get away with the false positives. Thanks a lot!

    Now I tried putting the servo back on that is supposed to rotate this rig around, and the SIS went completely nuts again, but now at least I know how to deal with it, so that shouldn't be a problem. I think it's reasonably safe to say that the SIS seems to be a rather sensitive fellow - none of the other sensors care the slightest (oh and the Sharp seems to be ok from a voltage drop point of view - haven't had it cause any issues for the SIS, and it's running without any capacitors).

    Thanks again for your kind help and explanations guys! Now back to wedding planning! :)

    OJ
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-11 14:17
    Good to hear you got it working.

    Thanks for the update.

    Good luck with your wedding.
Sign In or Register to comment.