<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Controlling Buzzer using Analog input</title><link>/products/arduino/b/blog/posts/controlling-buzzer-using-analog-input</link><description>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 proj...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Controlling Buzzer using Analog input</title><link>https://community.element14.com/products/arduino/b/blog/posts/controlling-buzzer-using-analog-input</link><pubDate>Sat, 07 Apr 2018 15:55:05 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:c5280da2-481c-4d27-940d-18cf602cc441</guid><dc:creator>rictrajano</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;&lt;span&gt;[mention:8fb233e8974445138ef0af2b63b49f94:e9ed411860ed4f2ba0265705b8793d05]&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;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 if the distance detected is not activating the buzzer, the reading is very fast, but as soon as the buzzer is activated, I only get the readings each time the buzzer sounds, which means depending on the delay of the sound the faster or slower I get the readings.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;If someone has a clue of how to get it to display the readings at a fast rate all the time I&amp;#39;ll appreciate the help.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Here&amp;#39;s the working code and the video of it working. I hope it helps someone on a similar quest.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Thanks for all the help&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3ef06e6b-9b7d-4651-b12d-db8be7f5e991:type=c_cpp&amp;amp;text=int+buzzer+%3D+11%3B%0A%2F%2F+the+setup+routine+runs+once+when+you+press+reset%3A%0Avoid+setup%28%29+%7B%0A++%2F%2F+initialize+serial+communication+at+9600+bits+per+second%3A%0A++Serial.begin%289600%29%3B%0A++pinMode%28buzzer%2C+OUTPUT%29%3B%0A%7D%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F+the+loop+routine+runs+over+and+over+again+forever%3A%0Avoid+loop%28%29+%7B%0A++%2F%2F+read+the+input+on+analog+pin+0%3A%0A++int+sensorValue+%3D+analogRead%28A0%29%3B%0A++%2F%2F+print+out+the+value+you+read%3A%0A++float+voltage+%3D+sensorValue+*+%283.3+%2F+1023.0%29%3B%0A++if++%28voltage+%3C+0.05%29%0A+++++++%7B+%0A++++++++tone%28buzzer%2C+700%29%3B%0A++++++++delay%2875%29%3B%0A++++++++noTone%28buzzer%29%3B+%0A++++++++delay%2875%29%3B+%0A+++++++%7D+++%0A+++++++if+%28voltage+%3E%3D+0.05+%26%26+voltage+%3C%3D+0.1%29%0A+++++++%7B%0A++++++++tone%28buzzer%2C+700%29%3B%0A++++++++delay%28150%29%3B++%0A++++++++noTone%28buzzer%29%3B+%0A++++++++delay%28150%29%3B+++%0A+++++++%7D%0A+++++++if+%28voltage+%3E+0.1+%26%26+voltage+%3C%3D+0.2%29%0A+++++++%7B%0A++++++++tone%28buzzer%2C+700%29%3B%0A++++++++delay%28200%29%3B++%0A++++++++noTone%28buzzer%29%3B+%0A++++++++delay%28200%29%3B+++%0A+++++++%7D%0A+++++++if+%28voltage+%3E+0.2%29%0A+++++++%7B%0A++++++++noTone%28buzzer%29%3B%0A+++++++%7D%0A++Serial.println%28voltage%29%3B+%0A%7D]&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span id="352c71fc_d970_48eb_8ad9_9ea881de66fe"&gt;&lt;span&gt;[View:https://www.youtube.com/watch?v=3j5Wp4iWBQ8:1110:699]&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=4598&amp;AppID=145&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Controlling Buzzer using Analog input</title><link>https://community.element14.com/products/arduino/b/blog/posts/controlling-buzzer-using-analog-input</link><pubDate>Wed, 04 Apr 2018 09:27:35 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:c5280da2-481c-4d27-940d-18cf602cc441</guid><dc:creator>beacon_dave</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;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)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a class="jive-link-external-small" href="https://www.arduino.cc/reference/en/language/structure/control-structure/else/" rel="nofollow ugc noopener" target="_blank" title="https://www.arduino.cc/reference/en/language/structure/control-structure/else/"&gt;https://www.arduino.cc/reference/en/language/structure/control-structure/else/&lt;/a&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3ef06e6b-9b7d-4651-b12d-db8be7f5e991:type=c_cpp&amp;amp;text=if+%28condition1%29%0A%7B%0A++%2F%2F+do+Thing+A%0A%7D%0Aelse+if+%28condition2%29%0A%7B%0A++%2F%2F+do+Thing+B%0A%7D%0Aelse%0A%7B%0A++%2F%2F+do+Thing+C%0A%7D]&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;img src="https://community.element14.com/aggbug?PostID=4598&amp;AppID=145&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>