Jdy40 Arduino Example Best -
This comprehensive guide will walk you through the technical specifications, wiring configurations, AT command configurations, and provide the ultimate working code example for bidirectional communication. Technical Specifications & Pinout
// If wireless module receives data, send it to the computer (jdy40.available()) Serial.write(jdy40.read());
Mode Selection Pin (Pull LOW to enter AT command mode, pull HIGH/Floating for transparent transmission) Hardware Wiring Diagram
#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
This code reads data from the Serial Monitor and sends it wirelessly to any other JDY-40 on the same channel (must be in Transparent Mode).
The JDY-40's native "transparent transmission" is a broadcast: every module on the same frequency and network ID receives every message. In a multi-node setup, you need a way for the hub to talk to individual nodes without them all responding at once.
In the world of DIY electronics and IoT prototyping, Bluetooth and WiFi modules often steal the spotlight. However, when you need simple, low-power, and surprisingly long-range data transfer, the JDY-40 is a hidden gem. This comprehensive guide will walk you through the
Serial.println("Waiting for Bluetooth data...");
// Define RX (JDY-40 TX) and TX (JDY-40 RX) pins SoftwareSerial jdy40(2, 3); // RX = pin 2, TX = pin 3
The best example is the one that handles failure gracefully. Always validate your data. In a multi-node setup, you need a way
This setup uses pins 2 (RX) and 3 (TX) on the Uno via the SoftwareSerial library, preserving the default hardware serial for debugging.
Before writing code, it is essential to understand the pin layout and specifications of the JDY-40 module. Pin Configuration
: Program your Arduino nodes to ignore any message that does not match their specific ID. Hardware Setup :
Posting Komentar