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.
Wiring Diagram
Step 1: Connect ESP8266 to MAX485 Module
| ESP8266 | MAX485 |
|---|---|
| Vin (5V) | VCC |
| GND | GND |
| 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-N01 | Wire Color | MAX485 |
|---|---|---|
| Pin B | Blue wire | B |
| Pin A | Yellow wire | A |
Step 3: Connect 12V Power to Sensor
| SN-3001-WZ-N01 | Wire Color | Power Supply |
|---|---|---|
| Positive (+) | Brown wire | 12V+ |
| Negative (-) | Black wire | 12V- |
Step 4: Connect ESP8266 to OLED (I2C)
| ESP8266 | OLED |
|---|---|
| Vin (5V) | VCC |
| GND | GND |
| D2 (GPIO4) | SDA |
| D1 (GPIO5) | SCL |
Important Note: All GND pins (ESP8266, MAX485) must be connected together (Common Ground) to ensure consistent signal reference.
Installing Libraries
- Download the Library pack from MediaFire (OLED and SoftwareSerial)
- Extract files using WinRAR or WinZip
- 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
- Open Arduino IDE and connect the board
- Select Board: NodeMCU 1.0 (ESP-12E Module)
- Select the correct COM Port
- Click the Upload button
- Wait for “Done Uploading” message
- 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.
Reference Video
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย