using accelerometer axis output varable as pwm motor speed setting?

I have the radio shack memsic dual axis accelerometer made by parallax model #mx2125 here[url=http://http://forums.parallax.com/showthread.php?76042-How-to-Accelerometer-%281%29-Fundamentals-and-Tilt-Measurement] http://forums.parallax.com/showthread.php?76042-How-to-Accelerometer-%281%29-Fundamentals-and-Tilt-Measurement[/url] I also have the grove motor shield (I do not recommend this product to anyone) here http://www.seeedstudio.com/wiki/Motor_Shield and arduino uno here arduino.cc and I am using 2 geared dc motors from a dollar store rc car

how do I change the pwm motor speed depending on the y axis out put from the accelerometer? for example. if output is 0 degrees then motor is off but from 1 degrees to 45 degrees the motor will be on and the higher the degree of angle, the faster the motor speed up to pwm max = 255? for 45 degree angle

and then to make it more confusing, I need to do the same for -1 deg to -45 deg but if the var is negative, then the motor needs to run backwards too.

can this be set up for smooth motor speed changes instead of jerking? you have probably guessed by now, yes. it is the self balance robot gimmick. I will make some pics of the hardware build so far.

seeed screwed me with the motor shield blocking all unused pins so I bought 2 mini breadboards and mounted the motor shield to that and ran jumper from that to my arduino so I could use the rest of my pins on arduino... seeed grove motor shield sucks.

I was thinking…
if (yaxis = 0 degrees)
{
forward pwmspeed = 0
}
if (yazis = 1 to 5 degrees)
{
forward pwmspeed = 10
}
if (yaxis = -1 to -5 degrees)
{
backwards pwmspeed = 10
}

and so on like this. but I think this would make the motors jerk like hell… how would I smoothly ramp the motor speed?

The motor shield should have a pin to set the direction, and a pin to enable movement. Conventionally you would use PWM on the enable pin to control the 'speed' of the motor. (It's not really speed that it controls, but that term'll do for now.)

If you start with a signed variable that holds the required speed then you need to test whether it's positive or negative to find the required direction, and then take the absolute value to find the required speed.

I don't know how well your algorithm is going to work. It seems to be based on the assumption that the accelerometer works as an inclinometer. The accelerometer can certainly be used like that when it is stationary, but not when it's accelerating - and yours will be accelerating sideways as the 'bot falls sideways. It may be possible to figure out a way to balance your 'bot from the accelerometer signal, but I don't know for sure. If it's possible, it's unlikely to be as straight forward as your design seems to assume. But give it a go - you lose nothing by trying.

according to the package info via radioshack,
measures rotation, tilt, acceleration, and vibration
dual and single axis sensing, +/- 3g on each axis

radio shack part #276-0029
memsic dual-axis accelerometer

and I do under stand that it is pulse width, and not speed.
such as 10% on and 90% off or other … I just used “speed” as that was the way it was labeled in the seeed sample code. but that is another problem… The seeed motor shield has a very limmited wiki and a horrible layout with no pin refrence diagram. I will never buy another one. So I don’t know what pin controls what.
[here is the link:](http://here is the link:)
http://www.seeedstudio.com/wiki/Motor_Shield
so you can see what I am talking about… they really suck. I had to mount it on 2 mini breadboards and run jumpers to it so I could use the blocked unused pins on arduino.