Very Worried If This Will Work or Not

Hi, if anyone read my last post, this is pretty much a repost of it, and this time I have a different question. WILL THIS IDEA WORK? DOES IT WORK IN THEORY? I have no previous experience in Arduino, and am very very worried about this project. I completed it, but I still have yet to do some troubleshooting. Also, it would really help if anyone knows where I can find in-person help somewhere in Atlanta, Georgia, USA. THANK YOU VERY MUCH

One Arduino is hooked up to an MPU-6050 acccelerometer/gyro, while the other Uno is hooked up to a DC motor liquid pump. Each Arduino is hooked up to an Xbee shield and Xbee. The accelerometer should be practically attached to the hip, measuring walking/running speed, and then sends this speed to the motor which will translate these speed values to the motor speed. Head to the very end of the post to see the purpose of the project.

Before explaining what exactly the code does, I have included both codes below.

The Accelerometer Code constantly updates for spikes in x acceleration as one is moving forward (these spikes generally occur when the person makes a step), then through simple arithmetic, turns this into velocity which is measured in steps per minute.

Through the Xbees, the velocity is sent to the other Arduino with the motor, which simply maps the walking velocity to motor speed how I need it. Rest continues after codes.

Accelerometer Code:

// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  
  int timeMilliseconds = millis();
  int timeSeconds = timeMilliseconds/1000
  int steps;
  
  if(AcX > 100)
    {
      delay(50);
      steps = steps + 1;
    }
  int walkingSpeed = (steps/time);
  
  Serial.println(walkingSpeed);
  
  delay(200);
}

Motor Code:

const int motorPin = 3;
char incomingSpeed = ' ';
void setup()
{      
  Serial.begin(9600);
  pinMode(motorPin, OUTPUT);
}


void loop()
{
  while(Serial.available() == 0); {
          incomingSpeed = Serial.read();
          if(incomingSpeed <= 2.91){
            int speedMotor = map(incomingSpeed, 0, 2.91, 63.75, 255);
            analogWrite(motorPin, speedMotor);
          }
          
          if(incomingSpeed > 2.91){
            analogWrite(motorPin, 255);
          }

  }
   delay(200);
}

I purchased the Xbees from the Sparkfun website, and the shields from a seller in China from Ebay. I programmed these Xbees with PuTTY according to a YouTube tutorial from Jeremy Blum.

I made sure everything was correct according to the plan, and when I run it… NOTHING! I have pictures of my current setup, but they are too big for this forum, can someone please help me? I am Very Frustrated. Thank You Very Much!

This is a science fair project I am working on. It is made to improve the current temporary artificial heart design by implementing the factor of walking to the flow rate of the heart. So it is like basically having a pedometer on your hip measuring how fast you walk as your heart changes its flow rate accordingly.

Also please disregard some of the small syntax errors here and there, I have fixed those.

  while(Serial.available() == 0); {

Do you know what that does?

          incomingSpeed = Serial.read();
          if(incomingSpeed <= 2.91){

incomingSpeed is a type char variable that gets a char from Serial.read().
Since when do chars become floating point?

<= 2.91 works out to 0, 1 or 2.

I won’t even go into the delays. You have a lot to learn in a day or two but it’s possible.
Look into the first two links at the bottom of my post. See if anything clicks into place.

int speedMotor = map(incomingSpeed, 0, 2.91, 63.75, 255);
            analogWrite(motorPin, speedMotor);

The int in front of speedMotor stands for integer. Do you know what an integer is?

Delta_G: int speedMotor = map(incomingSpeed, 0, 2.91, 63.75, 255);             analogWrite(motorPin, speedMotor);

The int in front of speedMotor stands for integer. Do you know what an integer is?

Specifically, 16 bit signed integer.

As opposed to 8, 32 or 64 bit integers. As opposed to unsigned integers.

Maybe the floating point is in there to further slow the sketch down?

So are you saying that using the integer variable is too fast for the sketch, and is thus not allowing the information to be sent?

v-shee: So are you saying that using the integer variable is too fast for the sketch, and is thus not allowing the information to be sent?

No, I'm saying all those decimals in your numbers there are worthless and worse yet may be causing unexpected results. You are trying to store something with a decimal part in a variable called an integer. I ask again do you know what the word integer means.

Oh :stuck_out_tongue: (sorry if you were frustrated), I understand, so by rounding any integers should fix that problem? And about using character earlier in the sketch, what is the issue, and how can that be solved?

GoForSmoke:

  while(Serial.available() == 0); {

Do you know what that does?

          incomingSpeed = Serial.read();

if(incomingSpeed <= 2.91){




incomingSpeed is a type char variable that gets a char from Serial.read().
Since when do chars become floating point?

<= 2.91 works out to 0, 1 or 2.

I won't even go into the delays. You have a lot to learn in a day or two but it's possible.
Look into the first two links at the bottom of my post. See if anything clicks into place.

You mean this bit? Well, a char variable is one that can also only hold integers. Normally when things get sent over serial, they come in as ascii characters. So a Serial.read() will get you one of these ascii characters. If you sent over 2.91, tht gets sent as 4 separate characters, a ‘2’, then a ‘.’ then a ‘9’ then a ‘1’. You are only calling Serial.read() once. So you are only bringing in one character.

Now read that paragraph I just wrote. There are several reasons why that char you read can never possible be equal to 2.91. At best it could be equal to the ascii code for 2.