Example using the Acceleration & Tilt  Sensor for VEX
Go to Home Page

This page shows an example using the Acceleration & Tilt Sensor for VEX.                  

In this example you will make your robot go up a hill and stop at the top. It will use the the Accel/Tilt sensor to determine when it is going uphill and when it has reached the top. This is intended as a programming example only. You will probably need to modify the program to make it work with your robot.

First build a hill for your robot to climb. An easy way is to use cardboard as shown in the picture below. The one below has a flat cardboard box under the middle to hold it up.

Next find which side of the sensor will cause the channel #1 value to increase when you tilt that side up. . To do this connect the sensor to ports 1and 2 on the VEX computer analog/digital connector. Plug the sensor connector with a white dot into channel 1 on the VEX. Connect the VEX computer to your personal computer using the serial port cable. Start the “Intelitek EasyC for VEX” program. Click on the “Build and Download” menu and select “Terminal Window”. Select the “Online” tab. (You may need to download the online code) Turn on the VEX computer. It should now display all the port values. You may want to connect a touch sensor to make sure the program is working. Rotate the ACCEL sensor. You should see the values change in the windows for sensor 1 and 2. Place the sensor on a flat surface and then tilt it to lift one side. Watch the values in the terminal window. Find which side causes the channel 1 value to increase when you lift it. Mark this side of the sensor with a piece of tape.

Build a robot capable of going up the hill. Any robot will work for this example You can use a modified “square-bot” robot shown in the VEX documentation. In the photo below note one one pair of wheels is larger. If you use only small wheels on the square-bot, the gears will hit the edge of the cardboard as it reaches the top. Note that only one channel of the sensor is used. Be sure you use channel #1or have both channels plugged in if you are using channel #2. Also note the sensor has a small piece of foam rubber under it to help reduce vibration from the motors.

Write, compile, and download the program shown in the .pdf file below. This program assumes the robot is starting on a level surface. The program first looks for an increase in angle, indicating the robot is going uphill. Then it looks for a level reading. When it finds the level reading it turns off the drive motors. (When the robot is at the top of the hill it will be level)

The program uses a smoothing algorithm to reduce the detected vibration from the motors. This algorithm lets each sensor measurement change an "average" value by only 10 percent. You may want to change the percentage for better results with your robot.


Download the demo program flowchart in .pdf format


Download the Easy C code for the demo program.


Download the User's guide for this sensor.