if (cmd == "LED_ON") digitalWrite(13, HIGH); // Turn on built‑in LED Serial.println("LED turned ON"); else if (cmd == "LED_OFF") digitalWrite(13, LOW); Serial.println("LED turned OFF"); else if (cmd == "STATUS") jdy.println("OK");
You can extend this to multiple sensors – simply give each sensor node a unique ID and have the PC switch IDs periodically, or use separate channels for each sensor.
void loop() // Relay any data from the Serial Monitor to the JDY-40 if (Serial.available() > 0) String comdata = ""; while (Serial.available() > 0) comdata += char(Serial.read()); delay(2); jdy40 arduino example best
void setup() // Initialize hardware serial to talk to the JDY-40 Serial.begin(9600);
void setup() Serial.begin(9600); // Default baud rate if (cmd == "LED_ON") digitalWrite(13, HIGH); // Turn
Before diving into the code, it is vital to understand the pinout and operational modes of the JDY-40. The module features 8 pins, but for standard Arduino serial communication, you only need to focus on a few key connections. Pinout Configuration
#include <SoftwareSerial.h>
: Receive Pin (Connects to Arduino TX via a voltage divider)
Because AT commands take only a few milliseconds, this method works well for low‑duty‑cycle applications. Pinout Configuration #include <SoftwareSerial
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.