element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Sensor input noisy when inserted to Arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 3 replies
  • Subscribers 392 subscribers
  • Views 414 views
  • Users 0 members are here
  • due
  • noise
  • frequency
Related

Sensor input noisy when inserted to Arduino

Former Member
Former Member over 11 years ago

Hello,

 

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:

http://www.limpkin.fr/index.php?post/2013/08/09/Making-the-electronics-for-a-%247-USD-doppler-motion-sensor

 

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()

{

  Serial.begin(19200);

  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(currentMillis);

    Serial.print(" "); // separator!

    Serial.print(Freq);

    Serial.print(" ");

    Serial.print(_pulsecount);

    Serial.print(" ");

    Serial.println(_duration);

  }

}

 

void myinthandler() // interrupt handler

{

  unsigned long currentMicros = micros();

  duration += currentMicros - previousMicros;

  previousMicros = currentMicros;

  pulsecount++;

}

 

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?

 

Thanks.

Attachments:
image
image
  • Sign in to reply
  • Cancel
  • colin_meikle@mentor.com
    colin_meikle@mentor.com over 11 years ago

    From the scope it looks as if the pin you are connecting is configured as an output rather than an input. Have you connected it to the correct pin ? Is your attachInterrupt correct, should the first arg not be the interrupt number unless you are using Due . Most Ardiunos only have 2 external interrupts so unless you are using Due the attach doesn't look right to me i.e.

     

    Syntax

    attachInterrupt(interrupt, ISR, mode)
    attachInterrupt(pin, ISR, mode)(Arduino Due only)
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to colin_meikle@mentor.com

    I am using the Due, hence the use of attachInterrupt.

     

    In regard to the scope, all the signals in the scope images are from the sensor and the amplifying and filter circuit (see explanations in the question), not from the Arduino.

     

    because I'm using interrupts I shouldn't use pinMode(6, INPUT), should I?

     

    Thanks.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • colin_meikle@mentor.com
    colin_meikle@mentor.com over 11 years ago in reply to Former Member

    Sorry Matt I missed the bit about the due, so the attachinterupt looks correct .

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube