// Define pins for SoftwareSerial (RX, TX) SoftwareSerial jdy(2, 3); // RX = 2 (connect to JDY-40 TX), TX = 3 (connect to JDY-40 RX via divider)
For this example, you need two Arduino boards (Uno/Nano/Mega) and two JDY-40 modules.
SoftwareSerial bluetooth(2, 3); // RX, TX jdy-40 arduino example
void loop() if (bluetooth.available() > 0) char data = bluetooth.read(); Serial.print("Received: "); Serial.println(data); bluetooth.print("Hello from Arduino!");
Why SoftwareSerial? The hardware serial pins (0,1) interfere with USB uploading. Using SoftwareSerial allows us to upload code without unplugging the modules. // Define pins for SoftwareSerial (RX, TX) SoftwareSerial
The JDY-40 is a Bluetooth 4.0 module that uses the UART (Universal Asynchronous Receiver-Transmitter) protocol for communication. It has a maximum data transfer rate of 1 Mbps and a range of up to 30 meters. The module is powered by a voltage range of 3.3V to 5V, making it compatible with most Arduino boards.
void setup() Serial.begin(9600); bluetooth.begin(9600); Using SoftwareSerial allows us to upload code without
This example sends the reading of a potentiometer (or random data) from the Transmitter to the Receiver, which displays it on the Serial Monitor.
Serial.println("JDY-40 Transmitter Ready"); delay(100);