Advertisement
NaroxEG

HC05 Arduino LED Control

Jan 25th, 2025
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. SoftwareSerial bluetooth(10, 11);  // RX, TX
  4.  
  5. int ledPin = 3;
  6. char command;
  7.  
  8. void setup() {
  9.   pinMode(ledPin, OUTPUT);
  10.   bluetooth.begin(9600);  // Start Bluetooth communication
  11.   Serial.begin(9600);
  12. }
  13.  
  14. void loop() {
  15.   if (bluetooth.available() > 0) {
  16.     command = bluetooth.read();  // Read command from Bluetooth
  17.     Serial.println(command);
  18.     if (command == '1') {
  19.       digitalWrite(ledPin, HIGH);  // Turn on LED
  20.     } else if (command == '0') {
  21.       digitalWrite(ledPin, LOW);   // Turn off LED
  22.     }
  23.   }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement