LM35 temp(A4); BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming) BLEService RelayService("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEUnsignedCharCharacteristic switchCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); BLEUnsignedIntCharacteristic LM35Data( "19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); const int RelayPin = 13; // pin to use for the Relay char control = '0'; int old_data ;
void setup() { Serial.begin(9600);
// set Light pin to output mode pinMode( RelayPin, OUTPUT);
// set advertised local name and service UUID: blePeripheral.setLocalName("LM35"); blePeripheral.setAdvertisedServiceUuid( RelayService.uuid());
// add service and characteristic: blePeripheral.addAttribute(RelayService); blePeripheral.addAttribute(switchCharacteristic); blePeripheral.addAttribute(LM35Data); // set the initial value for the characeristic: switchCharacteristic.setValue(0);
// begin advertising BLE Relay service: blePeripheral.begin();
Serial.println("BLE Relay service."); }
void loop() { // listen for BLE peripherals to connect: BLECentral central = blePeripheral.central();
// if a central is connected to peripheral: if (central) { Serial.print("Connected to central: "); // print the central's MAC address: Serial.println(central.address());
// while the central is still connected to peripheral: while (central.connected()) { // if the remote device wrote to the characteristic, // use the value to control the Light: if (switchCharacteristic.written()) {
control = switchCharacteristic.value(); Serial.print("value : "); Serial.println(control);
if (control == 'O') { Serial.println("Relay on"); Serial.println(switchCharacteristic.value()); digitalWrite(13, HIGH); // Open relay } else if(control == 'C'){
Serial.println(F("Relay off")); Serial.println(switchCharacteristic.value()); digitalWrite(13, LOW); // Close Relay }