Programming accelerometer

Hi, i’ve been reading up on Analog accelerometers (one sold on the vex website) since i got mine, but i still dont have a clue how to program for it
so far i understand what Quazar once said about the 3 axis and output thing, large values for it mean acceleration and low ones decceleration, that if on it side it will read gravity, and that i use analog stuff in easyC for it…

I was wondering, since there is no inventors guide/other info given by vex when you get it, if someone could help me out with some basics about programming for it or if someone could think up a sample program i could toy with.

Thanks in advance:)

If you have an idea how top read the outputs, then you’ve got a good head start.

I strongly recommend just attaching the accelerometer to a bar of vex metal, and writing a simple program that takes the analog value, divides it by 4 and feeds it to a servo (in a loop). Then you can play around with it and get a good feel for how it reacts to various movements.

Of course you can do the same thing by watching the analog readings in the On-line Window, but I like to positional feedback you get from watching a servo move.

Do you have something in mind that you want to accomplish with the accelerometer? If so, we might be better able to provide better information. Here are a few ideas:

*]Automatic front/back correction for a “flip bot”
*]Tilt sensor
*]Impact detector
*]Distance calculation based on X/Y acceleration
*]Balance bot (very advanced)


  • Dean

Interesting, how would this be accomplished? Wouldn’t a compass be more useful when trying to determine whats going forward and whats going backward.

This sounds like a very fun project, but I still have not gotten around to it. Remember along with an accelerometer, a gyroscope would be also needed to keep the robot in an upward position.

Good for competition code and such…

Personally, this is the most interesting use of the accelerometer by far! Through physics equations or integrals you can obtain the velocity of the robot (1st integral) and the displacement of the robot (2nd integral)… This would open up a whole new world for programmers in autonomous mode! Think mapping of field…


Well, a “flip bot” will operate even if flipped upside down (typically they look a lot like the “Tumbler” robot design). Some motor controllers like the Sabertooth 2X5 actually have a flip channel input, and will automatically remap the driving controls based on this input.

If the robot is completely symmetrical and doesn’t have a designated front and back, then you don’t need to know which side is up at any given time - the controls all map correctly either way.

However, if your robot has a front (say, you’ve added a claw to the front), then you need to remap the controls when it flips upside down. Typically, drivers just use an extra channel on the remote to toggle the up/down orientation, but having it switch automatically based on gravity might be a nice time saver.

This would be a pretty simple first project for the accelerometer, but it is only interesting if you have (or want to build) a flip-bot. If you do make a flip bot, remember to plan for antenna placement - it can be tricky.

Yep, though I think it would be possible to do a different project I’ve had in mind with just the accelerometer:

Build a robot with a gimbal platform driven by servos. Design a control loop that tilts the platform based on acceleration so that a ball placed on the platform won’t roll off while the robot is maneuvering (or a glass of water won’t spill).

An easier first step would be to try this in 1 dimension only. In other words, build a robot that can’t steer - just accelerate and decelerate along a straight line. Then the gimbal platform only needs one servo to keep it aligned.


  • Dean

Well, in programming, i like the idea of a certain function continuing until a certain goal is reached, like having my bot’s arm move until the encoder reads 30, etc.
So, with the accelerometer i want to have it run the driving motors until a certain distance is reached (I’m just trying to move from one goal to the other)
I know this is very possible with just guess work and knowing your bot’s speed and doing that simple math, but i’d still like the experience with more advanced programming than what i’ve done up to this point.
And, i want to get my money’s worth from that $40 black microchip :stuck_out_tongue:

I greatly appreciate the help:)

In Robot C, do you take in the Accelerometer Values as just Raw Values? I think those are the analog outputs.

I keep getting a value of 0 for y, and 1 for x & z, but that can’t be right!
When I change the z value to read another input type like reflection the raw data for x reads in properly but the y axis maintains a 0 value!
I’ve changed the cable and such, no simple solution exists :frowning: