BELT_02 (Formerly _120806_in_class_01)

/* This is _120806_in_class_01 renamed

IMRAN SHAMSUL – MAJOR PROJECT – PROJECT ANDERS

*/
// these arrays are looped through, make sure your pinb and motor match.
// so mypin[1] should corrispond to mymotor[1] and so on
int myPins[] = {2,3,4,5};
int myMotors[] = {13,12,11,10};
int howmany = 4;
int maxDistance[] = {20,20,20,20};
int maxPower[] = {255,255,2555,255};

void setup() {
// initialize serial communication:
Serial.begin(9600); // this just means you can output to the serial panel
}

void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, cm;
// loop through the pins array, noting theat we’ve set the limit to 5
int i; // define “i” this is used as a count variable
// start a count loop, since you know how many sensors there are, hard code this in the i < NUMBER OF SENSORS bit
for (i = 0; i < howmany; i = i + 1) {
// print out what pin
// Serial.println(myPins[i]);

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
// check the pin pMyPin[i]
pinMode(myPins[i], OUTPUT);
digitalWrite(myPins[i], LOW);
delayMicroseconds(2);
digitalWrite(myPins[i], HIGH);
delayMicroseconds(5);
digitalWrite(myPins[i], LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(myPins[i], INPUT);
duration = pulseIn(myPins[i], HIGH);

// convert the time into a distance
cm = microsecondsToCentimeters(duration);

// Serial.print(inches);
// Serial.print(“in, “);
// inches are for americans, they silly.
Serial.print(myPins[i]);
Serial.print(“-“);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();

// if(cm < 100){
int motorPWM = map(cm,maxDistance[i],0,0,maxPower[i]); //variable map formula relationship
motorPWM = constrain(motorPWM, 0, 255);

analogWrite(myMotors[i],motorPWM);

Serial.print(“motorPWM = “);
Serial.println(motorPWM);

delay(200);
}

// delay(returndelay(cm));
// analogWrite(myMotors[i], 0);
// } else {
// analogWrite(myMotors[i], 0);
// }
// end of the pin loop

// delay(200); uncomment if needed
}

/*
// change to formul
int returnfeedback(int cm){
int motorPWM = map(cm,maxDistance[],0,0,maxPower[]); //variable map formula relationship
motorPWM = constrain(motorPWM, 0, 255);
// if (cm < 5){ // distance
// return 255; // strength
// } else if (cm < 10){
// return 220;
// } else if (cm < 20){
// return 190;
// } else if (cm < 40){
// return 160;
// } else if (cm < 80){
// return 130;
// } else if (cm < 100){
// return 100;
// } else {
// return 0;
// }
Serial.print(“motorPWM = “);
Serial.println(motorPWM);

return motorPWM; //serial print pwm

}
*/

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}

HPB now wearable!

 

After an even’s work, I have managed to make the belt wearable with all sensors and motors attached, including the arduino. This simplifies my original concept of requiring an Ethernet cable to transport sensor pins to arduino pins. The velcro tape does a good job of organising the cables and also mounting and holding the arduino+shield on the back of the belt. Code still needs to be worked on, I will build a coding rig to debug the issues, it will follow this set-up and include LEDs for extra diagnostics.

Haptic Proximity Best (HPB) Components for Build V1.0

At this stage the belt is wired as correctly as I can imagine. I did make the mistake of connecting positive to negative and vice versa. This was corrected and now I’m having problems with the code, as only one sensor and motor combination is working.

In terms of sensor placement, it seems ideal for my body shape. It is restricted in the sense that it is unable to be worn by a person with a smaller or larger girth of tummy than myself.

Once the coding bugs are sorted (refer to this post), I will be able to test things like battery life.

My plan is to simplify the assembly and break it down into components. This will require some cadding and hopefully some rapid prototyping!!

Wiring and programming Arduino

Ultrasonic Sensor attached with zipties

Vibration Motor on the read of the belt.

Parts laid out before the belt build

BELT_01 Code – Arduino

/* BELT DEVICE _ V1.01

Imran Shamsul http://www.imranshamsul.com.au
4 sensors
4 motors
Arduino Mega 2560

*/

// these arrays are looped through, make sure your pinb and motor match.
// so mypin[1] should corrispond to mymotor[1] and so on

int myPins[] = {2,3,4,5};
int myMotors[] = {10,11,12,13};
int howmany = 4;

int maxDistance[] = {50};  //THIS IS THE PROBLEM CODE it should look like this: {50,50,50,50}
int maxPower[] = {255}; //max 255 ” {255,255,255,255}

void setup() {
// initialize serial communication:
Serial.begin(9600); // this just means you can output to the serial panel
}

void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, cm;

// loop through the pins array, noting theat we’ve set the limit to 5
int i; // define “i” this is used as a count variable

// start a count loop, since you know how many sensors there are, hard code this in the i < NUMBER OF SENSORS bit
for (i = 0; i < howmany; i = i + 1) {

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
// check the pin pMyPin[i]
pinMode(myPins[i], OUTPUT);
digitalWrite(myPins[i], LOW);
delayMicroseconds(2);
digitalWrite(myPins[i], HIGH);
delayMicroseconds(5);
digitalWrite(myPins[i], LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(myPins[i], INPUT);
duration = pulseIn(myPins[i], HIGH);

// convert the time into a distance
cm = microsecondsToCentimeters(duration);

Serial.print(myPins[i]);
Serial.print(“-“);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();

int motorPWM = map(cm,maxDistance[i],0,0,maxPower[i]); //variable map formula relationship
motorPWM = constrain(motorPWM, 0, 255);

analogWrite(myMotors[i],motorPWM);

Serial.print(“motorPWM = “);
Serial.println(motorPWM);

delay(200);
}

}

long microsecondsToCentimeters(long microseconds)

{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}