Sensor input noisy when inserted to Arduino


I’m using the HB100 sensor to measure the speed of an approaching object.

I built amplifying and filter circuit based on the example presented here:

After the comparator, the output is a nice square signal (images attached - yellow - signal at the IF output of the sensor, blue - signal after the amplifier and filter, purple - signal after the comparator) when the sensor detect movement.

I’m using the following code:

#define MainPeriod 10
long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;
void setup()
  attachInterrupt(6, myinthandler, RISING);
void loop()
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= MainPeriod)
    previousMillis = currentMillis;  
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    float Freq = 1e6 / float(_duration);
    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(" "); // separator!
    Serial.print(" ");
    Serial.print(" ");
void myinthandler() // interrupt handler
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;

to measure the frequency. it’s working for frequencies that are higher than 1.5kHz for a square wave that is generated by signal generator.

The problem is when I input the signal at the comparator output to pin 6 of my Arduino Due (and looking at the signals through a scope) the signals are getting very noisy, thus I can’t measure the frequency accurately (when I disconnect the signal from pin 6 it all goes back to normal).

Any idea how to fix this?


photo 1.JPG

photo 2.JPG

You have to be a little more explicit:

  1. Add, at least, a block diagram.

  2. Scope signals are far from "nice".

  3. "based on the example presented here" is not enough: post the exact circuit you are using