Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SparkFun Electret Microphone Breakout - BOB-12758 use gareko ho
- //https://support.arduino.cc/hc/en-us/articles/360014869820-How-to-install-the-Arduino-Create-Agent
- // https://forum.arduino.cc/t/analog-read-value-db/307667/2
- #include "thingProperties.h"
- int adc;
- int adc_ac;
- int volts;
- float decibelValue;
- int seconds;
- float bias; // when microphone is quiet how much does it read?
- float peak_value;
- void setup() {
- // Initialize serial and wait for port to open:
- Serial.begin(9600);
- // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
- delay(1500);
- // Defined in thingProperties.h
- initProperties();
- // Connect to Arduino IoT Cloud
- ArduinoCloud.begin(ArduinoIoTPreferredConnection);
- /*
- The following function allows you to obtain more information
- related to the state of network and IoT Cloud connection and errors
- the higher number the more granular information you’ll get.
- The default is 0 (only errors).
- Maximum is 4
- */
- setDebugMessageLevel(2);
- ArduinoCloud.printDebugInfo();
- }
- void loop() {
- bias = 400; //when silent what is the value being read?
- peak_value = 1024; // when full noise what is value being read
- ArduinoCloud.update();
- adc = analogRead(A0);
- adc_ac = adc - bias;
- // 5.0 is reference voltage , if you use microphone with different characteristics; check the datasheet
- // and replace 5.0 to maybe 3.3 or whatever is present
- volts = (5.0 / peak_value ) * adc_ac;
- decibelValue = -20.0 * log10(volts) + 6;
- seconds = millis() / 1000;
- }
- /*
- Since DecibelValue is READ_WRITE variable, onDecibelValueChange() is
- executed every time a new value is received from IoT Cloud.
- */
- void onDecibelValueChange() {
- Serial.print("decibel value set to ");
- Serial.println(decibelValue);
- }
Advertisement
Add Comment
Please, Sign In to add comment