Changes the Leds on self balancing robot

At first run, I see 3 leds on (2 reds and 1 green).
When I changed some line codes (adding bluetooth features) it stuck and got failed uploading the sketch. I remove all wires and restart my computer and finally I uploaded my codes without bluetooth code and wired them again.

But, I see only 2 leds on = led "on" and "L" - I don't see the other led (RX) on anymore.

My self balancing robot runs as I wished but I heard loud sound. I checked again wires and codes and everything is fine. What's wrong? please help.

Seriously?

deadly serious. wait. I want to upload the show

Do you think there's some more you need to be telling us?

I checked again wires and codes and everything is fine

Obviously not.

And we certainly want you to do that! Holding my breath...

1 Like

EDIT: Sorry, the HTML editor doesn't allow me to upload video. Here's the image.

That is not a useful post.

If you want help, after carefully reading the "How to get the best out of the forum" post:
post the code, using code tags,
post evidence for the error(s),
post a wiring diagram (photo of a clear, hand drawn diagram is fine).

1 Like

Here's the code I use:

#include "I2Cdev.h"
#include <PID_v1.h> //From https://github.com/br3ttb/Arduino-PID-Library/blob/master/PID_v1.h
#include "MPU6050_6Axis_MotionApps20.h" //https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050

MPU6050 mpu;

bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

double setpoint= 177.9;
double Kp = 21;
double Kd = 1.1;
double Ki = 60;

double input, output;
PID pid(&input, &output, &setpoint, Kp, Ki, Kd, DIRECT);
volatile bool mpuInterrupt = false;

void dmpDataReady(){
  mpuInterrupt = true;
  }

void setup(){
  Serial.begin(115200);
  mpu.initialize();
  devStatus = mpu.dmpInitialize();
  mpu.setXGyroOffset(220);
  mpu.setYGyroOffset(76);
  mpu.setZGyroOffset(-85);
  mpu.setZAccelOffset(1688); 
  if (devStatus == 0){
      mpu.setDMPEnabled(true);
      attachInterrupt(0, dmpDataReady, RISING);
      mpuIntStatus = mpu.getIntStatus();
      dmpReady = true;
      packetSize = mpu.dmpGetFIFOPacketSize();
      pid.SetMode(AUTOMATIC);
      pid.SetSampleTime(10);
      pid.SetOutputLimits(-255, 255);  
      }
  pinMode (6, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);
  pinMode (11, OUTPUT);
  analogWrite(6,LOW);
  analogWrite(9,LOW);
  analogWrite(10,LOW);
  analogWrite(11,LOW);
  }

void loop(){
  if (!dmpReady) return;
  while (!mpuInterrupt && fifoCount < packetSize){
      pid.Compute();    
if (input>150 && input<200){
  if (output>0)
      Forward();
  else if (output<0)
      Reverse();
      }
else
  Stop();
  }

mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
fifoCount = mpu.getFIFOCount();

if ((mpuIntStatus & 0x10) || fifoCount == 1024){
  mpu.resetFIFO();
  }
else if (mpuIntStatus & 0x02){
  while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
      mpu.getFIFOBytes(fifoBuffer, packetSize);
      fifoCount -= packetSize;
      mpu.dmpGetQuaternion(&q, fifoBuffer);
      mpu.dmpGetGravity(&gravity, &q);
      mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
      input = ypr[1] * 180/M_PI + 180;
      }
  }

void Forward(){
  analogWrite(6,output);
  analogWrite(9,0);
  analogWrite(10,output);
  analogWrite(11,0);  
  }
void Reverse(){
  analogWrite(6,0);
  analogWrite(9,output*-1);
  analogWrite(10,0);
  analogWrite(11,output*-1);  
  }
void Stop(){
  analogWrite(6,0);
  analogWrite(9,0);
  analogWrite(10,0);
  analogWrite(11,0); 
  }

and the circuit diagram:

ADDITION:
IT stucks after 2 minutes later and fall. Besides, It also does nothing when I plug 9volt adaptor and unplug and plug again and it runs extremely. I'm tired ... please

SOLVED! Stupid me, I found a wire from pinout INT (interrupt pinout of Mpu6050) to digital pinout 2 wired not properly (or, loosing). Thanks @jremington => I checked again as you said.

Now I can see the three leds "ON" again :star_struck: (I love it)

NB: I guess ... about 80% my project problem is wiring :rofl: By the way, I call my robot "Jimmy" (LOL)

Okay, thanks for all helps. best regards.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.