In this article, we will make two Arduino control each other by turning off /on their built in LED using the RS-485 module
You will need the following items to carry out this project
Hardware
Software
- Latest Arduino IDE, get it here
Introducing the RS-485 module
The RS-485 module is a device that allows sending and receiving of data up to 1.2 km at a rate of 20 Mbps. It can support up to 32 devices. It runs off 5 volts meaning your Arduino can supply power to it.

IMPLEMENTATION
STEP 1: CIRCUIT CONNECTION
Below is the circuit diagram of the project.

STEP 2: UPLOAD THE CODE
1. Start your Arduino IDE and copy the following code into your Arduino IDE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include <SoftwareSerial.h> /*-----( Declare Constants and Pin Numbers )-----*/ #define SSerialRX 10 //Serial Receive pin #define SSerialTX 11 //Serial Transmit pin #define SSerialTxControl 3 //RS485 Direction control #define RS485Transmit HIGH #define RS485Receive LOW #define Pin13LED 13 /*-----( Declare objects )-----*/ SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX /*-----( Declare Variables )-----*/ int byteReceived; int byteSend; void <b>setup</b>() /****** SETUP: RUNS ONCE ******/ { // Start the built-in serial port, probably to Serial Monitor <b>Serial</b>.begin(9600); <b>Serial</b>.println("RS-485 EXAMPLE"); <b>Serial</b>.println("Use Serial Monitor, type Y/N to turn off/ON LED and press ENTER"); pinMode(Pin13LED, OUTPUT); pinMode(SSerialTxControl, OUTPUT); digitalWrite(Pin13LED, LOW); digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver // Start the software serial port, to another device RS485Serial.begin(9600); // set the data rate }//--(end setup )--- void <b>loop</b>() /****** LOOP: RUNS CONSTANTLY ******/ { if (<b>Serial</b>.available()) { byteReceived = <b>Serial</b>.read(); digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit RS485Serial.write(byteReceived); // Send byte to Remote Arduino delay(10); digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit } if (RS485Serial.available()) //Look for data from other Arduino { byteReceived = RS485Serial.read(); // Read received byte if (byteReceived == 'Y' || byteReceived == 'y') { digitalWrite(Pin13LED, HIGH); } else if (byteReceived == 'N' || byteReceived == 'n') { digitalWrite(Pin13LED, LOW); } <b> Serial</b>.write(byteReceived); // Show on Serial Monitor delay(10); digitalWrite(Pin13LED, LOW); // Show activity } } |
2. Click the upload button
(Note: Upload code to both Arduino)
3. Open your serial monitor and type Y or N to turn on/off the built in LED
Feel free to write any comments, thank you.
Wanna do more?
Build a Carbon Monoxide sensor with LCD display. Get the parts
Arduino & Microcontrollers

