Two Arduino Multiple Sensor Bluetooth Connection

Hello guyz,

I have a project for one of my courses and I have come to you gain from your knowledge.
I have a five finger controlled robotic hand. 5 flex sensors are used and this sensor values are transmitted to Arduino Nano. Nano also works with HC-06 slave module. Arduino Uno controls the robot and rotates servo motors corresponding to sensor values. Each flex sensor controls one servo. HC-05 bluetooth module connected to Uno in master mode. Bluetooths are paired already.

  1. To transmit five sensor values I use bluetooth.serialread and write commands. For one flex one servo, it works fine. But when it comes to five it just does not send the sensor data. I used the .read() code and tried to define inside of paranthesis but it didn't work. When I connect all od them at the same time, servos are buzzing but do not respond any change of flex sensor. How can I modify the code for such application?
    I will try to upload the code asap. I suppose Uno(servo) side receive the data but does not know which one is for which servo.
  2. Could the slave and master module vice versa be a solution for that?
  3. regardless from this question, Serial monitoring sensor values are fluctuating and when i use them to map for pwm outputs, I use a typical renge like 600-900. But I need some sort of calibration like when flex is at zero degrees ie min value will be 650 and when 90 it is 950. But I check this for one flex sensor. Is there a mini code or sth for that?
    Maybe a code for arduino to choose the maximum value and scale it to my range. 900--180 Normally. If sensor max is 950 automatically this value should be equal to 180 since it is over limits.

Thanks in advance!

up

upupup

jrrtolkien09:
I will try to upload the code asap.

?

//Yazılım Geliştirme By Robimek - 2015
//Yazılım Lisans By Robimek
//www.robimek.com
#include <SoftwareSerial.h>
#define BT_SERIAL_TX 2
#define BT_SERIAL_RX 3
SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);
// Include the servo library to add servo-control functions:

// Define the analog input pin to measure flex sensor position:

const int flexpin1 = A0;
const int flexpin2 = A1;
const int flexpin3 = A2;
const int flexpin4 = A3;
const int flexpin5 = A4;
//int sensorValue = 0; // the sensor value
//int sensorMin = 1023; // minimum sensor value
//int sensorMax = 0; // maximum sensor value
int flexposition1;
int flexposition2;
int flexposition3;
int flexposition4;
int flexposition5;
int sensorMin = 760;
int sensorMax = 950;

char flex1[4];
char flex2[4];
char flex3[4];
char flex4[4];
char flex5[4];

String strflex1;
String strflex2;
String strflex3;
String strflex4;
String strflex5;

