Example Code for Arduino-Manual Transmission Mode

Last revision 2025/12/10

This article presents a detailed guide on setting up and programming RS485 Shield for Arduino in manual transmission mode. It covers hardware and software preparation, wiring diagrams, and offers sample code to facilitate RS485 communication, emphasizing sending and receiving data using Arduino's serial monitor.

Hardware Preparation

Software Preparation

Wiring Diagram

DFR0259-Wiring Diagram

RS485 Shield Pin name USB to RS422/RS485 Cable Pin name
GND GND
A A
B B

Note: Downloading code, run / program mode switch must hit the OFF position, otherwise it will lead to the download fails. When downloaded,it is complete to ON, and the shield to normal use.

Sample Code

/*
# This sample codes is for testing the RS485 shiled(manual transmission mode).
# EN=2;
# Editor : YouYou
# Date   : 2013.9.16
# Ver    : 0.1
# Product: RS485 shield
# SKU    : DFR0259
*/
int led = 13;
int EN = 2;  //Definition RS485 shield enable terminal (the 2nd digital IO ports),
//high for the sending state, the low level of receiving state
void setup()
{
  Serial.begin(9600);
  pinMode(led,OUTPUT);
  pinMode(EN,OUTPUT);
}
void loop()
{
  int temp;
  digitalWrite(EN,LOW);    //Enable low, RS485 shield waiting to receive data
  if(Serial.available())
  {
    temp=Serial.read();
     if(temp=='V')
     {
      digitalWrite(led,1-digitalRead(led));
      digitalWrite(EN,HIGH);    //Enable high, RS485 shield waiting to transmit data
      Serial.println("OK");
      delay(10);    //Delay for some time, waiting for data transmitted
     }
  }
}

Result

Send characters "V" via the serial monitor of Arduino IDE, you can see the LED status change, and reply "OK".

Was this article helpful?

TOP