element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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
Blog Controlling Buzzer using Analog input
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: rictrajano
  • Date Created: 4 Apr 2018 8:42 AM Date Created
  • Views 12927 views
  • Likes 3 likes
  • Comments 12 comments
Related
Recommended

Controlling Buzzer using Analog input

rictrajano
rictrajano
4 Apr 2018

Hello,

 

I’ve been an electronics curious since a child but never got in too deep. I’ve recently bought an Arduino, start playing with it and realised the potential of this device. I started thinking and it would be the perfect solution for a project that I’ve been wanting to do for a long time.

 

I have a laser that mesures distances with a board which I can make it output a Voltage depending on how far it is from an object, and the final objecting is activating a buzzer whenever in reaches a certain threshold. I was planing on having two different signals for different distances e.g at 5m would start to buzz every half a second in a certain frequency (700Hz) and when it would reach 2m would buzz every 1/8 of a second in the same frequency. Of course the distances in this case would be read as voltages for the arduino.

 

So far I manage to make the Arduino read the voltage fluctuation and already created a project where I make the buzzer work in diferent timer intervals and frequencies. I’m only missig the code to do everything interact with each other. I’ve been fideling around with it but couldn’t manage to find a solution.

 

Does anyone would know how could I be able to achieve this amazingly complex engineering project. image

 

Thank you very much for your help

  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 7 years ago in reply to rictrajano +2
    rictrajano Thanks for the code, and I've now discovered the tone command. Tone drives the appropriate pin (buzzer) with a 50% duty cycle at the desired frequency. You wish to generate this tone when the…
  • rictrajano
    rictrajano over 7 years ago +2
    mcb1 So finally I managed to make the code work. The only thing that still is making me pull my hair is that the readings in the Arduino serial monitor are only refreshed as fast as the Buzzer delay. So…
  • rictrajano
    rictrajano over 7 years ago in reply to beacon_dave +1
    I’ve used some conditions and I’ve managed to make it work with a LED but for the buzzer I need to specify the tone and the delay between buzzes abd that’s when tge conditions stop working and I just get…
  • rictrajano
    rictrajano over 7 years ago in reply to beacon_dave

    I’ve used some conditions and I’ve managed to make it work with a LED but for the buzzer I need to specify the tone and the delay between buzzes abd that’s when tge conditions stop working and I just get the constant intermitent buzz.

     

    I’ll post later where I’m at with the code and you‘ll have a better idea what I might be doing wrong.

     

    thanks

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 7 years ago

    Perhaps take a look at the if...else structure to test for various conditions (e.g. distances) and then act upon them (e.g. change buzzer settings)

     

    https://www.arduino.cc/reference/en/language/structure/control-structure/else/ 

     

    if (condition1)
    {
      // do Thing A
    }
    else if (condition2)
    {
      // do Thing B
    }
    else
    {
      // do Thing C
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • 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 © 2026 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