void setup()
{
// // calibrate during the first five seconds
// while (millis() < 25000) {
// flexposition1 = analogRead(flexpin1);
//
// // record the maximum sensor value
// if (flexposition1 > sensorMax) {
// sensorMax = flexposition1;
// }
//
// // record the minimum sensor value
// if (flexposition1 < sensorMin) {
// sensorMin = flexposition1;
// }
// flexposition2 = analogRead(flexpin2);
//
// // record the maximum sensor value
// if (flexposition2 > sensorMax) {
// sensorMax = flexposition2;
// }
//
// // record the minimum sensor value
// if (flexposition2 < sensorMin) {
// sensorMin = flexposition2;
// }
// flexposition3 = analogRead(flexpin3);
//
// // record the maximum sensor value
// if (flexposition3 > sensorMax) {
// sensorMax = flexposition3;
// }
//
// // record the minimum sensor value
// if (flexposition3 < sensorMin) {
// sensorMin = flexposition3;
// }
// flexposition4 = analogRead(flexpin4);
//
// // record the maximum sensor value
// if (flexposition4 > sensorMax) {
// sensorMax = flexposition4;
// }
//
// // record the minimum sensor value
// if (flexposition4 < sensorMin) {
// sensorMin = flexposition4;
// }
// flexposition5 = analogRead(flexpin5);
//
// // record the maximum sensor value
// if (flexposition5 > sensorMax) {
// sensorMax = flexposition5;
// }
//
// // record the minimum sensor value
// if (flexposition5 < sensorMin) {
// sensorMin = flexposition5;
// }
// }
//
//
// // signal the end of the calibration period
Serial.begin(9600);
BluetoothSerial.begin(38400);
}
void loop()
{
flexposition1 = analogRead(flexpin1);
flexposition1 = map(flexposition1, sensorMin, sensorMax, 0, 175);
flexposition1 = constrain(flexposition1, 0, 180);
flexposition2 = analogRead(flexpin2);
flexposition2 = map(flexposition2, sensorMin, sensorMax, 0, 175);
flexposition2 = constrain(flexposition2, 0, 180);
flexposition3 = analogRead(flexpin3);
flexposition3 = map(flexposition3, sensorMin, sensorMax, 0, 175);
flexposition3 = constrain(flexposition3, 0, 180);
flexposition4 = analogRead(flexpin4);
flexposition4 = map(flexposition4, sensorMin, sensorMax, 0, 175);
flexposition4 = constrain(flexposition4, 0, 180);
flexposition5 = analogRead(flexpin5);
flexposition5 = map(flexposition5, sensorMin, sensorMax, 0, 175);
flexposition5 = constrain(flexposition5, 0, 180);

//buradan

strflex1=String(flexposition1);
strflex1.toCharArray(flex1,4);
BluetoothSerial.write("flex1 ");
BluetoothSerial.write(flex1);
BluetoothSerial.write("\n");

strflex2=String(flexposition2);
strflex2.toCharArray(flex2,4);
BluetoothSerial.write("flex2 ");
BluetoothSerial.write(flex2);
BluetoothSerial.write("\n");

strflex3=String(flexposition3);
strflex3.toCharArray(flex3,4);
BluetoothSerial.write("flex3 ");
BluetoothSerial.write(flex3);
BluetoothSerial.write("\n");

strflex4=String(flexposition4);
strflex4.toCharArray(flex4,4);
BluetoothSerial.write("flex4 ");
BluetoothSerial.write(flex4);
BluetoothSerial.write("\n");

strflex5=String(flexposition5);
strflex5.toCharArray(flex5,4);
BluetoothSerial.write("flex5 ");
BluetoothSerial.write(flex5);
BluetoothSerial.write("\n");

//burasını ben yazdım, veri gönderip diğer tarafta char a çevrilip okuması lazım

Serial.print(" sensor1: ");
Serial.print(flexposition1);
Serial.print(" sensor2: ");
Serial.print(flexposition2);
Serial.print(" sensor3: ");
Serial.print(flexposition3);
Serial.print(" sensor4: ");
Serial.print(flexposition4);
Serial.print(" sensor5: ");
Serial.println(flexposition5);
delay(100);

// // Because the voltage divider circuit only returns a portion
// // of the 0-1023 range of analogRead(), we'll map() that range
// // to the servo's range of 0 to 180 degrees. The flex sensors
// // we use are usually in the 600-900 range:
//
// servoposition = map(flexposition, 600, 900, 0, 180);
// servoposition = constrain(servoposition, 0, 180);
// val = analogRead(potpin);
// val = map(val, 0, 1023, 0, 179);
// BluetoothSerial.write(val);
//
// delay(100);
}

//Yazılım Geliştirme By Robimek - 2015
//Yazılım Lisans By Robimek
//www.robimek.com
#include <SoftwareSerial.h>
#define BT_SERIAL_TX 2
#define BT_SERIAL_RX 3
SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
unsigned int flexposition1;
unsigned int flexposition2;
unsigned int flexposition3;
unsigned int flexposition4;
unsigned int flexposition5;
int servoposition1;
int servoposition2;
int servoposition3;
int servoposition4;
int servoposition5;
int sensorMin = 730;
int sensorMax = 940;

//benim eklediklerim
char cmd[100];
int cmdIndex;

