Pages: [1]   Go Down
Author Topic: Lights and motion.  (Read 777 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is your LED wired?
Logged

"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.

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Was the LED described as a common anode device, by any chance?
Logged

"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.

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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°.
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* photo.JPG (27.82 KB, 320x240 - viewed 10 times.)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: