กลับหน้าหลัก
views
Using ESP8266 with RS485 Vibration Sensor SN-3001-WZ-N01
Last updated on

Using ESP8266 with RS485 Vibration Sensor SN-3001-WZ-N01


Using ESP8266 with RS485 Vibration Sensor SN-3001-WZ-N01

This guide walks through wiring and coding ESP8266 (NodeMCU) to read vibration frequency from the SN-3001-WZ-N01 sensor using the RS485 protocol, displaying results on both Arduino IDE Serial Monitor and OLED screen.

Required Components

  • NodeMCU ESP8266 V2 board (CP2102 chip)
  • RS485 Vibration Sensor model SN-3001-WZ-N01
  • MAX485 RS485 to TTL Module
  • 0.96 inch OLED 128x64 I2C Display
  • Jumper wires (Male-Male, Male-Female, Female-Female)
  • 830 point Breadboard
  • 12V 5A Power Adapter with DC Jack 5.5x2.1mm
  • Micro USB cable for ESP8266 programming

How It Works

The SN-3001-WZ-N01 sensor measures vibration frequency in the 10-1600Hz range and transmits data via RS485, an industrial standard that supports long-distance communication with excellent electrical noise resistance. The MAX485 board converts RS485 signals to TTL that ESP8266 can read.

Photo showing all components laid out on a workbench - ESP8266, MAX485, sensor, and OLED ready for assembly

Wiring Diagram

Step 1: Connect ESP8266 to MAX485 Module

ESP8266MAX485
Vin (5V)VCC
GNDGND
D7 (GPIO13)RO (Receiver Output)
D4 (GPIO2)DI (Driver Input)
D6 (GPIO12)DE (Driver Enable)
D5 (GPIO14)RE (Receiver Enable)

Step 2: Connect SN-3001-WZ-N01 Sensor to MAX485

SN-3001-WZ-N01Wire ColorMAX485
Pin BBlue wireB
Pin AYellow wireA

Step 3: Connect 12V Power to Sensor

SN-3001-WZ-N01Wire ColorPower Supply
Positive (+)Brown wire12V+
Negative (-)Black wire12V-

Step 4: Connect ESP8266 to OLED (I2C)

ESP8266OLED
Vin (5V)VCC
GNDGND
D2 (GPIO4)SDA
D1 (GPIO5)SCL
Complete circuit diagram showing all wire connections between ESP8266, MAX485, sensor, and OLED on breadboard

Important Note: All GND pins (ESP8266, MAX485) must be connected together (Common Ground) to ensure consistent signal reference.

Installing Libraries

  1. Download the Library pack from MediaFire (OLED and SoftwareSerial)
  2. Extract files using WinRAR or WinZip
  3. Copy the Library folders to Documents/Arduino/libraries

If you haven’t installed Arduino libraries before, check our “Arduino Library Installation Guide” article for detailed instructions.

Arduino Code for ESP8266

#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


// Define pins for SoftwareSerial RS485
#define RS485_RX_PIN D7    // RO (Receiver Output)
#define RS485_TX_PIN D4    // DI (Driver Input)
#define RS485_DE_PIN D6    // DE (Driver Enable)
#define RS485_RE_PIN D5    // RE (Receiver Enable)

// Define pins for OLED
#define OLED_SDA D2
#define OLED_SCL D1

// Create SoftwareSerial object for RS485
SoftwareSerial rs485(RS485_RX_PIN, RS485_TX_PIN);

// Create OLED object
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  // Start Serial for Debug
  Serial.begin(9600);
  
  // Start SoftwareSerial for RS485 (4800 baud per sensor spec)
  rs485.begin(4800);
  
  // Set DE and RE pins as Output
  pinMode(RS485_DE_PIN, OUTPUT);
  pinMode(RS485_RE_PIN, OUTPUT);
  
  // Set RS485 to Receive mode
  digitalWrite(RS485_DE_PIN, LOW);
  digitalWrite(RS485_RE_PIN, LOW);
  
  // Initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("OLED allocation failed"));
    for(;;);
  }
  
  // Clear OLED screen
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Vibration");
  display.println("Sensor OK");
  display.display();
  
  delay(2000);
}

void loop() {
  // Wait for data from RS485
  if (rs485.available()) {
    String data = rs485.readStringUntil('\n');
    
    // Display on Serial Monitor
    Serial.print("Freq: ");
    Serial.println(data);
    
    // Display on OLED
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    display.println("Freq (Hz):");
    display.setTextSize(3);
    display.println(data);
    display.display();
  }
  
  delay(100);
}

Points to adjust: If your sensor outputs data in a different format, such as with prefix or suffix characters, you may need to modify the String parsing logic in the loop() function accordingly.

Uploading the Code

  1. Open Arduino IDE and connect the board
  2. Select Board: NodeMCU 1.0 (ESP-12E Module)
  3. Select the correct COM Port
  4. Click the Upload button
  5. Wait for “Done Uploading” message
  6. Open Serial Monitor and change Baud Rate to 4800

Testing

After uploading the code, the Serial Monitor and OLED screen will display vibration values detected by the sensor. If no vibration is present, the reading will show approximately 0.000000 Hz.

To test, generate vibration by tapping or knocking on the surface where the sensor is mounted. The frequency reading will change according to the vibration applied.

Screenshot showing test results on Serial Monitor and OLED when vibration is applied, with frequency values displayed on both screens

Reference Video

https://www.youtube.com/embed/AwJs5O2e-Hc

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

ความคิดเห็น

Verified user reviews

รีวิวและความคิดเห็นจากผู้ใช้จริง

ล็อกอินด้วยบัญชีบนเว็บนี้แล้วให้คะแนนหรือคอมเมนต์ได้เลย ระบบเก็บผ่าน Supabase ไม่ต้องใช้ GitHub แล้ว

กำลังโหลดรีวิว...