trying to make a pedometer with serial monitor and Arduino UNO

Using arduino uno, getting error message, seems to be a syntactic error...???

had a couple other drafts, in one I was able to read on my serial monitor "1" for still accelerometer and "11" for moving accelerometer (when code read steps + 1... :slight_smile: )

in another, I was able to read nothing for still accelerometer, and "1" for moving accelerometer

this draft won't compile successfully

I would like it to start at 0 on serial monitor, and increase by one each time accelerometer moves on any of 3 axis

Help is appreciated, go easy on me, im a beginner

this is my code - error message: expected ')' before 'x'

const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
int Steps = 0;
int x = 1;

void setup()
{
pinMode (xpin, INPUT);
pinMode (ypin, INPUT);
pinMode (zpin, INPUT);

Serial.begin (9600);
}


void loop()
{
int a = analogRead (xpin);
delay (500);
int b = analogRead (ypin);
delay (500);
int c = analogRead (zpin);
delay (500);

if (a < 678)
  {
    Serial.print (Steps ++x);
  }
if (b <= 464 )
  {
    Serial.print (Steps ++x);
  }
if (c <=4 )
   {
    Serial.print (Steps ++x);
   }
if (a >= 680)
  {
    Serial.print (Steps ++x);
  }
if (b >= 674)
  {
    Serial.print (Steps ++x);
  }
if (c > 6)
{
   Serial.print (Steps ++x);
}
}

Steps ++x is not a valid value or statement. Did you mean to increase x by one, and add it to Steps?

PS.: Karma++ for posting in code tags the first time.

yes

should have "steps" set equal to zero, and increase by one each time accelerometer moves

Then what is the function of int x ? As I understand, you could just increase Steps (Steps++) and print it, there's no need for int x at all.

I don't know. maybe that line shouldn't be there? I thought that would set the value of x equal to one for the point when its used in the ++x addition part. but you're saying ++x isn't valid...?

I made this all from scratch and I honestly don't know what im doing!

: (

I tried it as (steps ++)

now in the serial monitor its going: 01234567..etc without me moving the accelerometer

when I move the accelerometer its also adding three new integers at a faster speed than that

don't know what im doing!

I didn't either when I first played with an Arduino. :wink:

you're saying ++x isn't valid...?

No, I said Steps ++x is not valid.

I tried it as (steps ++)
now in the serial monitor its going: 01234567..etc without me moving the accelerometer

So we'll have to find out why that's happening.

Add these lines to void loop(), right before if (a < 678):

Serial.print(a);
Serial.print("\t");  // tab character
Serial.print(b);
Serial.print("\t");
Serial.println(c);  // println() moves the cursor to a new line after printing

Now, if you run the sketch, you can see the values of a, b and c, and deduct which part(s) of the code is/are causing the printing of 01234 etc....

the only problem is that the numbers are increasing without the accelerometer moving at all

the hope was that the count would increase by one each time the accelerometer moves...here its just going up automatically without moving the accelerometer at all

Oh! I see what you mean now!

great! it works!

THANKS for the help, its really appreciated as a novice trying to learn arduino and coding!!!

:slight_smile:

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