Show Posts
Pages: [1]
1  Using Arduino / Sensors / Lilypad Accelerometer ADXL335 Help on: March 29, 2011, 09:30:38 pm
Hi,

I have a Lilypad Arduino ATmega 328 and a Lilypad Accelrometer ADXL335.

I have used the example code to retrieve input values from the ADXL335 and that seems to be working fine.  When the ADXL335 is flat and stationary I am getting values around 512 for x and y, and 612 for z.

As a simple experiment, I am trying to get individual LEDs to light up depending on the tilt of the ADXL335.  I decided to start with the x axis.  When I tilt the ADXL335 away from me I get minimum values of about 370 and when I tilt it towards me I get maximum values of about 640.

The hardware is setup as follows:
xpin = A3
ypin = A2
zpin = A1
+ to + on lilypad
- to - on lilypad
xforward LED to 6
xbackward LED to 7

I have written some code in an attempt to get xforward to light up when I tilt the ADXL335 towards me and x backwards to light up when I title the ADXL355 away from me. However I am failing.  To test my connection I wrote an else statement to get the lights to blink. The lights just blink all the time, regardless of my xpin readings.

Any advice would be great.  Here is my code:


Code:
/*
 ADXL3xx
 
 Reads an Analog Devices ADXL3xx accelerometer and communicates the
 acceleration to the computer.  The pins used are designed to be easily
 compatible with the breakout boards from Sparkfun, available from:
 http://www.sparkfun.com/commerce/categories.php?c=80

 http://www.arduino.cc/en/Tutorial/ADXL3xx

 The circuit:
 analog 0: accelerometer self test
 analog 1: z-axis
 analog 2: y-axis
 analog 3: x-axis
 analog 4: ground
 analog 5: vcc
 
 created 2 Jul 2008
 by David A. Mellis
 modified 4 Sep 2010
 by Tom Igoe
 
 This example code is in the public domain.

*/

// these constants describe the pins. They won't change:
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models)
int xforward = 6;
int xbackward = 7;
int ledState = LOW;

void setup()
{
  // initialize the serial communications:
  Serial.begin(9600);
 
  // Provide ground and power by using the analog inputs as normal
  // digital pins.  This makes it possible to directly connect the
  // breakout board to the Arduino.  If you use the normal 5V and
  // GND pins on the Arduino, you can remove these lines.

  pinMode(xforward, LOW);
  pinMode(xbackward, LOW);
 
}

void loop()
{
  // print the sensor values:
  Serial.print(analogRead(xpin));
  // print a tab between values:
  Serial.print("x \t");
  Serial.print(analogRead(ypin));
  // print a tab between values:
  Serial.print("y \t");
  Serial.print(analogRead(zpin));
  Serial.println("z");
  // delay before next reading:
  delay(1000);
 
  if(xpin > 370 && xpin < 512){     //get xbackward to light up when tilt back
    digitalWrite(xbackward, HIGH);
    digitalWrite(xforward, LOW);
}

else if(xpin > 512 && xpin < 640) {   //get xforward to light up when tilt back
  digitalWrite(xforward, HIGH);
  digitalWrite(xbackward, LOW);
}

else {
  ledState = !ledState;              //get xforward and xbackward to blink
  digitalWrite(xforward, ledState);
  digitalWrite(xbackward, ledState);
}
}
2  Using Arduino / Sensors / Re: Lilypad Temperature Sensor. Help on: March 28, 2011, 11:34:31 pm
Thanks so much,

My temp sensor is returning much more consistent and accurate readings now using the code changes you suggested. 

It may also be that I am now in an airconditioned office where the temperature is regulated.

Now to write some code to do something with my temp inputs : )
3  Using Arduino / Sensors / Lilypad Temperature Sensor. Help on: March 28, 2011, 01:48:18 am
Hi,

I am using the Lilypad Temperature sensor with the Lilypad Arduino w/ATmega328.

