I am doing project to make led on and off if adxl x axis value is greater than 20.
here i want to make if x axis value is greater than 20 for more than 4 seconds only then led should turn on. else it should go be in off state.
can someone help me how this can be done.
#include <Wire.h>
#include <ADXL345.h>
ADXL345 adxl; //variable adxl is an instance of the ADXL345 library
int x;
void setup(){
Serial.begin(9600);
adxl.powerOn();
}
void loop(){
adxl.readAccel(&x); //read the accelerometer values and store them in variables x,y,z
Serial.print("x: ");
delay(1000);
Serial.println(x);
if (x>20)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}// raw data without offset
}
arduino wakesup if there is any interrupt change with the digital pin. this interrupt of digital pin made using adxl x axis value. if x axis is greater than 20 the digital pin 3 goes low else digital pin goes high.
the problem is after device is sending data one time if device goes to sleep the it is not wakes up to read adxl data. so i wnat to make adruni to read adxl data even in sleep mode. is this possible?
communication between two arduino is made using nrf24l01.