HOW to use SLEEP Mode in Arduino

First of all, sorry for my bad english.

Dear all of the advance programmer in this forum,

Hello guys, recently i’ve working on a project using Arduino UNO and inclinometer SCA100T to get the angle data using SPI. It’s feel difficult in the begining, but after search for many examples from this forum, and from other place, finally i made it.

but now, i want to use Arduino Sleep Mode in this project.

The idea is, i want the Arduino enter the Sleep mode after get the data(angle), and when i want to get the data again, the Arduino will wake up and send me the data again, and then enter sleep mode again, and so on.

Dose anybody know how the code for sleep mode that can be insert in my code ? so that my idea will work

this is where the data sheet of inclinometer that i used (SCA100T) if u want to see it :

http://www.mouser.co.id/ProductDetail/Murata-Electronics/SCA100T-D01-1/?qs=ez%2bYtvyjdJKWQmDQfYN2Tg%3D%3D

and this is my code :

#include <SPI.h>
/*
MEAS 00000000 Measure mode (normal operation mode after power on)
RWTR 00001000 Read and write temperature data register
RDSR 00001010 Read status register
RLOAD 00001011 Reload NV data to memory output register
STX 00001110 Activate Self test for X-channel
STY 00001111 Activate Self test for Y-channel
RDAX 00010000 Read X-channel acceleration through SPI
RDAY 00010001 Read Y-channel acceleration through SPI
*/

const byte MEAS = B00000000;
const byte RWTR = B00001000;
const byte STX  = B00001110;
const byte STY  = B00001111;
const byte RDAX = B00010000;
const byte RDAY = B00010001;

const int ChipSelect = 10;
const int DataInput = 11;
const int DataOutput = 12;
const int SerialClock = 13;
int sudutx, suduty;

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  
  //inisialisasi pin
  
  pinMode(DataInput, INPUT);
  pinMode(DataOutput, OUTPUT);
  pinMode(ChipSelect, OUTPUT);
  pinMode(SerialClock, OUTPUT);
  delay(500);
}

void loop()
{
    float xAxisData = readCommand(RDAX);
    float xAxisData1 = asin((xAxisData - 1024)/1638)*(180/3.14);
	 Serial.println("X Axis: ");
         Serial.println(xAxisData1);
  
    float yAxisData = readCommand(RDAY);
    float yAxisData1 = asin((yAxisData - 1024)/1638)*(180/3.14);
	Serial.println("Y Axis: ");
	Serial.println(yAxisData1);
  delay(1000);
}

word readCommand(byte Command)
{
  byte inByte = 0;
  word result = 0;
  digitalWrite(ChipSelect, LOW);
  delay(20);
  SPI.transfer(Command);
  result = SPI.transfer(RDAX);
  result = result << 8;
  inByte = SPI.transfer(RDAX);
  result = result | inByte;
  result = result >> 5;
  digitalWrite(ChipSelect, HIGH);
  return(result);
}

word readCommand1(byte Command)
{
  byte inByte = 0;
  word result = 0;
  digitalWrite(ChipSelect, LOW);
  delay(20);
  SPI.transfer(Command);
  result = SPI.transfer(RDAY);
  result = result << 8;
  inByte = SPI.transfer(RDAY);
  result = result | inByte;
  result = result >> 5;
  digitalWrite(ChipSelect, HIGH);
  return(result);
}

it will be my pleasure if u guys want to help me to solve this

Please use code tags when posting code. In the editor, it’s the </> button at the top left.

http://www.gammon.com.au/forum/?id=11497

oh sorry, i have change it and use the code tags, thanks

@pampambudi, have you considered doing a search? Before posting a question on the forums, it's recommended to first make some effort yourself. It took me less than 30 seconds to find this. Have you read it? :- Sleep

@OldSteve yes i have search but i think i still need more information about this, so i post it on this forum to gather more information, so have many source to start work on this project.

Your question was "Dose anybody know how the code for sleep mode that can be insert in my code ?"

The article I linked shows a method of coding it. Why not try the method(s) outlined, then post if you have problems?

No matter what, the code will need to be customised to suit your application, and if you make a start we can help if you have any problems. No one will simply write the code for you, and until you strike a specific problem, there's nothing we can really do to help.

@OldSteve oh okay, my apologize, i will not do that anymore, sorry once again. Maybe i'm too frustrated and confused with this project. But i will do my best, thank you very much for your information it's reall help :)

pampambudi: @OldSteve oh okay, my apologize, i will not do that anymore, sorry once again. Maybe i'm too frustrated and confused with this project. But i will do my best, thank you very much for your information it's reall help :)

No worries, and no need to apologise, but the best approach would be to study the examples that are on the 'Sleep' page, then have a go at it. We're always here if you have problems. :)

Try the Narcoleptic library.

https://code.google.com/p/narcoleptic/