Great idea! Do you know any code for this?Assuming the Esp32 A/D conversion rate is at least 100k samples/sec. you can just rapidly sample the 1kHz signal and look for the peak signal in each of the samples over the 1kHz period.
Eu preciso usar o amostrador e criar este sinal ou apenas um dos dois?You need to create a signal when the peak occurs so ESP knows exact time when to trig an ADC.
This signal can be made from precisely calculated RC differentiator. The edge before peak seems to be very sharp so you can use just RC with very short time constant.
There is also possible to use a comparator like LM393 with reference set to about 1/2 of smallest peak. After comparator signal rise delay the ADC start so you sample in the middle of peak.
Btw, there is no need a rectifier. Just use a small RC low pass so peaks become flat a little to measure. If you need to measure positive and negative peaks also shift the Gnd to Adc/2.
If the negative is no needed clamp it with diode.
Thank you so much for giving the awesome idea!Assuming the Esp32 A/D conversion rate is at least 100k samples/sec. you can just rapidly sample the 1kHz signal and look for the peak signal in each of the samples over the 1kHz period.

//Função para pulsar os LEDs
void gera_onda_quadrada(int pin_LED, int pin_fotodiodo, int pin_transistor) {
float tensao;
unsigned long inicio_loop;
const unsigned long periodo = 500;
float soma_tensao = 0.0;
pinMode(pin_LED, OUTPUT);
pinMode(pin_transistor, OUTPUT);
pinMode(pin_fotodiodo, INPUT);
for (int i = 0; i < 128; i++) {
inicio_loop = micros();
digitalWrite(pin_LED, HIGH);
// Aguarda até que o período definido se passe
while(micros() - inicio_loop < periodo){
}
// Desliga o LED após o período definido
digitalWrite(pin_LED, LOW);
delayMicroseconds(10);
valor_adc = analogRead(pin_fotodiodo);
digitalWrite(pin_transistor, HIGH);
soma_tensao += valor_adc;
digitalWrite(pin_transistor, LOW);
// Aguarda o restante do período
while(micros() - inicio_loop < 2 * periodo){
}
}
tensao = (soma_tensao * 3.3) / 4095; // Converte o valor ADC em tensão
float media_tensoes = tensao / 128;
Serial.print("Tensão medida: ");
Serial.println(media_tensoes);
}
void setup() {
Serial.begin(9600); //Para comunicação USB
//lerArquivo(); //Quando for descarregar os dados é necessário habilitar esta linha
}
void loop() {
// Gera 128 pulsos de 1 kHz no pino 19 que alimenta o circuito NIR, lê a tensão medida pelo fotodiodo e descarrega o capacitor
gera_onda_quadrada(19, 34, 22);
// Gera 128 pulsos de 1 kHz no pino 23 que alimenta o circuito RED, lê a tensão medida pelo fotodiodo e descarrega o capacitor
gera_onda_quadrada(23, 34, 22);
delay(2000);
}