Go Down

Topic: Accelometer Question (Read 529 times) previous topic - next topic

Kobra299

Hello Firstly I am sorry if this is the Wrong Section I hope an Admin will move it to Right one

here is what I want to do using a Wii Nunchuck which has a built in Accelometer I want to make a Different LED come on when its tilted one way or the other but I am not sure how to do this with a Arduino Uno I have a Connector for it just not sure how ir would be coded as never done this kind of Sensor before

wwbrown

Remember Google is your friend, I googled 'arduino Wii Nunchuck' and got the following top hits
http://www.windmeadow.com/node/42
and closer to home
http://www.arduino.cc/playground/Main/WiiChuckClass

See if these help,

wade

If I understand correctly, I have done something similar once. What you need to do is learn what values define "level." Use the "pulseIn(pin,state)" command, where "pin" is the pin your accelerometer's x or y axis is on and "state" is the logic level (this is usually high, or "1"). After getting these values from using "Serial.println(pulseIn(pin,1))", use if then statements. I will give an example:
Code: [Select]

//this is to get the values of "level"

const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer


void setup()
{
   // initialize serial communications:
  Serial.begin(9600);
  // initialize the pins connected to the accelerometer
  // as inputs:
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
}

void loop()
{
  Serial.println(pulseIn(xPin,HIGH));
  Serial.println(pulseIn(yPin,HIGH));
  delay(500);
}


An example, with made-up numbers:
Code: [Select]

const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer
const int red_led = 4;          //connect red LED here
const int blue_led = 5;         //Blue LED here


void setup()
{
   // initialize serial communications:
  Serial.begin(9600);
  // initialize the pins connected to the accelerometer
  // as inputs:
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
}

void loop()
{
  if ((pulseIn(xPin,HIGH) > 10) and (pulseIn(xPin,HIGH) < 5000))
  { digitalWrite(red_led,HIGH); }
  else
  {digitalWrite(red_led,LOW);}
 
  if ((pulseIn(yPin,HIGH) > 1000) and (pulseIn(yPin,HIGH) < 1200))
  { digitalWrite(blue_led,HIGH); }
  else
  {digitalWrite(blue_led,LOW);}
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy