AHT20+BMP280 Module
Controls
Properties
Availability & Pricing
Distributor | Qty 1 |
---|
Assets
id=TEM-HUM-DHT11_4P-15.5X12.0MM_ Symbol.svg
id=Untitled v1
id=AHT20+BMP280 Module
id=F_M
Simulation
Analyzing TonesCpp
#include <Arduino.h> const int micPin = A0; // Microphone connected to analog pin A0 void setup() { Serial.begin(9600); } void loop() { int micValue = analogRead(micPin); // Read microphone output Serial.println(micValue); // Print the value to the Serial Monitor delay(10); // Delay for stability }
arduinoFFT
can be used for performing FFT on the recorded audio signals.1. MIC:+ to Resistor:2.2kΩ.
2. Resistor:2.2kΩ to Transistor:Base.
3. Transistor:Collector to Arduino:5V via Resistor:10kΩ.
4. Transistor:Emitter to GND.
5. Capacitor:100nF from Transistor:Collector to Arduino:A0.
6. MIC:- to GND.
Arduino Code for Reading Microphone Signal
Tone AnalysisCpp
#include <Arduino.h> const int micPin = A0; // Microphone connected to analog pin A0 void setup() { Serial.begin(9600); } void loop() { int micValue = analogRead(micPin); // Read microphone output Serial.println(micValue); // Print the value to the Serial Monitor delay(10); // Delay for stability }
Cpp
#include <Arduino.h> const int micPin = A0; // Microphone connected to analog pin A0 const int numSamples = 100; // Number of samples to plot void setup() { Serial.begin(9600); } void loop() { for (int i = 0; i < numSamples; i++) { int micValue = analogRead(micPin); // Read microphone output Serial.println(micValue); // Send the value to the Serial Plotter delay(20); // Small delay for better plotting resolution } }
Cpp
void loop() { for (int i = 0; i < numSamples; i++) { int micValue = analogRead(micPin); Serial.println(micValue); delay(1); // Reduced delay for higher sampling rate } }
arduinoFFT
or a similar library to perform frequency analysis on the incoming audio data. This allows you to visualize the frequency spectrum, which can help in identifying specific tones.Additional RecommendationsCpp
#include <Arduino.h> #include <arduinoFFT.h> #define SAMPLES 64 // Must be a power of 2 #define SAMPLING_FREQUENCY 1000 // Hz, must be less than 10000 due to ADC limitations arduinoFFT FFT = arduinoFFT(); unsigned int sampling_period_us; unsigned long microseconds; double vReal[SAMPLES]; double vImag[SAMPLES]; const int micPin = A0; void setup() { Serial.begin(9600); sampling_period_us = round(1000000 * (1.0 / SAMPLING_FREQUENCY)); } void loop() { /* Sample the microphone signal */ for (int i = 0; i < SAMPLES; i++) { microseconds = micros(); vReal[i] = analogRead(micPin); vImag[i] = 0; while (micros() < (microseconds + sampling_period_us)) { // wait } } /* Calculate FFT */ FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD); FFT.ComplexToMagnitude(vReal, vImag, SAMPLES); /* Print first 10 frequency components */ for (int i = 0; i < 10; i++) { Serial.print("Freq "); Serial.print((i * 1.0 * SAMPLING_FREQUENCY) / SAMPLES, 1); Serial.print(" Hz: "); Serial.println(vReal[i], 1); } delay(1000); // Adjust as needed }
analogReference()
function to set the ADC reference voltage closer to the signal level. For instance, using INTERNAL
for the $1.1\text{V}$ reference can help if the microphone's output voltage is low.ConclusionCpp
#include <Arduino.h> const int micPin = A0; const int numReadings = 10; void setup() { Serial.begin(9600); // Use the internal reference (1.1V on most Arduinos) analogReference(INTERNAL); } void loop() { long total = 0; for (int i = 0; i < numReadings; i++) { total += analogRead(micPin); delay(10); // Small delay between samples } // Calculate average int average = total / numReadings; Serial.println(average); delay(100); }
Image
Welcome 👋
Flux helps you build PCBs faster with an AI teammate!
To use this component and get started with Flux sign up now.