Arduino Sound Meter

Hackster.ioLearning Hardware Community. Projects× Log inSign up ProjectsProjectsChannelsChannelsNewsContestsEventsVideos ×

Embed the widget on your own site

Add the following snippet to your HTML:

Arduino Sound meter

In this video we make a sound level meter using an Ardiuino Una, a 1.3" OLED display and a microphone breakout board.

Read up about this project on Hackster.io

Arduino Sound meter

Rayan kiwan3 6,354
  • Overview
  • Things
  • Story
  • Code
  • Credits
  • Comments(0)
Rayan kiwanRayan kiwanPublished © GPL3+Arduino Sound meter

In this video we make a sound level meter using an Ardiuino Una, a 1.3" OLED display and a microphone breakout board.

IntermediateFull instructions provided6,354Arduino Sound meter

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
  • Buy from Newark
  • Buy from store.arduino.cc
  • Buy from Adafruit
  • Buy from Arduino Store
  • Buy from CPC
Gravity I2C OLED-2864 Display
DFRobot Gravity I2C OLED-2864 Display
×1
Gravity: Analog Sound Sensor For Arduino
DFRobot Gravity: Analog Sound Sensor For Arduino
×1
Jumper wires (generic)
Jumper wires (generic)
×1
  • Buy from Newark
  • Buy from SparkFun
Breadboard (generic)
Breadboard (generic)
×1
  • Buy from Newark
  • Buy from SparkFun

Software apps and online services

Arduino IDE
Arduino IDE
Arduino IDE
Arduino IDE

Story

Arduino Sound Level MeterIn this video we make a sound level meter using an Ardiuino Una, a 1.3" OLED display and a microphone breakout board. The sketch samples the AC waveform of the microphone for 50ms and records the minimum and maximum values. This gives us the peak-to-peak value for the sound.Then we convert this value to a calibrated decibel numeric value and then map that value to create a bar graph.

connections :

OLED:

connect VCC to 5V.

connect GND to GND.

connect SCL to A5.

connect SDA to A4.

sound sensor :

connect VCC to 5V.

connect GND to GND.

connect A0 pin to A0.

Read more

Code

  • arduino oled sound meter

arduino oled sound meter

Arduino //-------------------------------------------------------------------------------------------- // LIBRARIES //-------------------------------------------------------------------------------------------- #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_RESET 4 Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET); //-------------------------------------------------------------------------------------------- // GLOBAL VARIABLES //-------------------------------------------------------------------------------------------- const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz) unsigned int sample; //-------------------------------------------------------------------------------------------- // SETUP //-------------------------------------------------------------------------------------------- void setup() { Serial.begin(9600); //Serial comms for debugging display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //OLED display start display.display(); //show buffer display.clearDisplay(); //clear buffer display.setTextSize(1); //Set text size to 1 (1-6) display.setTextColor(WHITE); //Set text color to WHITE (no choice lol) display.setCursor(0,0); //cursor to upper left corner display.println(" Arduino Sound Meter"); //write title display.display(); //show title delay(2000); //wait 2 seconds } //-------------------------------------------------------------------------------------------- // MAIN LOOP //-------------------------------------------------------------------------------------------- void loop() { unsigned long startMillis= millis(); // Start of sample window float peakToPeak = 0; // peak-to-peak level unsigned int signalMax = 0; //minimum value unsigned int signalMin = 1024; //maximum value // collect data for 50 mS while (millis() - startMillis < sampleWindow) { sample = analogRead(0); //get reading from microphone if (sample < 1024) // toss out spurious readings { if (sample > signalMax) { signalMax = sample; // save just the max levels } else if (sample < signalMin) { signalMin = sample; // save just the min levels } } } peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude float db = map(peakToPeak,20,900,49.5,90); //calibrate for deciBels display.setCursor(0,0); //cursor to upper left display.setTextSize(2); //set text size to 2 display.print(db); //write calibrated deciBels display.print(" dB"); //write units for(int x =5;x<114;x=x+6){ //draw scale display.drawLine(x, 32, x, 27, WHITE); } display.drawRoundRect(0, 32, 120, 20, 6, WHITE); //draw outline of bar graph int r = map(db,0,120,1,120); //set bar graph for width of screen display.fillRoundRect(1, 33, r, 18, 6, WHITE); //draw bar graph with a width of r display.display(); //show all that we just wrote & drew display.clearDisplay(); //clear the display }

Credits

Rayan kiwan

Rayan kiwan

36 projects • 2 followersFollow ContactContact

Comments

Related channels and tags
  • DFRobot
  • microphone
  • oled
  • oled sound meter
  • sound meter

Tag » Arduino Db Meter Code