I made shower head light like attached images.
And I use references ‘http://arduino.cc/en/Tutorial/BarGraph’,
‘http://arduino.cc/en/Tutorial/ADXL3xx’.
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() {
Serial.begin(9600);
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() {
Serial.print(analogRead(xpin));
Serial.print("\t");
Serial.print(analogRead(ypin));
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
delay(100);
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.