Things used in this project

Custom parts and enclosures

Connections
This image shows how to connect the wires.
Makerball starter elements exkl x3s1hx5xpx

Schematics

Schematic of the parts
This is how the parts are connected.
170512 sensors arduino schema 3 tjlt10nmor

Code

Arduino Main CodeArduino
This code takes the signals coming from the 3 sensors and the bluetooth.
unsigned long timeMillis = 0;
unsigned long timeReset = 0;



void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
  setup_bluetooth();
  setup_sensor_a();
  setup_sensor_b();
  setup_sensor_c();
  setup_sensor_d();
}

void loop()
{
  loop_bluetooth();
}


void second_loop(){
  timeMillis = millis();
  loop_sensor_a();
  loop_sensor_b();
  loop_sensor_c();
  loop_sensor_d();
}
Arduino Bluettoth CodeArduino
This code handles the bluetooth connection from the Genuino 101 to a smartphone.
//https://www.arduino.cc/en/Tutorial/Genuino101CurieBLEHeartRateMonitor
#include <CurieBLE.h>

int const outLED = 13; // customize name
boolean isBluetoothOnline = false;
int const maxSendValue = 255;
int const bluetoothSendDelay = 10;


BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService bleService("025A7775-49AA-42BD-BBDB-E2AE77782966"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEIntCharacteristic switchCharacteristic("F38A2C23-BC54-40FC-BED0-60EDDA139F47", BLERead | BLEWrite | BLENotify);


void setup_bluetooth() {
  pinMode(outLED, OUTPUT);   // initialize the LED on pin 13 to indicate when a central is connected

  // set advertised local name and service UUID:
  blePeripheral.setLocalName("LED");
  blePeripheral.setAdvertisedServiceUuid(bleService.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(bleService);
  blePeripheral.addAttribute(switchCharacteristic);


  // set the initial value for the characeristic:
  switchCharacteristic.setValue(0);

  // begin advertising BLE service:
  blePeripheral.begin();

  Serial.println("BLE LED Peripheral");
}


void loop_bluetooth() {
  // 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()) {
      isBluetoothOnline = true;
      digitalWrite(13, isBluetoothOnline);
      second_loop();
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
    isBluetoothOnline = false;
    digitalWrite(13, isBluetoothOnline);
  }
}

void sendSensorValue(int value) {

  Serial.print("write value: ");
  Serial.println(value, DEC);


  if (value <= maxSendValue) {
    switchCharacteristic.setValue(value);
  } else {
    int loops = (int) floor(value / maxSendValue);
    int modulo = (int) value % maxSendValue;

    for (int i = 0; i < loops; i++) {
      switchCharacteristic.setValue(maxSendValue);
      delay(bluetoothSendDelay);
    }
    if (modulo != 0) {
      switchCharacteristic.setValue(modulo);
    }
  }
}
Arduino Sensor CodeArduino
This code checks the signals from the conductive copper foils.
int const outputValueA = 0;  // customize name and value.

int const inPinA = 8; // customize name

unsigned long sensorBreakA = 5000;  // customize name
unsigned long sensorBreakTimeA = timeReset; // customize name

void setup_sensor_a() {
  pinMode(inPinA, INPUT); // customize name
  Serial.println("Setup up sensor A : done");
}



void loop_sensor_a() {
  int val = digitalRead(inPinA);  // customize name

  // prüfen, wie lange es dauert, bis er wieder eine prüfung macht
  Serial.println(millis(), DEC);

  // prüfen, wie lange sensor berührt wird
  if (val == 1){
    Serial.println(millis(), DEC);
  }

  if (sensorBreakTimeA == timeReset && val == 1) { // customize name
    sensorBreakTimeA = timeMillis + sensorBreakA; // customize name
    Serial.print("send value : ");
    Serial.println(outputValueA, DEC);
    sendSensorValue(outputValueA);
  } else if (sensorBreakTimeA > timeMillis) { // customize name
    //Serial.println("break :  A");             // customize name
  } else if (sensorBreakTimeA < timeMillis) { // customize name
    sensorBreakTimeA = timeReset;             // customize name
    //Serial.println(val, DEC);
  }
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Starry Night Prom
Intermediate
  • 2,373
  • 18

How did I stand out at prom? In a light up dress of course!

The Trump Button
Intermediate
  • 1,230
  • 8

Full instructions

The famous connected button to order your favorite drink using Sigfox network.

ARDUINO PONG
Intermediate
  • 22
  • 1

Full instructions

The game in a dot matrix display P10 16x32 pixels

Direction Indicators for Bikes
Intermediate
  • 328
  • 6

Full instructions

Riding bike is a little dangerous. With the Direction Indicators for a bike, car's know if you want to turn right or left. Make biking safe!

Third Eye for The Blind
Intermediate
  • 1,014
  • 13

Full instructions

An innovative wearable technology for visually impaired peoples.

Arduino Tamagotchi Clone - Digital Pet
Intermediate
  • 41
  • 1

Full instructions

In this video we are going to build our own digital pet using Arduino, a Tamagotchi clone.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login