A little help with the code?!

Hey all!

I have a question concerning code I am trying to develop for a motion sensor of sorts.

I am using a Arduino to read from ADXL345. I want to take a "sample" of the XYZ two times a second and compare the two samples. Ideally storing each of the two samples in a variable. I want to add in a sensitivity slider on my app that will allow me to make it more or less sensitive. This is what I have so far. I am attempting to utilize Blynk for app control...my problem relates to the error I am receiving on compiling which is Exit Status 1, 'x' was not declared in this scope on the line "adxl.readAccel(&x,&y,&z); " . Can someone assist me? I built this on top of existing working code that sampled the xyz one time, but adding a second time may have caused issue. There may be a better way to sample twice and compare, but I am having issues finding any hints.

int x1,y1,z1;
long sum1 = x1+y1+z1;
int x2,y2,z2;
long sum2 = x1+y2+z2;

long total = sum1-sum2;
if (total > sliderValue);
Blynk.notify("Disturbance Detected!");
Blynk.virtualWrite(V1, 255);
Serial.println("Disturbance Detected!");
digitalWrite(spkr_gpio, HIGH);
digitalWrite(spkr_gpio, LOW);

Your sketch is incomplete; please post the full code.

In the code snippet you posted, x, y and z are indeed nowhere defined. You do, however, have x1, x2 etc. Did you intend to use those, perhaps?

Do you realize that you're now in fact taking two samples 500ms apart, followed by a 1 second delay, so effectively 2 measurements every 1.5 seconds?

Finally, I think doing a one-shot measurement may be disappointing due to the inevitable noise/fluctuations. You'll probably have to do a couple of measurements each time and average them.

My code is actually very long, and consists of 11 tabs in total...if you count all the Blynk Edgent tabs that control the OTA, the communication between devices, and the settings. I suppose my question would be. If you wanted to know if motion occurred and have the ability to adjust sensitivity from very sensitive(a light breeze perhaps) to not so sensitive(a decent shake or movement) is there a better way to pull from the ADXL? I am looking into averaging to avoid noise, that is a great idea.

I am wanting to get away from relational data computations that seems to be messing with our dashboard. Thinking that it might be more code, but simpler to compute. So I was hoping to basically know if the device moves and have a slider to adjust how much movement before triggering an event or buzzer.

no body? (";")

how do measure sensitivity? have you considered short-term vs long-term values?

Please explain.

  int x1, y1, z1;
  adxl.readAccel(&x1, &y1, &z1);


  int x2, y2, z2;
  adxl.readAccel(&x2, &y2, &z2);

  // Deltas: Changes in acceleration
  // Using 'long' because they will be squared soon
  long dx = x1 - x2;
  long dy = y1 - y2;
  long dz = z1 - z2;

  // Sum of the squares of the deltas
  long movement = (dx * dx) + (dy * dy) + ( dz * dz);

  if (movement > threshold)
    // Something moved

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.