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

Arduinomated Car Parking with Voice Assistance in Smartphone
Intermediate
  • 104
  • 5

Full instructions

Make an assistant which tells you about how much to drive backwards without any collision through your smartphone by Arduino and 1Sheeld.

Sigfox Forest Fire Detector
Intermediate
  • 2,242
  • 14

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector.

From BT to WiFi: Creating WiFi Controlled Arduino Robot Car
Intermediate
  • 316
  • 5

Protip

NodeMCU ESP8266 in access point mode: the simplest way to make Wi-Fi controlled Robot Car from Bluetooth Arduino Robot Car + Android App.

Analog-XY-Plotter-Output-to-HPGL-Translator
Intermediate
  • 250
  • 3

Translate analog X-Y plotter output to HPGL command stream.

Using Common Cathode and Common Anode RGB LED with Arduino
Intermediate
  • 876
  • 15

Protip

Common Cathode and Common Anode RGB LEDs are two different kinds of RGB LEDs whose function is same but working is different.

TV Tee Shirt
Intermediate
  • 3,784
  • 12

One shirt, thirty-six LEDs, endless possibilities.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog