Project With Xbees! Very Confused! Please Help!

Ladies and Gentlemen, before I begin, I would like to let you know that I am not very educated in Arduino, all I know is from various YouTube tutorials and Arduino forums, so please bear with me as I go through this project. Thank You.

I completed the construction of my project and seemed to work out perfectly in theory, but it did not work when ran. My project involves the communication of one Arduino Uno to another. 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 I am trying to finish by the end of January. 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.

Hey,

Welcome to the forum (sort of)!

Your first post looks good. Please use the code tags to enclose code. If your project doesn't work, which is always the case, you should try to troubleshoot it. Here are some general guidelines:

  1. Try the xbee modules to make sure that if the sender sends something, the receiver receives it.
  2. Try to program the sender to send a fake speed value (say send 5 for 10 seconds and 10 for 10 seconds etc.) and see how the receiver responds.
  3. Test the sender to see how kind of speed it is finding with some moderate walking

When you are trying to make a complex project work, always test the individual pieces first.

liudr:
When you are trying to make a complex project work, always test the individual pieces first.

Very good advice.

Write the smallest programs you can just to send the letter 'a' from one Arduino to the other.

...R

Another thing. Now that I'm home from work, I looked at your code. Your sender is printing an integer, i.e. into something like "100\r\n" but your receiver is expecting to read one character and receive the whole value. Plus, your "time" in sender is not defined.

o please bear with me as I go through this project. Thank You.

#7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html