Jdy40 Arduino Example Best -
Getting Started with JDY-40 Arduino Module: A Comprehensive Guide
The JDY-40 is a popular Bluetooth 4.0 module widely used in Arduino projects for wireless communication. It's a cost-effective and efficient way to add Bluetooth connectivity to your Arduino board. In this article, we'll explore the JDY-40 module, its features, and provide a step-by-step guide on how to use it with Arduino, along with some example code.
Overview of JDY-40 Module
The JDY-40 is a Bluetooth 4.0 module based on the CSR8510 chipset. It supports a wide range of Bluetooth protocols, including SPP (Serial Port Protocol), HID (Human Interface Device), and more. The module operates at a frequency of 2.4 GHz and has a maximum data transfer rate of 1 Mbps.
Key Features of JDY-40 Module:
- Bluetooth 4.0 version
- CSR8510 chipset
- Supports SPP, HID, and other protocols
- Frequency range: 2.4 GHz
- Maximum data transfer rate: 1 Mbps
- Low power consumption
- Small form factor (18mm x 15mm)
Hardware Requirements:
- JDY-40 Bluetooth module
- Arduino board (e.g., Arduino Uno, Arduino Nano)
- Breadboard and jumper wires
- Power source (e.g., USB cable, battery)
Software Requirements:
- Arduino IDE (version 1.8.x or later)
Step-by-Step Guide:
- Connect the JDY-40 Module to Arduino:
- VCC (JDY-40) to 5V (Arduino)
- GND (JDY-40) to GND (Arduino)
- RX (JDY-40) to TX (Arduino)
- TX (JDY-40) to RX (Arduino)
- Install the SoftwareSerial Library:
- Open the Arduino IDE and navigate to Sketch > Include Library > Manage Libraries
- Search for "SoftwareSerial" and install the library
- Upload the Example Code:
- Create a new Arduino project and paste the following code:
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3); // RX, TX
void setup()
Serial.begin(9600);
bluetooth.begin(9600);
void loop()
if (bluetooth.available() > 0)
char data = bluetooth.read();
Serial.print("Received: ");
Serial.println(data);
if (Serial.available() > 0)
char data = Serial.read();
bluetooth.print(data);
Explanation of the Code:
- The code uses the SoftwareSerial library to create a software serial port on pins 2 (RX) and 3 (TX).
- In the
setup()function, we initialize the serial communication at 9600 bps for both the serial monitor and the Bluetooth module. - In the
loop()function, we check if there's incoming data from the Bluetooth module or the serial monitor. If there is, we read the data and send it to the other device.
Example Use Cases:
- Wireless temperature monitoring
- Home automation control
- Robot control
Tips and Troubleshooting:
- Make sure to pair the JDY-40 module with your Bluetooth device before uploading the code.
- If you encounter issues with communication, try adjusting the baud rate or swapping the RX and TX pins.
- For more advanced applications, refer to the JDY-40 datasheet and the SoftwareSerial library documentation.
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!
The JDY-40 is a compact 2.4GHz wireless transceiver that functions like a wireless serial cable. It is widely used for Arduino projects due to its simplicity, low power consumption (5uA in sleep), and a range of up to 120 meters in open areas. 1. Essential Wiring
The JDY-40 is a 3.3V device. While its serial pins (RX/TX) are often tolerant to 5V Arduino logic, you must power it with 3.3V. JDY-40 Pin Arduino Pin Description VCC Power Supply (2.2V - 3.6V) GND RXD Pin 11 (SoftSerial TX) Serial input to module TXD Pin 10 (SoftSerial RX) Serial output from module SET Pin 9 (or GND for AT) Low (GND): AT Command mode; High: Data mode CS Low: Awake; High: Sleep mode 2. Best Code Example: Transparent Serial
The most common "best" use case is transparent transmission, where data sent to the RX pin of one module instantly appears at the TX pin of another.
#include Use code with caution. Copied to clipboard 3. Essential AT Configuration Commands jdy40 arduino example best
To configure the module, pull the SET pin to GND. All commands must end with \r\n (CR+LF).
AT+BAUD: Set the baud rate. Default is 4 (9600). Options range from 1 (1200) to 6 (19200).
AT+RFID: Sets the Wireless ID (0000 to FFFF). Both modules must have the same RFID to talk.
AT+DVID: Sets the Device ID. Useful for identifying specific nodes in a network.
AT+POWE: Adjusts transmit power (0 to 9). 9 is max (+12dBm).
AT+CLSS: Changes operating mode. A0 is standard transparent serial, while C0-C5 are for remote GPIO control. 4. Pro Tips for Better Reliability
Video #257: Serial Wireless Comms for Arduino (et al) - GitHub
JDY-040/JDY-041 module. JDY-040 module Serial Wireless transceiver info. PLEASE NOTE: this module is 3v3 limited - don't apply 5v.
Радиомодули JDY-40 2.4G с UART интерфейсом - arduinoLab
References
[1] JDY-40 Datasheet, Shenzhen Jiayida Electronic Co.
[2] Arduino SoftwareSerial Library Reference.
[3] “2.4 GHz Wireless Modules Comparison,” Embedded Lab, 2021.
Appendix – Full wiring diagram (available in source repository).
The Go to product viewer dialog for this item. is a versatile 2.4GHz wireless serial transceiver module popular for Arduino projects due to its low power consumption ( 40mA40 m cap A
sleep) and ease of use in point-to-point or broadcast networks. Unlike Bluetooth, it natively broadcasts to all nodes on the same channel and ID, making it ideal for simple telemetry and "one-to-many" communication. Core Specifications
Operating Voltage: 2.2V to 3.6V (3.3V recommended; do not use 5V directly). Communication: Standard TTL Serial (UART). Range: Up to 120 meters in open sight.
Modes: Transparent transmission (default) or AT command mode (for configuration). Connection Guide (Arduino Uno/Nano) Getting Started with JDY-40 Arduino Module: A Comprehensive
To interface with an Arduino, connect the pins as follows, ensuring you use a voltage divider or level shifter for the RX pin if using a 5V Arduino. Configuration with AT command - Arduino Forum
1. Executive Summary
The JDY-40 is a low-cost, ultra-low power wireless serial pass-through module based on the CC2541 chip. It is often preferred over the older HC-05/HC-06 Bluetooth modules because it supports both Bluetooth 4.0 (BLE) and standard serial transparency, and it requires no complex AT command pairing process for basic data transmission.
To get the "best" results, this report recommends using the module in Transparent Transmission Mode (Pass-through) with Hardware Serial where possible.
Pro Tip: Always pair addresses and channels
If you have multiple sets of JDY-40s nearby, change the channel and address:
Module A & B (must match):
AT+RFCH5
AT+ADDR1234
AT+DEFAULT (if something breaks)
Feature Proposal: "Smart Config & Link Monitor"
Description: A full-duplex communication bridge that allows the user to change the JDY-40 baud rate via Arduino code (removing the need for USB-to-TTL adapters for setup) and provides a "Heartbeat" signal quality indicator.
Why this is the "Best" approach:
- Solves the Baud Rate Trap: The JDY-40 ships at 9600 baud by default. If your project needs 115200, you usually need a separate USB adapter to configure it. This feature automates that configuration using Arduino commands.
- Debugging Visibility: Wireless modules often fail silently. This feature uses an LED to indicate if the link is active (Traffic) or dead (No Signal).
- Non-Blocking Code: Uses
millis()instead ofdelay(), ensuring no data is lost during transmission.
What You Need
- 2x Arduino Uno (or Nano/Pro Mini)
- 2x JDY-40 modules
- 2x Breadboards
- Jumper wires
- (Optional) 2x Logic level converters (if your Arduino is 5V)
The Code Implementation
This sketch sets up a "Pass-through" bridge. It checks for incoming configuration commands from the PC and relays all other data transparently.
/* * Title: JDY-40 Smart Bridge & Link Monitor * Description: The "Best" example to configure JDY-40 and monitor connection health. * * Circuit: * - JDY-40 TX -> Arduino Pin 2 * - JDY-40 RX -> Arduino Pin 3 * - Built-in LED (Pin 13) used for Link Status. */#include <SoftwareSerial.h>
// --- Configuration --- #define JDY_RX_PIN 2 // Connect to JDY-40 TX #define JDY_TX_PIN 3 // Connect to JDY-40 RX #define LED_PIN 13 // Status LED
// 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
SoftwareSerial jdySerial(JDY_RX_PIN, JDY_TX_PIN); // RX, TX
// Variables for Non-blocking LED Blink unsigned long lastReceiveTime = 0; const long linkTimeout = 1000; // If no data for 1s, consider link idle
// Feature Flag: Set to true once we configure the module bool isConfigured = false;
void setup() pinMode(LED_PIN, OUTPUT);
// Start PC Serial Serial.begin(PC_BAUD); while (!Serial) ; // Wait for port to connect
// Start JDY Serial at Default Factory Baud jdySerial.begin(JDY_DEFAULT_BAUD);
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("-----------------------------------"));
void loop() { // 1. Handle PC -> JDY-40 Traffic if (Serial.available()) { String command = Serial.readStringUntil('\n'); command.trim();
// FEATURE: Software Configuration Helper if (command ==
While there isn't a single "academic paper" that serves as the definitive guide, the following highly-regarded technical resources and tutorials are considered the best documentation for using the JDY-40 wireless module with Arduino. Best Technical Guides & Documentation
Detailed Setup and AT Commands: For a comprehensive technical overview, including how to configure the module via AT commands and its 128 radio channel options, refer to the Simple Wireless Serial Communication guide by Ben Emmett
. This resource is excellent for understanding current draw and power options.
Networking and Broadcast Examples: If you are looking to build a multi-node network (e.g., one hub and multiple remote nodes), Ben Emmett's JDY-40 Wireless Broadcast project provides complete Arduino and Python code examples using JSON formatting for message transmission.
Scientific Application: 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
Video Tutorials: Ralph Bacon’s video tutorial on Wireless Serial Comms and the accompanying GitHub repository
are highly recommended for beginners. These resources demonstrate how to use the Go to product viewer dialog for this item.
as a "wireless USB cable" for serial debugging and data transfer.
Datasheets: The JDY-40 Wireless Serial Module PDF on Scribd provides the essential hardware specifications, including its 120-meter transmission range and 2.4GHz operating frequency. Critical Usage Tips Voltage Limitation: Always remember that the Bluetooth 4
is a 3.3V limited device; applying 5V directly to the VCC or logic pins without a level shifter can damage the module.
Channel Interference: For stable communication between multiple links, it is best to separate their channels by at least 6 to avoid interference.