Live Stream Broadcast icon Live Stream Broadcast — Broadcast live audio and video from ARC camera to the web via HLS; cross-browser streaming. Requires router configuration for external access. Try it →
Asked
1 Participant
LattePanda Sharp IR Collision jitter

Lattepanda Sharp IR Collision Jitter

Running ARC on a LattePanda (Windows) and using the built-in Arduino Leonardo over USB as the EZB with the EZ-Genuino_Leonardo firmware. DTR Enabled is checked in the Connection config (without it the ADC readings didn’t update). I’ve got a Sharp GP2Y0A21YK0F wired to ADC0 (A0), powered from a PDF Robot shield’s 5V with common ground. Drive is two continuous rotation servos on D9 and D10 via the Continuous Rotation Movement Panel. The Sharp IR Collision skill is set to ADC0 with a stop threshold tuned so open space reads ~180-200 and an obstacle at ~20-25 cm drops to ~80-100. I expected the Movement Panel to stop only when the reading drops below the threshold, but I’m getting random stops in open space (values jittering 10-30 counts) and occasional late stops when approaching darker objects. The skill’s VU meter shows noticeable noise even with the robot stationary. I’ve tried: moving the sensor away from USB cabling, adding 0.1 F + 10 F decoupling at the sensor, twisting the signal/ground, measuring supply (5.02 V steady), and shielding from a nearby window (sunlight makes it worse). I also tested with a small JavaScript smoothing loop; it’s more stable, but I’m unsure if this is the recommended approach:

var thr = 100;
while(true){
  var hits = 0;
  for(var i=0;i<8;i++){
    if (GetADC(0) < thr) hits++;
    Sleep(10);
  }
  if (hits >= 6) { Stop(); }
}

Is there a built-in way to add hysteresis/debounce within the Sharp IR Collision skill (e.g., moving average or N-of-M confirmation), or should I rely on a script like the above, and if so, are my assumptions about the Leonardo ADC scaling in ARC (0-255 0-5 V) and threshold selection for the GP2Y0A21 correct?



Related Hardware (view all EZB hardware)
Lattepanda by DF Robot
LattePanda with Synthiam ARCx runs headless, loads EZB firmware on the built-in Arduino, and controls robots from any browser
Wi-Fi / USB
Servos 12
Camera
Audio
UART 1
I2C
ADC 5
Digital 12

Related Robot Skills (view all robot skills)
ADC Graph by Synthiam
Historical ADC graph and numeric readout (0-255) for 0-3.3/5V inputs; configurable board/port, sample interval, color, and pause for ezb controllers.
Stops movement panels when a Sharp IR sensor on EZB ADC detects objects within a set range; displays ADC voltage, VU meter and 0-255 distance value.

ARC Pro

Upgrade to ARC Pro

Subscribe to ARC Pro, and your robot will become a canvas for your imagination, limited only by your creativity.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Yes - your understanding of ARC’s ADC scaling is correct:

  • ADC ports in ARC read 0-255 on the Leonardo/ARC connection
  • That corresponds to roughly 0-5V
  • Your GP2Y0A21YK0F readings sound reasonable for a Sharp IR sensor
  • The noise you’re seeing is also very common with Sharp IR sensors, especially in sunlight and on darker/less reflective surfaces

What’s happening

The Sharp IR Collision skill is designed as a simple threshold-based stopper. It does not currently provide configurable:

  • moving average
  • hysteresis
  • N-of-M confirmation
  • debounce delay

So if the sensor value is bouncing around the minimum distance threshold, the Movement Panel can stop/start/stop unexpectedly.

For this sensor, I would not rely on the built-in Collision skill alone if you need stable behavior. The best practice is to:

  1. Read the ADC in a script
  2. Apply smoothing / confirmation
  3. Stop the Movement Panel only after several consecutive "hits"
  4. Optionally add hysteresis so it doesn’t re-arm until the reading rises well above the stop threshold

That will be much more reliable than a single raw sample.


A better JavaScript approach

Your example is close in spirit, but the loop needs a small fix and a little more structure.

Here’s a simple N-of-M confirmation example using a rolling average:

var adcPort = ADC0;
var stopThreshold = 100;      // stop if average falls below this
var rearmThreshold = 115;      // must rise above this before re-arming
var sampleCount = 6;
var hitCountRequired = 4;

var armed = true;

while (true) {
  var sum = 0;

  for (var i = 0; i < sampleCount; i++) {
    sum += ADC.get(adcPort);
    sleep(20);
  }

  var avg = sum / sampleCount;
  print("ADC avg = " + avg);

  if (armed && avg <= stopThreshold) {
    Movement.stop();
    armed = false;
    print("STOP triggered");
  }

  if (!armed && avg >= rearmThreshold) {
    armed = true;
    print("Re-armed");
  }

  sleep(30);
}

Why this helps

  • Average reduces noise
  • Hysteresis prevents rapid retriggering near the boundary
  • The robot won’t keep stopping from a single bad reading

If you want, I can also give you a version that uses a true N-of-M vote instead of averaging.


About your current threshold

Your threshold selection sounds in the right range, but for a Sharp sensor you should really calibrate using the exact mounted robot geometry:

  • measure the sensor value at your desired stop distance
  • then set the threshold a little before that
  • add hysteresis of about 10-20 ADC counts to start

Because Sharp sensors are nonlinear, the spacing between values changes with distance, so a threshold that works at 20 cm may not behave the same at 10 cm or 40 cm.


Why darker objects cause late stops

That’s also expected:

  • Sharp IR sensors depend on reflected IR light
  • black/dark/angled surfaces reflect less
  • sunlight can swamp the sensor and reduce reliability

So late stops on dark objects are a sensor limitation more than an ARC issue.


One important note about your snippet

This line:

for(var i=0;i= 6) {

should be something like:

for (var i = 0; i < 6; i++) {

Also, if you are using a script to control stopping, you’ll usually get more predictable results by calling the movement command directly from the script rather than relying on the Sharp Collision skill at the same time.


Best options, from most reliable to least

  1. Scripted smoothing + hysteresis
  2. Scripted N-of-M confirmation
  3. Built-in Sharp IR Collision skill alone

Helpful docs


If you want, I can write you a complete ARC JavaScript monitor that:

  • samples ADC0,
  • filters noise,
  • stops the movement panel,
  • and re-arms with hysteresis

for your LattePanda Leonardo setup.

I am a customer support AI and still learning. Please verify important answers in our support documentation. For advanced AI features, use the AI Script Agent built into ARC.