Further debugging with BELT_02 code

I created a testing rig with 2 Sensor+Motor+LED groups to test this code. At first they worked well and as expected. Then I decided to add another sensor+motor+LED group. The outcome did not follow the initial test with two groups. The set-up seemed to struggle as there seemed to be a power problem.

Like with the belt test, there was one group that was seemingly vibrating on its own. Potentially there is a need to isolate the power to the motos, or experiment with different code. As my coding skills are weak, I cannot see how I can modify my code further to solve this problem.

From this point, I will also begin to CAD and create what I need for an module.

HPB first wear/test

Using BELT_02 code I managed to get all four sensors and motors to work, as I realised my error with my initial attempt (failing to map all values of distance and power).

There are 4 sensor and motor combinations/groups, I labeled them FL, BL, FR, BR. [F = front; B = back; L = left; R = right]. The coupling/mapping was direct – vibration was coming from the point of distance detection.

Initially FR was only sensing and vibrating, after the code review and update all 4 groups were sensing and vibrating. However, only the BR motor kept vibrating the most and consistently. I also noticed a considerable delay when each sensor was activated.

The vibration strength varied based on the shroud’s effectiveness – the shrouds were made from straws with the motors inserted into them, this is low cost and fast way to allow the asymmetrical weight rotate. In effect the shrouds were failing and not allowing the motors to rotate, thus preventing any form of vibration. 

The code and potentially the wiring needs further debugging. I’m using jumper cables left right and centre! which is fine for a quick and dirty prototype but very messy when trying to debug. If time allows, a revisiting of the code and custom connectors/lengths of wire to make it work better and neater. 

I will revisit the Project HALO code from Instructables and see what I can do with that, I believe it deals with the sensing and motors in more of a clock fashion. Power seems to be another issue I’m facing. So far I’ve connected a battery directly to the Arduino Mega 2560, but Project HALO advises this: 

“a 5v regulator is connected to the 9v terminals and this is sent to drive the Darlington IC (and in turn, the motors) so we have 2 power systems and the Arduino is isolated”

 

Parts list:

  • Arduino Mega 2560
  • 3v Vibration Motors: 256382 from Jameco.com
  • HC-SR04 Ping Sensors
  • Bread board
  • Development Shield for Arduino Mega
  • Custom 4-to-3 connectors
  • Zip-ties
  • Electrical/Duct tape
  • Velcro Tape
  • Male-to-Female, Female-to-Female, Male-to-Male jumpers 
  • Old belt

 

More to come…

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;
}