////mass filter k katsayı
//int k=0.8;
//
//int old_val1=0;
//int new_val1=0;
//
//int old_val2=0;
//int new_val2=0;
//
//int old_val3=0;
//int new_val3=0;
//
//int old_val4=0;
//int new_val4=0;
//
//int old_val5=0;
//int new_val5=0;

void exeCmd(){

if( cmd[0]=='f' &&
cmd[1]=='l' &&
cmd[2]=='e' &&
cmd[3]=='x' &&
cmd[4]=='1' &&
cmd[5]==' ' ) {

int val = 0;
for(int i=6; cmd*!=0; i++) { // number begins at cmd[6]*
_ val = val10 + (cmd-'0');_
_
}_
// new_val1=val+new_val1;
// old_val1=kold_val1+(1-k)new_val1;
_
servo1.write(val);*_

* }*
* if( cmd[0]=='f' &&*
* cmd[1]=='l' &&*
* cmd[2]=='e' &&*
* cmd[3]=='x' &&*
* cmd[4]=='2' &&*
* cmd[5]==' ' ) {*

* int val = 0;*
_ for(int i=6; cmd*!=0; i++) { // number begins at cmd[6]
val = val10 + (cmd*-'0');
}*_

// new_val2=val+new_val2;
// old_val2=kold_val2+(1-k)new_val2;
_ servo2.write(val);_

* }*
* if( cmd[0]=='f' &&*
* cmd[1]=='l' &&*
* cmd[2]=='e' &&*
* cmd[3]=='x' &&*
* cmd[4]=='3' &&*
* cmd[5]==' ' ) {*

* int val = 0;*
_ for(int i=6; cmd*!=0; i++) { // number begins at cmd[6]
val = val10 + (cmd*-'0');
}*_

// new_val3=val+new_val3;
// old_val3=kold_val3+(1-k)new_val3;
_ servo3.write(val);;

* }
if( cmd[0]=='f' &&
cmd[1]=='l' &&
cmd[2]=='e' &&
cmd[3]=='x' &&
cmd[4]=='4' &&
cmd[5]==' ' ) {*_

* int val = 0;*
_ for(int i=6; cmd*!=0; i++) { // number begins at cmd[6]
val = val10 + (cmd*-'0');
}*_

* // new_val4=val+new_val4;
// old_val4=kold_val4+(1-k)new_val4;
_ servo4.write(val);
}
if( cmd[0]=='f' &&
cmd[1]=='l' &&
cmd[2]=='e' &&
cmd[3]=='x' &&
cmd[4]=='5' &&
cmd[5]==' ' ) {*_

* int val = 0;*
_ for(int i=6; cmd*!=0; i++) { // number begins at cmd[6]
val = val10 + (cmd*-'0');
}*_

* // new_val5=val+new_val5;
// old_val5=kold_val5+(1-k)new_val5;
_ servo5.write(val);
}*_

}
//buraya kadar
void setup()
{
Serial.begin(57600);
BluetoothSerial.begin(57600);
servo1.attach(5);
servo2.attach(6);
servo3.attach(9);
servo4.attach(10);
servo5.attach(11);
//bi de cmdIndex var
* cmdIndex = 0;*
}
void loop() // run over and over
{
* //burayı baştan yazdım ellemeye gerek yok fonksiyon hallediyo hepsini*
if (BluetoothSerial.available()>0){

* char c = (char)BluetoothSerial.read();*

* if(c=='\n') {*
* cmd[cmdIndex] = 0;*
* exeCmd(); // execute the command*
* cmdIndex = 0; // reset the cmdIndex*
* } else { *
* cmd[cmdIndex] = c;*
* if(cmdIndex<99) cmdIndex++;*
* }*
}
}

Hi sir for bluetooth project it done ?

i need to make this project but i have it same problem .

if you done you can show your code to me ?

Hy,

Can you please send the circuit diagram and code, because I am facing lot's of problem
and can you do it as soon as possible