At this point I am having difficulties getting a consistent reading of the ambient temp.  It jumps from as low as 15 degrees Celsius to 25 degrees Celsius. The actual temp should be 24 degrees Celsius.

My code is below.  Any help would be really appreciated!

Code:
//analog input 0/digital 14
int tempSenPin = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(tempSenPin, INPUT);
}

void loop()
{
  int reading = analogRead(tempSenPin);
 
  float voltage = reading * (3300 / 1024);
 
  float tempC = (voltage - 500)/10;
 
  Serial.print(tempC); Serial.println(" degrees C");

  delay(1000);
}
4  Using Arduino / LEDs and Multiplexing / Re: LEDs for Pin 10 and Pin 11 on: March 23, 2011, 06:12:39 pm
Thanks everyone for your replies.

Turns out sometimes you just need to have a good close look at your hardware.  There appears to be a small blob of solder that is joining pins 10 and 11.

I haven't seen this on any other lilypad.  It must just be a fault in mind!
5  Using Arduino / LEDs and Multiplexing / LEDs for Pin 10 and Pin 11 on: March 20, 2011, 11:57:33 pm
Hi all,

I must start by saying that I am very new to arduino.  I am using the Lilypad Arduino and am trying to get multiple LEDs to fade in and out. 

I have been pretty successful, however the LEDs attached to Pins 10 and 11 seem to mimic one another even if I try to program them to do different things, ie. fade in and out at different times.

Is this normal????

Ive written some code for LEDs attached to Pins 5,6,9,10 and 11 to fade in and then out all together, then to fade in and out one at a time. They all fade in and out together, however when it gets to fading them one at a time the LEDs on 10 and 11 don't do anything.

Any help will be really appreciated.

Here's my code:
Code:
// fading LEDs

int value = 0;

void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop()
{
  for(value = 0; value <= 255; value+=5)     // fade LEDs in
  {
    analogWrite(5, value);
    analogWrite(6, value);
    analogWrite(9, value);
    analogWrite(10, value);
    analogWrite(11, value);
    delay(30);                               // take 30 mili seconds to fade in
  }
  delay(200);                                // leave the LEDs on for 200 milliseconds


  for(value = 255; value >=0; value-=5)      // fade LEDs out
{
  analogWrite(5, value);
  analogWrite(6, value);
  analogWrite(9, value);
  analogWrite(10, value);
  analogWrite(11, value);
  delay(30);                                // take 30 mili seconds to fade out
}
  delay(1000);                              // leave LEDs off for 1 second


  for(value = 0; value <= 255; value+=5)     // fade LED 5 in
  {
    analogWrite(5, value);
    delay(30);
  }
   for(value = 255; value >=0; value-=5)      // fade LED 5 out
{
  analogWrite(5, value);
  delay(30);
}


  for(value = 0; value <= 255; value+=5)     // fade LED 6 in
  {
    analogWrite(6, value);
    delay(30);
  }
   for(value = 255; value >=0; value-=5)      // fade LED 6 out
{
  analogWrite(6, value);
  delay(30);
}


  for(value = 0; value <= 255; value+=5)     // fade LED 9 in
  {
    analogWrite(9, value);
    delay(30);
  }
   for(value = 255; value >=0; value-=5)      // fade LED 9 out
{
  analogWrite(9, value);
  delay(30);
}


  for(value = 0; value <= 255; value+=5)     // fade LED 10 in
  {
    analogWrite(10, value);
    delay(30);
  }
   for(value = 255; value >=0; value-=5)      // fade LED 10 out
{
  analogWrite(10, value);
  delay(30);
}


  for(value = 0; value <= 255; value+=5)     // fade LED 11 in
  {
    analogWrite(11, value);
    delay(30);
  }
   for(value = 255; value >=0; value-=5)      // fade LED 11 out
{
  analogWrite(11, value);
  delay(30);
}
}
Pages: [1]