zahra shekari
Published © GPL3+

Controlling LED with Android

This project uses the HM-05 module to control an LED via Bluetooth commands from an Android app.

ExpertProtip69
Controlling LED with Android

Things used in this project

Hardware components

HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Code

Untitled file

Arduino
#include <SoftwareSerial.h>

SoftwareSerial bluetooth(2, 3);  // RX, TX
const int lampPin = 13;  
char receivedChar;

void setup() {
  pinMode(lampPin, OUTPUT);
  bluetooth.begin(9600);
  Serial.begin(9600);
  Serial.println("منتظر دریافت دستور...");
}

void loop() {
  if (bluetooth.available()) {
    receivedChar = bluetooth.read();
    Serial.print("دستور دریافت شد: ");
    Serial.println(receivedChar);

    if (receivedChar == 'a') {
      digitalWrite(lampPin, HIGH);  
      Serial.println("لامپ روشن شد.");
    } 
    else if (receivedChar == 'b') {
      digitalWrite(lampPin, LOW);  
      Serial.println("لامپ خاموش شد.");
    }
  }
}

Untitled file

Arduino
#include <SoftwareSerial.h>

SoftwareSerial bluetooth(2, 3);  // RX, TX
const int lampPin = 13;  
char receivedChar;

void setup() {
  pinMode(lampPin, OUTPUT);
  bluetooth.begin(9600);
  Serial.begin(9600);
  Serial.println("منتظر دریافت دستور...");
}

void loop() {
  if (bluetooth.available()) {
    receivedChar = bluetooth.read();
    Serial.print("دستور دریافت شد: ");
    Serial.println(receivedChar);

    if (receivedChar == 'a') {
      digitalWrite(lampPin, HIGH);  
      Serial.println("لامپ روشن شد.");
    } 
    else if (receivedChar == 'b') {
      digitalWrite(lampPin, LOW);  
      Serial.println("لامپ خاموش شد.");
    }
  }
}

Credits

zahra shekari
3 projects • 1 follower

Comments