How to stop my 'LED Shower head light', using acceleration sensor.

I made shower head light like attached images.

And I use references ‘’,’.

Here is my code I made.

const int analogPin1 = A1;   
const int analogPin2 = A2;   
const int analogPin3 = A3;   

const int ledCount = 11;    

const int groundpin = 18;             
const int powerpin = 19;              
const int xpin = A1;
const int ypin = A2;                  
const int zpin = A3;   

int ledPins[] = { 
  1, 2, 3, 4, 5, 6, 7,8,9,10,11, };   

void setup() {


  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW); 
  digitalWrite(powerpin, HIGH);

  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT); 

void loop() {

  int sensorReading = analogRead(analogPin1);
  int ledLevel = map(sensorReading,350, 380, 0, ledCount);

  for (int thisLed = 1; thisLed < ledCount; thisLed++) {
    if (thisLed > ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);


    else {
      digitalWrite(ledPins[thisLed], LOW);


I used adxl335, LED light and arduino UNO.

But problem is that my device works always. LED lights turn on all the time.

Because of acceleration sensor always measuring value, LED light always turn on.

I want to my light turns off until someone grab it.

How to I fix my code that I want to?

Please help me.

What do your debug prints tell you (and us) ?

There will be noise on the accelerometer output so the output will vary a little even when it is not moving. Sounds like you need to take the difference between two accelerometer readings and if that is over a certain threshold, then light the LEDs.

Accelerometers sense gravity. I only see one analogRead() in your code, you probably want to read all three axes and subtract gravity to get the magnitude of the remaining acceleration.