# Accelerometer code

**URL:** <http://community.robotshop.com/forum/t/accelerometer-code/8217>\
**Category:** General Discussions\
**Tags:** legacy\
**Created:** [May 1, 2010, 2:15pm UTC](http://community.robotshop.com/forum/t/accelerometer-code/8217 "2010-05-01T14:15:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandonv](http://community.robotshop.com/forum/letter_avatar/brandonv/32/6_449c533f586939b6e5f246632a46421f.png) [@brandonv](http://community.robotshop.com/forum/u/brandonv)\
**Post date:** [May 1, 2010, 2:15pm UTC](http://community.robotshop.com/forum/t/accelerometer-code/8217/1 "2010-05-01T14:15:58Z")

</div>

Hey guys,&nbsp;  
  
looking to control two servos (standard futuba hobby servos) from a adxl 335.  
  
I have all the mechanical and electrical systems ready im just trying to figure out the code.  
  
I have seen how to use the accelerometer to measure acc and just print to the serial on my pc, but how do i get those signals to control the position of a servo.  
  
Also, how would you go about adding the signals from two axis (ie sum up the values from the x axis and y axis, and have a servo respond to that new number)

I have also been having problems when trying to power the servos from an external source (other then the 5v and grd on the arduino, i am using a hobby battery and a 5V reg, but for some reason the servos stop responding to the code when powered this way.  
  
thanks for the help

---

<div class="post-metadata">

**Author:** ![amando96](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/amando96/32/36749_2.png) [@amando96](http://community.robotshop.com/forum/u/amando96)\
**Post date:** [May 1, 2010, 2:27pm UTC](http://community.robotshop.com/forum/t/accelerometer-code/8217/2 "2010-05-01T14:27:20Z")

</div>

**Are you**

Sharing grounds with the power supplies?&nbsp;

As for the code, never used it, you could try

&nbsp;

map(val, minimum adxl value, maximum adxl value, 0(for servos), 180(for servos));

myservo.Write(val);
