Go Down

Topic: Lights and motion. (Read 1 time) previous topic - next topic

Cadet

Hi there, I'm a beginner looking for a little help with making my RGB LEDs turn on when they're picked up.

I have programmed a spark fun ADXL335 accelerometer to sense when its being picked up and turn on the LEDs

Here is my code so far:

int sensorValuex = 0;  // variable to store the value coming from the sensor
int sensorValuey = 0;  // variable to store the value coming from the sensor
int sensorValuez = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(8, OUTPUT); 
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT); 
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  sensorValuex = analogRead(0); 
  Serial.print(sensorValuex);
  Serial.print(" ");
  sensorValuey = analogRead(1); 
  Serial.print(sensorValuey);
  Serial.print(" ");
  sensorValuez = analogRead(2);   
  Serial.print(sensorValuez);
  Serial.println(" ");

  if (sensorValuez >  440)
  {
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    delay(5000);     //this delays for 5 seconds
  }
  else
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
   
   
  //digitalWrite(8, HIGH); 
  //digitalWrite(8, LOW);   
  //digitalWrite(9, HIGH); 
  //digitalWrite(9, LOW);   
  delay(10);                 
}



So far it has worked with a single colour LED but the RGB LED seems to do the exact opposite of my programming, it stays on until it's picked up.

Can anyone tell me where I'm going wrong?

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Cadet

The RGB LED didn't work when I wired the resistors to ground but oddly (or maybe not oddly) it worked when I wired it to 5V or AREF

I wired the R G & B pins to 8,9, and 10.

AWOL

Was the LED described as a common anode device, by any chance?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Cadet

It's described on the Maplin's site as a Full colour red lamp with a standard 6-pin DIP design which contains 3 ultra bright LED chips (RGB) within one package to produce various colours in the visible spectrum, including white light, with a wide viewing angle of 100°.

Cadet

This is the link to the most in depth description of the LED:

http://www.maplin.co.uk/rgb-full-colour-led-35893

AWOL

The little 6 pin 2mm pitch, white DIL package thing?

OK, so you've got the anodes tied to 5V, and the cathodes via resistors to the pins?

So, if you write a HIGH to a pin, you don't light the LED, if you write a LOW, you do light it?

That's what I would expect.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Cadet

I've wired the resistors to 5V, yes, and the RBG pins to pins 8, 9, 10 on the Uno

You can make it out in the images, the resistors are bunched together and wired to 5V and each of the R G B pins on the LED are wired to  8 9 and 10 respectively.

AWOL

Unfortunately, the orientation marks are on the top of the LED, so I can't really tell anything worthwhile from that photo.

So "if (sensorValuez >  440)", the LEDs go out?
Is that what you see?
That is what I would expect, because if that condition is true, you're writing HIGH to the LED pins.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Cadet

... Thanks for the info, it's all fixed now, i think the pressure of the deadline is liquifying my brain.

Go Up