Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: ESP32 Microphone
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-09-07 07:25:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Measures the voltage of the mic */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- const int micPin = 34; // ADC pin for microphone input
- // Reads the microphone voltage on the given ADC pin (ESP32, 12-bit ADC: 0-4095)
- float readMicVoltage(int pin)
- {
- int adcValue = analogRead(pin);
- // ESP32 ADC: 12-bit resolution, 0-4095
- // Map to 0 - 3.3V
- float voltage = (adcValue * 3.3f) / 4095.0f;
- return voltage;
- }
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(115200);
- // Give time for Serial to initialize
- delay(10);
- // Optional: configure ADC characteristics could go here if needed
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- int micValue = analogRead(micPin);
- float micVoltage = readMicVoltage(micPin);
- Serial.print("ADC: ");
- Serial.print(micValue);
- Serial.print(" Voltage: ");
- Serial.print(micVoltage, 3);
- Serial.println(" V");
- delay(50);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment