Jdy40 Arduino Example Best: [updated]
Use code with caution. Copied to clipboard 4. Advanced Networking: Multi-Node Broadcast
#include const int RX_PIN = 2; const int TX_PIN = 3; const int SET_PIN = 4; const int LED_PIN = 13; SoftwareSerial jdyRadio(RX_PIN, TX_PIN); unsigned long lastTxTime = 0; const unsigned long txInterval = 2000; // Send data every 2 seconds int simulatedSensorReading = 100; void setup() pinMode(SET_PIN, OUTPUT); digitalWrite(SET_PIN, HIGH); // Set to High for Transparent Data Mode pinMode(LED_PIN, OUTPUT); Serial.begin(9600); jdyRadio.begin(9600); Serial.println("Unit A Initialized."); void loop() unsigned long currentMillis = millis(); // Non-blocking loop for sending data if (currentMillis - lastTxTime >= txInterval) lastTxTime = currentMillis; simulatedSensorReading += random(-5, 6); // Simulate sensor drift // Package data cleanly with start and end markers jdyRadio.print(" "); Serial.print("Sent to Unit B: "); Serial.println(simulatedSensorReading); // Read incoming data from Unit B recvWithStartEndMarkers(); void recvWithStartEndMarkers() static boolean recvInProgress = false; static byte ndx = 0; char startMarker = '<'; char endMarker = '>'; const byte numChars = 32; static char receivedChars[numChars]; while (jdyRadio.available() > 0) char rc = jdyRadio.read(); if (recvInProgress == true) if (rc != endMarker) if (ndx < numChars - 1) receivedChars[ndx] = rc; ndx++; else receivedChars[ndx] = '\0'; // Terminate string recvInProgress = false; ndx = 0; processIncomingCommand(receivedChars); else if (rc == startMarker) recvInProgress = true; void processIncomingCommand(char* data) Serial.print("Received Raw Packet: "); Serial.println(data); // Example command layout parsing "LED:ON" or "LED:OFF" if (strcmp(data, "LED:ON") == 0) digitalWrite(LED_PIN, HIGH); Serial.println("Action: Built-in LED turned ON"); else if (strcmp(data, "LED:OFF") == 0) digitalWrite(LED_PIN, LOW); Serial.println("Action: Built-in LED turned OFF"); Use code with caution. Unit B: Central Processor & Command Dispatcher jdy40 arduino example best
By using structured packet markers ( < and > ) paired with non-blocking code structures, the JDY-40 transforms from a simple cheap chip into a robust industrial-style data pipeline. It bypasses the overhead of standard Bluetooth pairing sequences and avoids the power tax of Wi-Fi setups, serving as an exceptional baseline component for your next IoT telemetry network. Use code with caution
: 15mA in transmission, sub-microamps in sleep mode Wiring the JDY-40 to Arduino It bypasses the overhead of standard Bluetooth pairing
Always double-check your wiring. While the JDY-40 is forgiving, 5V logic can damage it over time. Use a level shifter for production projects.

