Serial plotter can't dislpay analog signal

Hi,
i have problem with my ESP8266 serial plotter can't dislpay analog signal but the analog signal is normal. When i try in arduino uno it can be display but the analog signal not normal.
this is code in ESP8266

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Inisialisasi LCD pada alamat I2C 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int sensorPin = A0;         // Pin sensor suara (A0 pada ESP8266)
const int sampleWindow = 50;      // Window sampling dalam ms
unsigned int sample;

void setup() {
  lcd.init();                     // Inisialisasi LCD
  lcd.backlight();                // Menyalakan lampu latar
  lcd.setCursor(0, 0);
  lcd.print("Decibel Meter");     // Tampilkan teks awal
  delay(2000);
  lcd.clear();
  Serial.begin(115200);           // Serial monitor dengan baudrate 115200 untuk ESP8266
}

void loop() {
  unsigned long startMillis = millis(); // Waktu awal
  unsigned int signalMax = 0;           // Nilai sinyal maksimum
  unsigned int signalMin = 1023;        // Nilai sinyal minimum

  // Ambil data selama jendela waktu tertentu
  while (millis() - startMillis < sampleWindow) {
    sample = analogRead(sensorPin);
    if (sample < 1024) {
      if (sample > signalMax) {
        signalMax = sample; // Simpan nilai maksimum
      } else if (sample < signalMin) {
        signalMin = sample; // Simpan nilai minimum
      }
    }
  }

  // Hitung nilai peak-to-peak
  int peakToPeak = signalMax - signalMin;

  // Konversi ke desibel (kalibrasi sederhana)
  int dB = map(peakToPeak, 20, 900, 35, 70);

  // Tampilkan nilai di LCD
  lcd.setCursor(0, 0);
  lcd.print("Loudness: ");
  lcd.print(dB);
  lcd.print(" dB");

  lcd.setCursor(0, 1);
  if (dB >= 35 && dB <= 45) {
    lcd.print("Level: Tenang   ");
  } else if (dB >= 46 && dB <= 55) {
    lcd.print("Level: Sedang   ");
  } else if (dB >= 56 && dB <= 60) {
    lcd.print("Level: Bising   ");
  } else if (dB >= 61 && dB <= 90) {
    lcd.print("Level: Melampaui");
  } else {
    lcd.print("Level: Unknown  ");
  }

  // Debugging di Serial Monitor
  Serial.print("Peak-to-Peak: ");
  Serial.println(peakToPeak);
  Serial.print("Desibel: ");
  Serial.println(dB);

  delay(100); // Tunggu sebelum pembacaan berikutnya
}

this is code in Arduino UNO

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Inisialisasi LCD pada alamat I2C 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int sensorPin = A0;         // Pin sensor suara
const int sampleWindow = 50;      // Window sampling dalam ms
unsigned int sample;

void setup() {
  lcd.init();                     // Inisialisasi LCD
  lcd.backlight();                // Menyalakan lampu latar
  lcd.setCursor(0, 0);
  lcd.print("Decibel Meter");     // Tampilkan teks awal
  delay(2000);
  lcd.clear();
  Serial.begin(9600);             // Untuk debugging
}

void loop() {
  unsigned long startMillis = millis(); // Waktu awal
  unsigned int signalMax = 0;           // Nilai sinyal maksimum
  unsigned int signalMin = 1023;        // Nilai sinyal minimum

  // Ambil data selama jendela waktu tertentu
  while (millis() - startMillis < sampleWindow) {
    sample = analogRead(sensorPin);
    if (sample < 1024) {
      if (sample > signalMax) {
        signalMax = sample; // Simpan nilai maksimum
      } else if (sample < signalMin) {
        signalMin = sample; // Simpan nilai minimum
      }
    }
  }

  // Hitung nilai peak-to-peak
  int peakToPeak = signalMax - signalMin;

  // Konversi ke desibel (kalibrasi sederhana)
  int dB = map(peakToPeak, 20, 900, 35, 70);

  // Tampilkan nilai di LCD
  lcd.setCursor(0, 0);
  lcd.print("Loudness: ");
  lcd.print(dB);
  lcd.print(" dB");

  lcd.setCursor(0, 1);
  if (dB >= 35 && dB <= 45) {
    lcd.print("Level: Tenang   ");
  } else if (dB >= 46 && dB <= 55) {
    lcd.print("Level: Sedang   ");
  } else if (dB >= 56 && dB <= 60) {
    lcd.print("Level: Bising   ");
  } else if (dB >= 61 && dB <= 90) {
    lcd.print("Level: Melampaui");
  } else {
    lcd.print("Level: Unknown  ");
  }

  // Debugging di Serial Monitor
  Serial.print("Peak-to-Peak: ");
  Serial.println(peakToPeak);
  Serial.print("Desibel: ");
  Serial.println(dB);

  delay(500); // Tunggu sebelum pembacaan berikutnya
}

Hello
Welcome to the forum.
It would be helpful for everyone if you could provide information about the board you are using. My friend faced a similar issue and solved it by selecting the correct board.
Some other trouble shooting steps:
Add the additional URL for using ESP32.
Download the required drivers for using ESP boards
Close serial plotter, restart arduino and try again.

If the issue persists do get back to the forum

I use Nodemcu LOLIN esp8266 with CH340C chipset. but when I bought it, the sales description said it uses IFT232. I installed the CH340 driver cause I can't found FT232

I don't know why you are having problems with your ESP8266, but I do see a problem with your Uno code.

You use:

Serial.print("Peak-to-Peak: ");
Serial.println(peakToPeak);
Serial.print("Desibel: ");
Serial.println(dB);

When displayed on the Serial Monitor this puts 'peakToPeak' and 'dB' on two separate lines.

However when used with the Serial Plotter, this causes both 'peakToPeak' and 'dB' to be plotted on the same trace. (That is why the plot alternates between a high and a low value.)

Try changing to:

  Serial.print("Peak-to-Peak: ");
  Serial.print(peakToPeak);
  Serial.print(", Desibel: ");
  Serial.println(dB);`

So that using Serial Monitor, the printing will be all on one line, but using Serial Plotter, the two variables 'peakToPeak' and 'dB' will now be plotted with each having it's own separate trace.

I don't know whether the same issue is causing your ESP8266 problems, as I don't have an ESP8266 to do tests on.

maybe this is why its not "normal"

How are you converting your peak to peak value to dB?

From this image I can see that the serial monitor is active but only the serial plotter isnt receiving any data. This may be possible due to the fact that 2 variables are being introduced. Also could you share a clear pic of the esp2866
Another thing to try is to start of simple and plot only one variable.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.