Using the Minimu 9dof v2 with the Arduino Mega 2560

So I've been running into small problems with my project. What I'm supposed to do is read data from the three sensors and have an LED change color based on the angle. When I plug in my Arduino Mega 2560, and the gyro to the SCL(21), SDA(20), VIN and GND pins, there seems to be a sensor working, however, when I unplug the sensor, the values keep doing what they did before. The power source that I'm using is the USB so yeah. Would the problem be something in my code, or is it more of a hardware issue? I can also send the code that I already have if that helps.

Thanks

koenigmax:
So I've been running into small problems with my project. What I'm supposed to do is read data from the three sensors and have an LED change color based on the angle. When I plug in my Arduino Mega 2560, and the gyro to the SCL(21), SDA(20), VIN and GND pins, there seems to be a sensor working, however, when I unplug the sensor, the values keep doing what they did before.

Are your inputs floating or tied to GND or 5V?

The power source that I'm using is the USB so yeah. Would the problem be something in my code, or is it more of a hardware issue?

Without your code, how can we tell? We're not mindreaders.

I can also send the code that I already have if that helps.

It would help us to help you.
Post your code using Code tags, the hash button above the input box.

This is the code that I made for this project:

int sda = SDA;
int scl = SCL;
int val = analogRead (sda);


void setup() {
  pinMode (13, OUTPUT);
  pinMode (sda, INPUT);
  pinMode (scl, OUTPUT);
  Serial.begin(9600);
  
  digitalWrite (13, LOW);
  
}

void loop() {
  
  int val = analogRead (sda);

  Serial.println(val);
  
delay (50);
}

You have to learn some basics about the Arduino.
Have you tried the blinking led example ?
Have you tried to read the voltage of a potentiometer with an analog input pin ?

The I2C bus is a digital bus. It uses a protocol with lots of '1's and '0's to communicate with sensors.

As soon as Wire.begin() fuction is used, the SDA and SCL pins (pin 20 and 21 for the Arduino Mega) are used for the I2C bus and can no longer be used for something else.

Sensor that are used with the I2C bus are 'digital' sensors. The software to interface those sensors is sometimes very complicated. For many sensors someone has read how to use them and written a library for it.

Is this your sensor board (the old one) ?

Or this one ? (version 2)

They have a level shifter on the board. So you can connect GND, 5V to VIN, SDA and SCL.
After that, run the i2c_scanner to see if all three sensors are detected.
http://playground.arduino.cc/Main/I2cScanner

So I ran the I2c code from this website you pointed me to. It turns out that this is what showed up:

I2C device found at address 0x19  !
I2C device found at address 0x1E  !
I2C device found at address 0x6B !

I'm not too sure how to interpret this code, but I'll most likely be able to find a place on the internet which has this.
By the way, thank you guys! This helped me get so far already

It means that all three sensor are found. That is very good.
So you IMU board is working and your I2C bus is working.

The I2C bus uses two wires (SDA and SCL) and can have many devices connected. Sometimes the devices are called "I2C slaves". Each device has an address. In your case there are three devices. One with I2C address 0x19, one with 0x1E, and one with 0x6B.

The next step is to use a library for the sensors. Pololu provides libraries for them, but I don't know if those libraries are good.
The best thing to do, is to create a few test sketches to test the sensors one by one.

I have tried the libraries from pololu, but it seems as though none of them worked. I looked at one of the .h files that was included in some of the files and none of them included the slaves or devices that were found by my computer. Do I need to create a separate .h file to use instead and then use it, or could I just create a plain sketch without the need for a programming language separate from Arduino.

Please tell more than "none of them worked". Tell us what you used and how and what the result was, perhaps even with screenshots of the error messages and so on.

Start for example with the lsm303.
Pololu has a library here: GitHub - pololu/lsm303-arduino: Arduino library for Pololu LSM303 boards
That library comes with a few examples. Try the 'Serial' example. It shows the x,y,z axis on the serial monitor.

This is a guide how to add libraries:

The I2C address is checked in the pololu library, in the file LSM303.cpp.
Your lsm303 chip should be detected.

You could continue with the pololu libraries, or try the Adafruit tutorial: