Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 |
Controlling LED with Android
#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("لامپ خاموش شد.");
}
}
}
#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("لامپ خاموش شد.");
}
}
}
Comments