#include #define JDY_RX 2 #define JDY_TX 3 SoftwareSerial jdySerial(JDY_RX, JDY_TX); const byte numChars = 32; char receivedChars[numChars]; boolean newData = false; void setup() Serial.begin(9600); jdySerial.begin(9600); Serial.println("Receiver Ready. Waiting for data..."); void loop() receiveWithMarkers(); processNewData(); void receiveWithMarkers() static boolean recvInProgress = false; static byte ndx = 0; char startMarker = '<'; char endMarker = '>'; char rc; while (jdySerial.available() > 0 && newData == false) rc = jdySerial.read(); if (recvInProgress == true) if (rc != endMarker) receivedChars[ndx] = rc; ndx++; if (ndx >= numChars) ndx = numChars - 1; else receivedChars[ndx] = '\0'; // Terminate the string recvInProgress = false; ndx = 0; newData = true; else if (rc == startMarker) recvInProgress = true; void processNewData() if (newData == true) Serial.print("Raw Packet Received: "); Serial.println(receivedChars); // Parse the CSV data char *strtokIndx; strtokIndx = strtok(receivedChars, ","); // Skip the header label "DATA" if (strcmp(strtokIndx, "DATA") == 0) strtokIndx = strtok(NULL, ","); // Get the actual numeric payload int parsedValue = atoi(strtokIndx); Serial.print("Parsed Sensor Value: "); Serial.println(parsedValue); // Perform actions based on value (e.g., trigger alarm, update display) newData = false; Use code with caution. Advanced Architecture: Multi-Node Addressing
Configuration pin. Pull LOW for AT command mode; pull HIGH or leave disconnected for transparent communication mode.
This example turns your Arduino into a wireless extension cord for your PC’s serial monitor. You can type "LED_ON" on Computer A, and it turns on an LED on Computer B. jdy40 arduino example best
Because the JDY-40 operates on , connecting its RXD pin directly to a 5V Arduino (like the Uno or Nano) can damage the module or cause unstable behavior. Always use a logic level shifter or a simple resistor voltage divider on the Arduino's TX line. Hardware Connections: JDY-40 VCC →right arrow Arduino 3.3V JDY-40 GND →right arrow Arduino GND JDY-40 TXD →right arrow Arduino Pin 2 (Software RX) JDY-40 RXD →right arrow Through a voltage divider to Arduino Pin 3 (Software TX) Voltage divider tip: Connect Arduino Pin 3 to a 1k Ωcap omega
Note: For reliable operation, it is recommended to use to communicate with the JDY-40 to leave the hardware serial (pins 0 & 1) open for USB debugging. 3. The Best JDY-40 Arduino Example: Wireless Serial Bridge #include #define JDY_RX 2 #define JDY_TX 3 SoftwareSerial
This code listens for any data from the paired JDY-40 and prints it to the Serial Monitor.
To safely connect a 5V Arduino to a 3.3V JDY-40, you use a voltage divider on the Arduino's TX line going to the JDY-40's RX. A simple solution is a resistor divider: a 2.2kΩ resistor between the 5V TX pin and the JDY-40's RX pin, and a 3.3kΩ resistor from the JDY-40's RX pin to GND. Alternatively, use a dedicated logic level converter. Pull LOW for AT command mode; pull HIGH
Before writing code, understanding the hardware constraints ensures you do not damage your components.
Serial.println(F("--- JDY-40 Smart Bridge Started ---")); Serial.println(F("Type 'AT' to enter config mode (works only at 9600 baud)")); Serial.println(F("Type 'SETBAUD' to automatically set module to 115200")); Serial.println(F("-----------------------------------"));
| Command | Description | Example Response | |---------|-------------|------------------| | AT | Test communication | OK | | AT+VER | Get firmware version | +JDY-40-V2.2 | | AT+BAUD | Get current baud rate | +BAUD=9600 | | AT+BAUDx | Set baud rate (x = 1–8) | AT+BAUD4 → 9600 baud | | AT+RFID | Get current RF channel and ID | +RFID=CH001,ID001 | | AT+RFCHxxx | Set channel (xxx = 001–128) | AT+RFCH005 → channel 5 | | AT+RFIDxxx | Set node ID (xxx = 001–999) | AT+RFID123 → ID 123 | | AT+POWE | Get current TX power | +POWE=3 (max) |