Why is my LED and pin 7 not working?

Im trying to make it so when the mpu6050 tilts past a certain threshold, it'll turn on the LED that I have plugged in to pin 7, but after awhile of trying I cant get it to do anything at all

#include <MPU6050.h>
#include <Wire.h>

const int ledPin = 7; //pin number for 3x LEDS

MPU6050 mpu;

void setup() {

pinMode(7, OUTPUT);

  Serial.begin(115200);

  Wire.begin();
  mpu.initialize(); //initializes the mpu... duh

  pinMode(ledPin, OUTPUT);

}

void loop() {

  digitalWrite(7, HIGH);
  

  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);

  float accelX = ax / 16384.0; //} VVVVV
  float accelY = ay / 16384.0; //} Converts the raw values to readable/more understandable ones
  Serial.print("X-axis=");
  Serial.println(accelX); //prints the X axis on the mpu
  Serial.print("Y-axis=");
  Serial.println(accelY); //prints the Y axis on the mpu


  if(accelX < 0.5) {
    digitalWrite(ledPin, HIGH);
  } else{
    digitalWrite(ledPin, LOW);
  }

  delay(50);
  

}

Is the LED stuck on? try commenting out (or remove it) this line "digitalWrite(7, HIGH);" in your loop.

What does that printout show?

it says next to it, prints the X axis on the mpu

I will try that now thanks :slight_smile:

Railroader is saying value are you actually seeing and if it ever goes below 0.5 to turn your LED off.

woops sorry misread that lol, yeah it prints below and above 0.5 to a max of about ~1

Just tried the LED again and its still not working

Post a schematic/picture or just a drawing is fine, maybe the LED is burned out.

1 Like

Just tested and I think its actually my arduino uno thats broken bc this worked when I tried it on a nano, thanks anyway lol :smiley:

1 Like

What "broke it" The same thing could also broke your Nano.

Do you have a series resistor connected to that LED?

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