Mobile phone Bluetooth control relay experiment

Mobile phone Bluetooth control relay experiment

Experimental phenomena

Wireless switch relay using mobile phone

Theoretical study

Electromagnetic relay is the earliest and most widely used relay among relays. Electromagnetic relay is generally composed of iron core, electromagnetic coil, armature, return spring, contact, support and pin. Electromagnetic relay is an electronic control device. It has a control system (also called an input loop) and a controlled system (also called an output loop). It is usually used in automatic control circuits. It actually uses a smaller current. Lower voltage to control larger current. A kind of "automatic switch" for higher voltage. Therefore, it plays the role of automatic adjustment, safety protection, conversion circuit, etc. in the circuit. The
Insert picture description here
relay is generally a device for low-voltage control of high-voltage, which generally needs to be driven by triode isolation, and the experimental module uses NPN triode drive. When the control pin is at high level, the normally open end of the relay is closed/D2 is on; when the control pin is at low level, the normally open end of the relay is open/D2 is off

Schematic diagram

Insert picture description here

Code writing

arduino UNO R3 board code:

//arduino UNO R3板子代码
String inputString = "";         // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete
int relay = 2;
void setup() {
    
    
  // put your setup code here, to run once:
  Serial.begin(9600);//初始化串口设置波特率
  pinMode(13, OUTPUT);
  pinMode(relay, OUTPUT);
}
void loop() {
    
    
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}
void serialEvent() {
    
    
  while (Serial.available()) {
    
    
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == 'A' || inChar == 'a') {
    
    
      digitalWrite(relay, HIGH);
    } else if (inChar == 'B' || inChar == 'b') {
    
    
      digitalWrite(relay, LOW);
    }
  }
}

arduino Leonardo board code:

//arduino Leonardo板子代码
String inputString = "";         // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete
int relay = 2;
void setup() {
    
    
  // put your setup code here, to run once:
  Serial1.begin(9600);//初始化串口设置波特率
  pinMode(13, OUTPUT);
  pinMode(relay, OUTPUT);
}
void loop() {
    
    
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}
void serialEvent1() {
    
    
  while (Serial1.available()) {
    
    
    // get the new byte:
    char inChar = (char)Serial1.read();
    if (inChar == 'A' || inChar == 'a') {
    
    
      digitalWrite(relay, HIGH);
    } else if (inChar == 'B' || inChar == 'b') {
    
    
      digitalWrite(relay, LOW);
    }
  }
}

Guess you like

Origin blog.csdn.net/qq_45671732/article/details/109543940