Components and supplies
Arduino 101
Apps and platforms
Arduino IDE
Xcode
Project description
Code
Arduino Bluettoth Code
arduino
This code handles the bluetooth connection from the Genuino 101 to a smartphone.
1//https://www.arduino.cc/en/Tutorial/Genuino101CurieBLEHeartRateMonitor 2#include <CurieBLE.h> 3 4int const outLED = 13; // customize name 5boolean isBluetoothOnline = false; 6int const maxSendValue = 255; 7int const bluetoothSendDelay = 10; 8 9 10BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming) 11BLEService bleService("025A7775-49AA-42BD-BBDB-E2AE77782966"); // BLE LED Service 12 13// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central 14BLEIntCharacteristic switchCharacteristic("F38A2C23-BC54-40FC-BED0-60EDDA139F47", BLERead | BLEWrite | BLENotify); 15 16 17void setup_bluetooth() { 18 pinMode(outLED, OUTPUT); // initialize the LED on pin 13 to indicate when a central is connected 19 20 // set advertised local name and service UUID: 21 blePeripheral.setLocalName("LED"); 22 blePeripheral.setAdvertisedServiceUuid(bleService.uuid()); 23 24 // add service and characteristic: 25 blePeripheral.addAttribute(bleService); 26 blePeripheral.addAttribute(switchCharacteristic); 27 28 29 // set the initial value for the characeristic: 30 switchCharacteristic.setValue(0); 31 32 // begin advertising BLE service: 33 blePeripheral.begin(); 34 35 Serial.println("BLE LED Peripheral"); 36} 37 38 39void loop_bluetooth() { 40 // listen for BLE peripherals to connect: 41 BLECentral central = blePeripheral.central(); 42 43 // if a central is connected to peripheral: 44 if (central) { 45 Serial.print("Connected to central: "); 46 // print the central's MAC address: 47 Serial.println(central.address()); 48 49 // while the central is still connected to peripheral: 50 while (central.connected()) { 51 isBluetoothOnline = true; 52 digitalWrite(13, isBluetoothOnline); 53 second_loop(); 54 } 55 56 // when the central disconnects, print it out: 57 Serial.print(F("Disconnected from central: ")); 58 Serial.println(central.address()); 59 isBluetoothOnline = false; 60 digitalWrite(13, isBluetoothOnline); 61 } 62} 63 64void sendSensorValue(int value) { 65 66 Serial.print("write value: "); 67 Serial.println(value, DEC); 68 69 70 if (value <= maxSendValue) { 71 switchCharacteristic.setValue(value); 72 } else { 73 int loops = (int) floor(value / maxSendValue); 74 int modulo = (int) value % maxSendValue; 75 76 for (int i = 0; i < loops; i++) { 77 switchCharacteristic.setValue(maxSendValue); 78 delay(bluetoothSendDelay); 79 } 80 if (modulo != 0) { 81 switchCharacteristic.setValue(modulo); 82 } 83 } 84} 85
Arduino Sensor Code
arduino
This code checks the signals from the conductive copper foils.
1 2int const outputValueA = 0; // customize name and value. 3 4int const inPinA = 8; // customize name 5 6unsigned long sensorBreakA = 5000; // customize name 7unsigned long sensorBreakTimeA = timeReset; // customize name 8 9void setup_sensor_a() { 10 pinMode(inPinA, INPUT); // customize name 11 Serial.println("Setup up sensor A : done"); 12} 13 14 15 16void loop_sensor_a() { 17 int val = digitalRead(inPinA); // customize name 18 19 // prüfen, wie lange es dauert, bis er wieder eine prüfung macht 20 Serial.println(millis(), DEC); 21 22 // prüfen, wie lange sensor berührt wird 23 if (val == 1){ 24 Serial.println(millis(), DEC); 25 } 26 27 if (sensorBreakTimeA == timeReset && val == 1) { // customize name 28 sensorBreakTimeA = timeMillis + sensorBreakA; // customize name 29 Serial.print("send value : "); 30 Serial.println(outputValueA, DEC); 31 sendSensorValue(outputValueA); 32 } else if (sensorBreakTimeA > timeMillis) { // customize name 33 //Serial.println("break : A"); // customize name 34 } else if (sensorBreakTimeA < timeMillis) { // customize name 35 sensorBreakTimeA = timeReset; // customize name 36 //Serial.println(val, DEC); 37 } 38}
Arduino Main Code
arduino
This code takes the signals coming from the 3 sensors and the bluetooth.
1unsigned long timeMillis = 0; 2unsigned long timeReset = 0; 3 4 5 6void setup() 7{ 8 Serial.begin(9600); // sets the serial port to 9600 9 setup_bluetooth(); 10 setup_sensor_a(); 11 setup_sensor_b(); 12 setup_sensor_c(); 13 setup_sensor_d(); 14} 15 16void loop() 17{ 18 loop_bluetooth(); 19} 20 21 22void second_loop(){ 23 timeMillis = millis(); 24 loop_sensor_a(); 25 loop_sensor_b(); 26 loop_sensor_c(); 27 loop_sensor_d(); 28} 29
Arduino Sensor Code
arduino
This code checks the signals from the conductive copper foils.
1 2int const outputValueA = 0; // customize name and value. 3 4int const inPinA = 8; // customize name 5 6unsigned long sensorBreakA = 5000; // customize name 7unsigned long sensorBreakTimeA = timeReset; // customize name 8 9void setup_sensor_a() { 10 pinMode(inPinA, INPUT); // customize name 11 Serial.println("Setup up sensor A : done"); 12} 13 14 15 16void loop_sensor_a() { 17 int val = digitalRead(inPinA); // customize name 18 19 // prüfen, wie lange es dauert, bis er wieder eine prüfung macht 20 Serial.println(millis(), DEC); 21 22 // prüfen, wie lange sensor berührt wird 23 if (val == 1){ 24 Serial.println(millis(), DEC); 25 } 26 27 if (sensorBreakTimeA == timeReset && val == 1) { // customize name 28 sensorBreakTimeA = timeMillis + sensorBreakA; // customize name 29 Serial.print("send value : "); 30 Serial.println(outputValueA, DEC); 31 sendSensorValue(outputValueA); 32 } else if (sensorBreakTimeA > timeMillis) { // customize name 33 //Serial.println("break : A"); // customize name 34 } else if (sensorBreakTimeA < timeMillis) { // customize name 35 sensorBreakTimeA = timeReset; // customize name 36 //Serial.println(val, DEC); 37 } 38}
Arduino Bluettoth Code
arduino
This code handles the bluetooth connection from the Genuino 101 to a smartphone.
1//https://www.arduino.cc/en/Tutorial/Genuino101CurieBLEHeartRateMonitor 2#include 3 <CurieBLE.h> 4 5int const outLED = 13; // customize name 6boolean isBluetoothOnline 7 = false; 8int const maxSendValue = 255; 9int const bluetoothSendDelay = 10; 10 11 12BLEPeripheral 13 blePeripheral; // BLE Peripheral Device (the board you're programming) 14BLEService 15 bleService("025A7775-49AA-42BD-BBDB-E2AE77782966"); // BLE LED Service 16 17// 18 BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central 19BLEIntCharacteristic 20 switchCharacteristic("F38A2C23-BC54-40FC-BED0-60EDDA139F47", BLERead | BLEWrite 21 | BLENotify); 22 23 24void setup_bluetooth() { 25 pinMode(outLED, OUTPUT); 26 // initialize the LED on pin 13 to indicate when a central is connected 27 28 29 // set advertised local name and service UUID: 30 blePeripheral.setLocalName("LED"); 31 32 blePeripheral.setAdvertisedServiceUuid(bleService.uuid()); 33 34 // add service 35 and characteristic: 36 blePeripheral.addAttribute(bleService); 37 blePeripheral.addAttribute(switchCharacteristic); 38 39 40 41 // set the initial value for the characeristic: 42 switchCharacteristic.setValue(0); 43 44 45 // begin advertising BLE service: 46 blePeripheral.begin(); 47 48 Serial.println("BLE 49 LED Peripheral"); 50} 51 52 53void loop_bluetooth() { 54 // listen for BLE 55 peripherals to connect: 56 BLECentral central = blePeripheral.central(); 57 58 59 // if a central is connected to peripheral: 60 if (central) { 61 Serial.print("Connected 62 to central: "); 63 // print the central's MAC address: 64 Serial.println(central.address()); 65 66 67 // while the central is still connected to peripheral: 68 while (central.connected()) 69 { 70 isBluetoothOnline = true; 71 digitalWrite(13, isBluetoothOnline); 72 73 second_loop(); 74 } 75 76 // when the central disconnects, print 77 it out: 78 Serial.print(F("Disconnected from central: ")); 79 Serial.println(central.address()); 80 81 isBluetoothOnline = false; 82 digitalWrite(13, isBluetoothOnline); 83 } 84} 85 86void 87 sendSensorValue(int value) { 88 89 Serial.print("write value: "); 90 Serial.println(value, 91 DEC); 92 93 94 if (value <= maxSendValue) { 95 switchCharacteristic.setValue(value); 96 97 } else { 98 int loops = (int) floor(value / maxSendValue); 99 int modulo 100 = (int) value % maxSendValue; 101 102 for (int i = 0; i < loops; i++) { 103 switchCharacteristic.setValue(maxSendValue); 104 105 delay(bluetoothSendDelay); 106 } 107 if (modulo != 0) { 108 switchCharacteristic.setValue(modulo); 109 110 } 111 } 112} 113
Arduino Main Code
arduino
This code takes the signals coming from the 3 sensors and the bluetooth.
1unsigned long timeMillis = 0; 2unsigned long timeReset = 0; 3 4 5 6void setup() 7{ 8 Serial.begin(9600); // sets the serial port to 9600 9 setup_bluetooth(); 10 setup_sensor_a(); 11 setup_sensor_b(); 12 setup_sensor_c(); 13 setup_sensor_d(); 14} 15 16void loop() 17{ 18 loop_bluetooth(); 19} 20 21 22void second_loop(){ 23 timeMillis = millis(); 24 loop_sensor_a(); 25 loop_sensor_b(); 26 loop_sensor_c(); 27 loop_sensor_d(); 28} 29
Downloadable files
Schematic of the parts
This is how the parts are connected.
Schematic of the parts
Schematic of the parts
This is how the parts are connected.
Schematic of the parts
Documentation
Connections
This image shows how to connect the wires.
Connections
Comments
Only logged in users can leave comments
makerball
0 Followers
•0 Projects
Table of contents
Intro
3
0