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

Reading RS485 Vibration Sensor SN-3001-WZ-N01 with Arduino


Reading RS485 Vibration Sensor SN-3001-WZ-N01 with Arduino

This guide walks you through wiring the SN-3001-WZ-N01 RS485 vibration sensor to an Arduino UNO R3 using a MAX485 breakout module, and writing code to read and display vibration data on both the Serial Monitor and an OLED screen.

Complete circuit diagram showing connections between Arduino UNO, MAX485 module, SN-3001-WZ-N01 sensor, OLED display, and 12V power supply

Required Components

  • Arduino UNO R3 with USB cable
  • SN-3001-WZ-N01 RS485 vibration sensor (10-1600Hz, magnetic mount)
  • MAX485 TTL-to-RS485 breakout module
  • OLED 128×64 I2C display, 0.96 inch
  • MB-102 Breadboard
  • Jumper wires (M-M, M-F, F-F)
  • 12V 5A DC adapter with 5.5×2.5mm jack
  • (Optional) 9V 2A adapter for Arduino power

Wiring the Circuit

1. Connect MAX485 to Arduino UNO

Arduino UNOMAX485
5VVCC
GNDGND
2 (RX)RO
3 (TX)DI
7DE
8RE
Detailed close-up of Arduino-to-MAX485 wiring with labeled pins

2. Connect Sensor to MAX485

SN-3001-WZ-N01MAX485
B (Blue wire)B
A (Yellow wire)A

3. Power the Sensor with 12V DC

SN-3001-WZ-N0112V Supply
Brown wire (V+)12V+
Black wire (V-)GND

4. Connect OLED Display to Arduino

Arduino UNOOLED (I2C)
5VVCC
GNDGND
A4 (SDA)SDA
A5 (SCL)SCL
OLED display connection diagram highlighting SDA and SCL lines on Arduino

Critical: All GND points (Arduino, MAX485, and the 12V supply) must be tied together at a common ground. Without a shared ground reference, the RS485 communication will fail to read data correctly.


Installing the Required Libraries

  1. Download the library package (OLED and SoftwareSerial) from MediaFire
  2. Extract the files using WinRAR or WinZIP
  3. Move the extracted folders to Documents/Arduino/libraries/
  4. Restart the Arduino IDE

Arduino Code

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

// RS485 communication pins
#define RS485_RX  2
#define RS485_TX  3
#define RS485_DE  7  // Driver Enable pin
#define RS485_RE  8  // Receiver Enable pin

// OLED display settings
#define OLED_SCREEN_WIDTH 128
#define OLED_SCREEN_HEIGHT 64
#define OLED_RESET -1

// Create SoftwareSerial instance for RS485
SoftwareSerial rs485(RS485_RX, RS485_TX);

// Create OLED display instance
Adafruit_SSD1306 display(OLED_SCREEN_WIDTH, OLED_SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  // Configure DE/RE pins as outputs
  pinMode(RS485_DE, OUTPUT);
  pinMode(RS485_RE, OUTPUT);

  // Start in receive mode: DE=LOW, RE=LOW
  digitalWrite(RS485_DE, LOW);
  digitalWrite(RS485_RE, LOW);

  // Start hardware serial for debugging
  Serial.begin(9600);

  // Start software serial for RS485 at 9600 baud
  rs485.begin(9600);

  // Initialize OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("OLED init failed"));
    for (;;);
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.display();

  Serial.println("RS485 Vibration Sensor Ready");
}

void loop() {
  // --- Send read command to sensor via Modbus RTU ---
  // Note: adjust the command below to match your sensor's datasheet
  digitalWrite(RS485_DE, HIGH);  // Enable transmitter
  digitalWrite(RS485_RE, HIGH);

  // Example: Read 10 Holding Registers starting at 0x0000
  byte request[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x0A, 0xC5, 0xCD};
  rs485.write(request, sizeof(request));
  delay(10);

  digitalWrite(RS485_DE, LOW);  // Return to receive mode
  digitalWrite(RS485_RE, LOW);

  // --- Wait for and read response ---
  delay(500);  // Allow sensor to process

  if (rs485.available()) {
    byte response[64];
    int len = 0;
    while (rs485.available() && len < 64) {
      response[len++] = rs485.read();
    }

    // Print raw data to Serial Monitor for debugging
    Serial.print("Raw Data: ");
    for (int i = 0; i < len; i++) {
      Serial.print(response[i], HEX);
      Serial.print(" ");
    }
    Serial.println();

    // --- Decode data according to sensor protocol ---
    // Note: adjust register offsets and data types per actual sensor manual
    if (len >= 23) {
      // Example: extract vibration and temperature values from response
      // Actual register positions depend on sensor datasheet
      int16_t vibration = (response[9] << 8) | response[10];
      int16_t temperature = (response[11] << 8) | response[12];

      // Display on Serial Monitor
      Serial.print("Vibration: ");
      Serial.print(vibration);
      Serial.print(" | Temp: ");
      Serial.print(temperature / 10.0);
      Serial.println(" C");

      // Display on OLED
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("Vibration Sensor");
      display.print("Freq: ");
      display.print(vibration);
      display.println(" Hz");
      display.print("Temp: ");
      display.print(temperature / 10.0);
      display.println(" C");
      display.display();
    }
  }

  delay(1000);  // Wait before next read cycle
}

Note: This is a skeleton sketch designed for reading Modbus RTU data from generic RS485 sensors. The register addresses, data offsets, and scaling factors must be adjusted according to the actual datasheet of the SN-3001-WZ-N01. If the values look incorrect, check the raw hex data in the Serial Monitor and verify against your sensor’s documentation.


Upload and Test Procedure

  1. Open Arduino IDE and paste the code above
  2. Select Board: Tools → Board → Arduino UNO
  3. Select Port: Tools → Port → COM (check in Device Manager)
  4. Click Upload
  5. Wait for “Done Uploading”
  6. Open Serial Monitor and set baud rate to 9600
  7. Connect the 12V power supply to the sensor
  8. Watch for vibration and temperature values on both the Serial Monitor and OLED screen

[image: Serial Monitor displaying vibration sensor readings with raw hex data visible]


Practical Test with a Hair Dryer

After uploading the sketch, try using a hair dryer to blow warm air near the sensor. You should observe:

  • Temperature readings increase as warm air reaches the sensor
  • Vibration values fluctuate as the motor’s vibrations propagate through the air

This quick test confirms the circuit is wired correctly and the sensor is functioning as expected.


Reference Video

https://www.youtube.com/embed/CpE6WYol3c8

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

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

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

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

ความคิดเห็น