Go Down

Topic: Disabling the accelerometer (Read 581 times) previous topic - next topic

nagasaker

Feb 07, 2013, 09:55 am Last Edit: Feb 07, 2013, 10:22 am by Coding Badly Reason: 1
i want to disable the function of the accelerometer if I put an LED in A2 (analog output for Arduino Uno) which is in high condition... if it is low condition, the function of the accelerometer can function it back normally.. during high state i want the accelerometer to disable...
my problem is how to make a command to disable the function of the accelerometer... Is it possible to use an IF/ELSE statement here...
can anyone help me??? please...

this is the code for my accelerometer taken from the net...

Code: [Select]
const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
int xpin = A3;                            // x-axis of the accelerometer
int sensorValue = 0;                    // variable to store the value coming from the sensor

void setup()
{
 // initialize the serial communications:
 Serial.begin(9600);

 pinMode(groundpin, OUTPUT);
 pinMode(powerpin, OUTPUT);
 digitalWrite(groundpin, LOW);
 digitalWrite(powerpin, HIGH);
}

void loop()
{
 
 // read the value from the sensor:
 sensorValue = analogRead(xpin);    
 
 // print the sensor values:
 Serial.print(analogRead(xpin));
 // print a tab between values:
 Serial.print("\t");
 Serial.println();
 // delay before next reading:
 delay(100);
}



Moderator edit: [code] [/code] tags added.

Quick5pnt0

#1
Feb 07, 2013, 11:47 am Last Edit: Feb 07, 2013, 11:56 am by Quick5pnt0 Reason: 1
I'm not sure what you're trying to do. The LED has no way of turning off in your code so even if you programmed it to stop taking readings from the accelerometer it won't do anything. How were you planning to toggle the LED on and off?

Lets say you added a button or some other way to toggle the LED on/off then you could only take readings from the accelerometer when powerpin is LOW like this.

Code: [Select]
if (digitalRead(powerpin) == LOW)
{
Serial.print(analogRead(xpin);
}

holmes4

While A0 can be used as a DIGITAL I/O pin it can only do ANALOG INPUT. A link to the accelerometer you are using would be helpful.

Why do you want to disable it?

Mark

nagasaker

to Mark:

I am using right now an RF module... If I press the button of the remote of the RF MODULE which is "ON", I want to disable the function of the accelerometer... when it is turn off, I want to go back in normal the function of the accelerometer... just make an on and off to the accelerometer...

holmes4

So you wan't to talk to the Arduino with an RF remote control and then have it do something? Is this correct?

Mark

nagasaker

To mark:

yes it is... i want to communicate the RF module to the Accelerometer... what can i do to make it???


tack

Some Acceleromers have a Sleep (SL) pin, which I suppose you could activate.

As for 'turning' accelerometer off then surely you could just toggle a variable accell_active = 0|1 and then only read the inputs and use them if it's active.

Pseudo code

Code: [Select]

declare accell_active and set to 1 (on by default)

if remote control set accelerometer on then set accell_active to 1
if remote control set accelerometer off then set accell_active to 0

if accell_active is 1 then read the accelerometer pins and do any processing
if accell_active is 0 then don't read the accelerometer pins of do any processing

AWOL

Quote
While A0 can be used as a DIGITAL I/O pin it can only do ANALOG INPUT.

That doesn't make sense - "I/O" means "Input/Output".
A0 can be a digital input, a digital output or an analogue input.
"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.

Go Up