Jdy40 Arduino Example Best Best
This transmitter code reads a sensor value (simulated via an analog pin) and packs it into a structured, delimited string format. Sending data with start and end markers prevents packet fragmentation issues over the air.
Mastering the JDY-40 Wireless Module with Arduino: A Complete Guide
Disconnect the SET pin from pin 4 or alter the code below to drive the SET pin to switch from AT mode to Transparent Wireless Mode. Unit A: Sensor Sender & LED Controller
To get the best performance out of your JDY-40, follow this standard serial setup: jdy40 arduino example best
When testing with separate battery packs or distinct USB ports on different computers, ensure a physical wire links the GND lines of both Arduinos together. Without a shared reference ground, the TTL logic levels will misinterpret incoming data bits. Conclusion
#include SoftwareSerial jdySerial(2, 3); // RX, TX void setup() Serial.begin(9600); jdySerial.begin(9600); Serial.println("JDY-40 AT Command Mode Ready."); void loop() if (jdySerial.available()) Serial.write(jdySerial.read()); if (Serial.available()) jdySerial.write(Serial.read()); Use code with caution. Essential AT Commands for Pairing
By following this guide, you should now have a better understanding of how to use the JDY-40 Bluetooth module with Arduino. Experiment with different projects and explore the possibilities of wireless communication with your Arduino board. Happy building! This transmitter code reads a sensor value (simulated
This sketch listens for incoming serial data from the JDY-40, parses the packet using start and end markers, and outputs the isolated integer to the serial monitor.
| Command | Function | | :--- | :--- | | AT | Test communication | | AT+VERSION | Get firmware version | | AT+DEFAULT | Reset to factory | | AT+BAUD4 | Set baud to 9600 (4=9600, 5=19200, etc.) | | AT+RFCH0 | Set channel (0-19) – use same on both | | AT+ADDR0001 | Set address (0001-FFFF) – use same on both |
This comprehensive guide covers everything you need to know to build a robust wireless link using the JDY-40 and Arduino, complete with wiring diagrams, AT command configuration, and a production-ready code example. Technical Specifications & Pinout Unit A: Sensor Sender & LED Controller To
: For a look at how the JDY-40 is used in professional research, the peer-reviewed paper "Wireless Data Acquisition System with Feedback Function" in MDPI details its integration into a data acquisition sensor, highlighting its 3.3V power requirements and energy-efficient sleep modes. Practical Implementation Resources
are highly recommended for beginners. These resources demonstrate how to use the Go to product viewer dialog for this item.
// Baud Rates const long PC_BAUD = 115200; // Speed for Serial Monitor const long JDY_DEFAULT_BAUD = 9600; // Factory default const long JDY_TARGET_BAUD = 115200; // Desired speed for project
#include const int RX_PIN = 2; const int TX_PIN = 3; const int SET_PIN = 4; SoftwareSerial jdyRadio(RX_PIN, TX_PIN); unsigned long lastCommandTime = 0; const unsigned long commandInterval = 5000; // Toggle remote LED every 5 seconds bool toggleState = false; void setup() pinMode(SET_PIN, OUTPUT); digitalWrite(SET_PIN, HIGH); // Transparent Data Mode Serial.begin(9600); jdyRadio.begin(9600); Serial.println("Unit B Initialized."); void loop() unsigned long currentMillis = millis(); // Send control commands every 5 seconds if (currentMillis - lastCommandTime >= commandInterval) lastCommandTime = currentMillis; toggleState = !toggleState; if (toggleState) jdyRadio.println(" "); Serial.println("Dispatched Command: LED ON"); else jdyRadio.println(" "); Serial.println("Dispatched Command: LED OFF"); // Handle incoming data strings from Unit A 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'; recvInProgress = false; ndx = 0; parseSensorData(receivedChars); else if (rc == startMarker) recvInProgress = true; void parseSensorData(char* data) // Parsing a structured string like "DATA:104" if (strncmp(data, "DATA:", 5) == 0) char* valuePtr = data + 5; // Move pointer past "DATA:" int sensorValue = atoi(valuePtr); // Convert payload string to integer Serial.print("Telemetry Processed -> Sensor Reading: "); Serial.println(sensorValue); Use code with caution. Troubleshooting Common Implementation Errors
Here is the wiring for two common configurations.