Hardware components | ||||||
| × | 3 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 3 | ||||
Hand tools and fabrication machines | ||||||
| ||||||
|
My project is a silicone gripper controlled with a flex sensor connected to my hand. When I close my hand the arduino nano 33 ble sense connected to the flex sensor sends a message to another nano 33 ble sense, the 2nd nano is connected to 7 relays. Each relay is connected to an air pump/valve (3 air pumps & 3 air valves), the final relay controls the nOOds green LED.
The silicone "fingers" are made of EcoFlex 00-30. I casted them using two 3D-printed molds, a top & bottom, which later is connected together using some eco-flex (also inserted an air tube in-between the two parts with a little bit of ecoflex to make sure it sticks).
Transmitter_BLE_Flex
ArduinoThe transmitter code, arduino nano 33 BE sense with a flex sensor sends msg via BLE to another arduino.
#include <ArduinoBLE.h>
const int R_LED_PIN = 22;
const int G_LED_PIN = 23;
const int B_LED_PIN = 24;
int voltageThreshold = 250;
void setup() {
Serial.begin(9600);
// initialize the BLE hardware
BLE.begin();
Serial.println("BLE Central - LED control");
// start scanning for peripherals
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}
void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();
if (peripheral) {
// discovered a peripheral, print out address, local name, and advertised service
Serial.print("Found ");
Serial.print(peripheral.address());
Serial.print(" '");
Serial.print(peripheral.localName());
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();
if (peripheral.localName() != "LED") {
return;
}
// stop scanning
BLE.stopScan();
controlLed(peripheral);
// peripheral disconnected, start scanning again
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}
}
void controlLed(BLEDevice peripheral) {
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}
// discover peripheral attributes
Serial.println("Discovering attributes ...");
if (peripheral.discoverAttributes()) {
Serial.println("Attributes discovered");
} else {
Serial.println("Attribute discovery failed!");
peripheral.disconnect();
return;
}
// retrieve the LED characteristic
BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214");
if (!ledCharacteristic) {
Serial.println("Peripheral does not have LED characteristic!");
peripheral.disconnect();
return;
} else if (!ledCharacteristic.canWrite()) {
Serial.println("Peripheral does not have a writable LED characteristic!");
peripheral.disconnect();
return;
}
while (peripheral.connected()) {
int currentVoltage = analogRead(A0); // store the incoming voltage
Serial.println(currentVoltage);
if (currentVoltage < 200 ) {
setColor("GREEN");
ledCharacteristic.writeValue((byte)0x01);
} if (currentVoltage > voltageThreshold) {
Serial.println("button released");
setColor("RED");
ledCharacteristic.writeValue((byte)0x00);
}
}
Serial.println("Peripheral disconnected");
}
void setColor(String color)
{
if (color == "RED")
{
digitalWrite(R_LED_PIN, LOW); // High values -> lower brightness
digitalWrite(G_LED_PIN, HIGH);
digitalWrite(B_LED_PIN, HIGH);
}else if (color == "GREEN")
{
digitalWrite(R_LED_PIN, HIGH); // High values -> lower brightness
digitalWrite(G_LED_PIN, LOW);
digitalWrite(B_LED_PIN, HIGH);
}else if (color == "BLUE")
{
digitalWrite(R_LED_PIN, HIGH); // High values -> lower brightness
digitalWrite(G_LED_PIN, HIGH);
digitalWrite(B_LED_PIN, LOW);
}else if (color == "PURPLE")
{
digitalWrite(R_LED_PIN, LOW); // High values -> lower brightness
digitalWrite(G_LED_PIN, HIGH);
digitalWrite(B_LED_PIN, LOW);
}
}
Receiver_BLE_Flex
ArduinoReceiver code, controls the relays connected to the 3 air pumps/3 air valves plus the nOOds LED.
#include <ArduinoBLE.h>
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
int relay7SOLELEFT = 7;
int relay10PUMPLEFT = 10;
int relay8SOLEMIDDLE = 8;
int relay11PUMPMIDDLE = 11;
int relay9SOLERIGHT = 9;
int relay12PUMPRIGHT = 12;
int relay5LED = 5;
void setup() {
Serial.begin(9600);
pinMode(relay7SOLELEFT, OUTPUT);
pinMode(relay10PUMPLEFT, OUTPUT);
pinMode(relay8SOLEMIDDLE, OUTPUT);
pinMode(relay11PUMPMIDDLE, OUTPUT);
pinMode(relay9SOLERIGHT, OUTPUT);
pinMode(relay12PUMPRIGHT, OUTPUT);
pinMode(relay5LED, OUTPUT);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("LED");
BLE.setAdvertisedService(ledService);
// add the characteristic to the service
ledService.addCharacteristic(switchCharacteristic);
// add service
BLE.addService(ledService);
// set the initial value for the characeristic:
switchCharacteristic.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
}
void loop() {
// listen for BLE peripherals to connect:
BLEDevice central = BLE.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 LED:
if (switchCharacteristic.written()) {
if (switchCharacteristic.value()) { // any value other than 0
digitalWrite(relay8SOLEMIDDLE, HIGH);
digitalWrite(relay11PUMPMIDDLE, HIGH);
digitalWrite(relay7SOLELEFT, HIGH);
digitalWrite(relay10PUMPLEFT, HIGH);
digitalWrite(relay9SOLERIGHT, HIGH);
digitalWrite(relay12PUMPRIGHT, HIGH);
digitalWrite(relay5LED, HIGH);
Serial.println("ON");
} else { // a 0 value
digitalWrite(relay8SOLEMIDDLE, LOW);
digitalWrite(relay11PUMPMIDDLE, LOW);
digitalWrite(relay7SOLELEFT, LOW);
digitalWrite(relay10PUMPLEFT, LOW);
digitalWrite(relay9SOLERIGHT, LOW);
digitalWrite(relay12PUMPRIGHT, LOW);
digitalWrite(relay5LED, LOW);
Serial.println("OFF");
}
}
}
}
}
Comments