Jdy40 Arduino Example Best ^new^ Jun 2026
To enter :
#include SoftwareSerial jdySerial(2, 3); // RX, TX const int ledPin = 13; const byte numChars = 32; char receivedChars[numChars]; boolean newData = false; void setup() jdySerial.begin(9600); Serial.begin(9600); pinMode(ledPin, OUTPUT); void loop() receiveWithMarkers(); processNewData(); // Robust parsing algorithm using start/end markers 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 string recvInProgress = false; ndx = 0; newData = true; else if (rc == startMarker) recvInProgress = true; void processNewData() if (newData == true) int targetValue = atoi(receivedChars); // Convert string to integer Serial.print("Data Received: "); Serial.println(targetValue); // Action: Turn on LED if sensor value exceeds threshold if (targetValue > 512) digitalWrite(ledPin, HIGH); else digitalWrite(ledPin, LOW); newData = false; Use code with caution. Troubleshooting & Best Practices
This example allows you to type in the Serial Monitor of Arduino A and see it appear in the Serial Monitor of Arduino B, and vice versa. Sketch for Both Devices (Master and Slave) jdy40 arduino example best
Upload the following configuration sketch to your Arduino. Use this code to configure Module A as the Master and Module B as the Slave.
bool sendCommand(String cmd) jdy40.println(cmd); unsigned long timeout = millis() + 500; while (millis() < timeout) if (jdy40.find("ACK")) return true; To enter : #include SoftwareSerial jdySerial(2, 3); //
/* * JDY-40 AT Command Configurator * This sketch sets the module to channel 5, ID 1, and queries the version. * Connect SET to pin 2, CS to pin 3, and the serial lines to RX/TX. */
The HC‑05 is a module that uses the Serial Port Profile (SPP). It is great for communicating with smartphones and PCs, but you must go through a pairing procedure, and its range is limited to about 10 metres. The JDY‑40, on the other hand, works like a wireless serial cable – two modules set to the same channel and ID immediately exchange data. This makes it far simpler for Arduino‑to‑Arduino links, especially when you need longer range or lower power consumption. Use this code to configure Module A as
To get the best performance out of your JDY-40, follow this standard serial setup:
The JDY-40 is a 2.4GHz wireless transceiver module with a built-in microcontroller. Its superpower? You just send data via Serial (UART), and the other module receives it.
