Issue reading serial output ESP8266 nodemcu v3

Hello,

I have a ESP8266 nodemcu v3 with a AJ-SR04M connector attached.
I am having issue to read any serial output in the Arduino IDE on different baud rates.

This is the sketch:

#define echoPin 11 // attach pin D2 Arduino to pin Echo of JSN-SR04T
#define trigPin 12 //attach pin D3 Arduino to pin Trig of JSN-SR04T

// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  Serial.begin(74880); // // Serial Communication is starting with 9600 of baud rate speed
  Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
  Serial.println("with Arduino UNO R3");
}
void loop() {
  // Clears the trigPin condition
  digitalWrite(trigPin, LOW);  //
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  // Displays the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");// working  code for aj-sr04m
}

Serial monitor is set on the same baud rate (74880) and seeing following output:
rf[112] : 0��@q|!5�P��X�(~Q�sYI�"8�t�e/����T����DP@�����nzA )i~�#D!yu�R���)DP���1 �N|��)�~�Pza�~�PZ�P���1/Q"�rf cal sector: 1020

I have tried multiple baud rate both Serial.input as the serial monitor but doesn't help.

Any advice?

Thank you!

don't use pins 6 to 11

Thanks for your response.
I am using pin D2 and D3?

^^^

Thanks for trying to use code tags. When clicking the <CODE/> button above the composer window you will basically see the below

image

Your are supposed to overwrite the highlighted text with your code

I've fixed it for you.

Change it to gpio 12 and gpio 14 - works like a charm now...

Thanks for your help

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