Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- To use the JDY-23 Bluetooth 5 Module with an Arduino, you can connect it via the serial interface (TX, RX). Here's an example code that sends several AT commands to test the JDY-23 Bluetooth module. This code sends the AT commands automatically one after another, with a delay between each command.
- Hardware Requirements:
- JDY-23 Bluetooth 5 Module
- Arduino board (e.g., Arduino Uno)
- Jumper wires
- Connection:
- Connect the JDY-23 Bluetooth 5 Module to the Arduino as follows:
- VCC pin of the JDY-23 to the 3.3V pin on the Arduino
- GND pin of the JDY-23 to a GND pin on the Arduino
- TX pin of the JDY-23 to the RX pin on the Arduino (Digital pin 0)
- RX pin of the JDY-23 to the TX pin on the Arduino (Digital pin 1)
- Note: It is recommended to use software serial for communication with the JDY-23 module so that the hardware serial pins can be used for debugging and communication with the Serial Monitor.
- This code sends AT commands one by one with a delay of 2 seconds (2000 ms) between each command. The AT commands sent are AT+VER, AT+MAC, AT+NAME, AT+BAUD, and AT+POWR. The responses from the JDY-23 module will be displayed on the Serial Monitor.
- Please note that this code is designed to send AT commands automatically in a sequence
- Code:
- */
- #include <SoftwareSerial.h>
- // JDY-23 module connected to pins 2 and 3 on the Arduino
- const int jdy23_rx = 2;
- const int jdy23_tx = 3;
- // Create a SoftwareSerial instance
- SoftwareSerial jdy23Serial(jdy23_rx, jdy23_tx);
- // Array of AT commands to test
- const char* atCommands[] = {
- "AT+VER",
- "AT+MAC",
- "AT+NAME",
- "AT+BAUD",
- "AT+POWR"
- };
- const unsigned long commandDelay = 2000; // Time delay between AT commands (milliseconds)
- unsigned long lastCommandTime = 0;
- int commandIndex = 0;
- void setup() {
- // Open the hardware serial port for debugging
- Serial.begin(9600);
- // Open the software serial port for communication with the JDY-23 module
- jdy23Serial.begin(9600);
- Serial.println("JDY-23 Bluetooth Module AT Command Test");
- }
- void loop() {
- // Read data from the JDY-23 module and print it to the Serial Monitor
- if (jdy23Serial.available()) {
- char received = (char)jdy23Serial.read();
- Serial.print(received);
- }
- // Send AT commands to the JDY-23 module with a delay between commands
- if (millis() - lastCommandTime > commandDelay) {
- if (commandIndex < (sizeof(atCommands) / sizeof(atCommands[0]))) {
- // Send the AT command to the JDY-23 module with "\r\n" terminator
- jdy23Serial.print(atCommands[commandIndex]);
- jdy23Serial.print("\r\n");
- Serial.print("Sent AT command: ");
- Serial.println(atCommands[commandIndex]);
- commandIndex++;
- lastCommandTime = millis();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement