//09/06/2022 07:00:41 //Arduino Nano 33 BLE vehicle data to Android App const int RadPin = A0; // Radiator Input Thermister const int CndPin = A1; // Condenser Input Thermister const int AuxPin = A2; // Auxilary Input Not used at this time const int FanPin = 9; // Set Fan pin const long Period = 10000; // Recheck period long previousMillis = 0; // last time the temperature levels were checked, in ms /* Temperatur Monitor This example creates a Bluetooth® Low Energy peripheral with the standard Temperature service and level characteristic. Pins A0, A1 and A2 are used to calculate the temperatures of 3 sensors. The data is calculated by the time set in the constant Period. The circuit: - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics created in this sketch. This example code is in the public domain. */ #include #define SERVICE_UUID = "0000FFE0-0000-1000-8000-00805F9B34FB" #define CHARACTERISTIC_UUID = "0000FFE1-0000-1000-8000-00805F9B34FB" // Define the Temperature Service BLEService TempService(SERVICE_UUID); //*** BLEService Class Any Hex Name 128-bit UUID in String format ********************************************************* // Define Characteristics BLEUnsignedIntCharacteristic IntCharacteristic(CHARACTERISTIC_UUID, BLERead | BLENotify | BLEWrite); // remote clients will be able to get notifications if this characteristic changes void setup() { Serial.begin(9600); // initialize serial communication with PC Arduino Serial Monitor pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); while (1); } /* Set a local name for the Bluetooth® Low Energy device This name will appear in advertising packets and can be used by remote devices to identify this Bluetooth® Low Energy device The name can be changed but maybe be truncated based on space left in advertisement packet */ BLE.setLocalName("Testing123"); //No spaces in name BLE.setAdvertisedService(TempService); // add the service UUID TempService.addCharacteristic(IntCharacteristic); // All integer values BLE.addService(TempService); // Add the Temperature service // Start advertising Bluetooth® Low Energy. It will start continuously transmitting Bluetooth® Low Energy // advertising packets and will be visible to remote Bluetooth® Low Energy central devices // until it receives a new connection BLE.advertise(); // start advertising // Serial.println("Bluetooth® device active, waiting for connections..."); } void loop() { // wait for a Bluetooth® Low Energy central BLEDevice central = BLE.central(); // if a central is connected to the peripheral: if (central) { Serial.print("Connected to central: "); // print the central's BT address: Serial.println(central.address()); // turn on the LED to indicate the connection: digitalWrite(LED_BUILTIN, HIGH); // check the temperature levels every Period (ms) // while the central is connected: while (central.connected()) { // if Period ms have passed, check the temperature levels: if (millis() - previousMillis >= Period) { previousMillis = millis(); updateTemperatures(); } } // when the central disconnects, turn off the LED: digitalWrite(LED_BUILTIN, LOW); Serial.print("Disconnected from central: "); Serial.println(central.address()); } } void updateTemperatures() { // Read the current voltage level on each analog input pin. // This is used here to simulate the charge level of temperaturs. int Rad = analogRead(RadPin); int Cnd = analogRead(CndPin); int Aux = analogRead(AuxPin); /* int RadLevel = map(Rad, 0, 1023, 0, 100); int CndLevel = map(Cnd, 0, 1023, 0, 100); int AuxLevel = map(Aux, 0, 1023, 0, 100); */ int RadLevel = Rad; int CndLevel = Cnd; int AuxLevel = Aux; Serial.print("Rad Level % is now: "); Serial.println(RadLevel); Serial.print("Cnd Level % is now: "); Serial.println(CndLevel); Serial.print("Aux Level % is now: "); Serial.println(AuxLevel); IntCharacteristic.writeValue(RadLevel); // update the Radiator level characteristics IntCharacteristic.writeValue(CndLevel); // update the Condenser level characteristics IntCharacteristic.writeValue(AuxLevel); // update the Aux level characteristics }