{"id":1528,"date":"2014-11-09T16:56:47","date_gmt":"2014-11-09T15:56:47","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=1528"},"modified":"2014-11-09T17:02:57","modified_gmt":"2014-11-09T16:02:57","slug":"arduino-use-an-op-amp-lm358-and-a-microphone","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=1528","title":{"rendered":"Arduino : use an op-amp (lm358) and a microphone"},"content":{"rendered":"<p>I found a small microphone unused in some old box.<br \/>\nI decided I could play with it by plugging it to my arduino.<br \/>\nWas rather easy using the analogread function but it was lacking sensitivity.<\/p>\n<p>Googling around it appeared I needed an op-amp.\u00a0For less than 2 euros, I could get a 10 pieces batch on ebay.<\/p>\n<p>See below the schematic.<br \/>\nNotice the voltage divider (r3 to 5v, r2 to gnd) to get a 2.5v voltage (5v \/ 2) : this way, you should read about 512 (1024 \/ 2) on the analog port when the microphone is off.<br \/>\nNotice the gain as well (r5\/r4) which should give me about x75 gain (r5\/r4*vin).<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/11\/lm358_2.bmp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/11\/lm358_2.bmp\" alt=\"lm358_2\" width=\"2178\" height=\"1494\" class=\"alignnone size-full wp-image-1529\" \/><\/a><\/p>\n<p>The Arduino sketch is rather simple : it will trigger a led when the reading goes about a certain value (that will depend on your mic and r0).<\/p>\n<pre>\r\nconst int analogInPin = A0;  \r\nconst int ledPin=13;\r\nint sensorValue = 0;        \r\n\r\nvoid setup() {\r\n  Serial.begin(38400); \r\n  pinMode(ledPin, OUTPUT); \r\n}\r\n\r\nvoid loop() {\r\n  digitalWrite(ledPin, LOW);\r\n  sensorValue = analogRead(analogInPin);            \r\n  if (sensorValue>640 || sensorValue<580) {\r\n  Serial.print(\"sensor = \" );                       \r\n  Serial.println(sensorValue);   \r\n  digitalWrite(ledPin, HIGH);  \r\n  delay(50);\r\n  }\r\n  delay(50);                     \r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I found a small microphone unused in some old box. I decided I could play with it by plugging it to my arduino. Was rather easy using the analogread function but it was lacking sensitivity. Googling around it appeared I needed an op-amp.\u00a0For less than 2 euros, I could get a 10 pieces batch on <a href='https:\/\/labalec.fr\/erwan\/?p=1528' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[67],"class_list":["post-1528","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-lm358","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1528"}],"version-history":[{"count":2,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1528\/revisions"}],"predecessor-version":[{"id":1531,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1528\/revisions\/1531"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}