Want to show your appreciation and help with hosting costs? Support us on Patreon!
Submitted on May 26, 2016 at 11:44 AM

Section 1 (Text)

#include <SoftwareSerial.h>
 
SoftwareSerial bluetooth(10, 11); // RX, TX
int a1 = 6;
int a2 = 5;

String receivedBluetoothString = "";
 
void setup() {
  bluetooth.begin(9600);
  pinMode(a1, OUTPUT);
  pinMode(a2, OUTPUT);
}
 
void loop() {
  while (bluetooth.available() > 0) {
 
    char receivedBluetoothChar = bluetooth.read();
    receivedBluetoothString += receivedBluetoothChar;
 
    if (receivedBluetoothChar == '\n') {
 
      if (receivedBluetoothString.toInt() == 887425) {
        digitalWrite(a1, HIGH);
        delay(500);
        digitalWrite(a1, LOW);
      } else if (receivedBluetoothString.toInt() == 887426) {
        digitalWrite(a1, HIGH);
        delay(1000);
        digitalWrite(a1, LOW);
      }
 
      receivedBluetoothString = "";
    }
  }
}