pleasedontcode

ESP32 Microphone rev_01

Sep 7th, 2025
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: ESP32 Microphone
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-09-07 07:25:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Measures the voltage of the mic */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. const int micPin = 34;  // ADC pin for microphone input
  33.  
  34. // Reads the microphone voltage on the given ADC pin (ESP32, 12-bit ADC: 0-4095)
  35. float readMicVoltage(int pin)
  36. {
  37.     int adcValue = analogRead(pin);
  38.     // ESP32 ADC: 12-bit resolution, 0-4095
  39.     // Map to 0 - 3.3V
  40.     float voltage = (adcValue * 3.3f) / 4095.0f;
  41.     return voltage;
  42. }
  43.  
  44. void setup(void)
  45. {
  46.     // put your setup code here, to run once:
  47.     Serial.begin(115200);
  48.     // Give time for Serial to initialize
  49.     delay(10);
  50.     // Optional: configure ADC characteristics could go here if needed
  51. }
  52.  
  53.  
  54. void loop(void)
  55. {
  56.     // put your main code here, to run repeatedly:
  57.     int micValue = analogRead(micPin);
  58.     float micVoltage = readMicVoltage(micPin);
  59.  
  60.     Serial.print("ADC: ");
  61.     Serial.print(micValue);
  62.     Serial.print("  Voltage: ");
  63.     Serial.print(micVoltage, 3);
  64.     Serial.println(" V");
  65.  
  66.     delay(50);
  67. }
  68.  
  69. /* END CODE */
  70.  
Advertisement
Add Comment
Please, Sign In to add comment