Вы находитесь на странице: 1из 36

HEAD MOVEMENT CONTROLLED ELECTRONIC WHEELCHAIR

FINAL YEAR PROJECT REPORT

SUBMITTED BY

Muhammad Ather Tayyab 2012207

Muhammad Bilal 2012210

Saim Ali 2012335

Advisor: Prof. Dr. Habibullah Jamal

Co-Advisor: Dr.Dur-e-Zehra Baig

Faculty of Engineering Sciences

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology

Topi, District Swabi, Khyber Pakhtunkhwa, Pakistan

I
ACKNOWLEDGEMENTS

A project report of this breadth and scope could not possibly be assembled by a group of

undergraduate students working alone, and so a number of words of thanks are in order.

First of all, we would like to thank God Almighty for bestowing us energy and will that enabled

us to compile and produce this report.

Next we would like to thank Prof. Dr. Jameel-Un Nabi, Dean Faculty of Engineering Sciences

GIK Institute for approval of our project. We also thank Prof. Dr. Habibullah Jamal our final

year project supervisor who helped us in every difficulty which we faced while completing this

project. He always encouraged us in problems solving during the project. We would also like

to acknowledge the help of Dr.Dur-e-Zehra Baig and Eng. Eram Asghar in mechanical related

part of our project.

Last but not least we want to thank to our Final year project coordinator Mr. Naveed Azam in

guiding us through the timeline so that we are able to manage our presentations, completion of

project and report submission in time.

At the end we would like to extend our gratitude towards whole faculty. They point out our

mistakes and lacks during presentations and enabling us to improve our project.

Finally we thanks our parents and friends for their support and encouragement without we are

not in a position to make this finished product.

II
ACHIEVEMENTS

Industrial Open house

This project was presented at the industrial open house 2016 at Ghulam Ishaq Khan Institute

and has been awarded 2nd position in faculty of Engineering Sciences.

Commercialization

After completing of our project we took initiatives on commercializing this product in Pakistan.

As this product is not available in market and also not being commercially manufactured. This

project has been presented to HARS and UM surgical Instrument traders and they agreed to

commercialize our product.

III
ABSTRACT

Head movement electronic wheelchair is a basic wheelchair which is modified into two modes

i.e. either manually or by following the motion of the head. This type of wheelchair is designed

for those patients who are unable to move their limbs and are dependent on care takers for their

movement. So our projects solves the problem to some extent. The head set is made up of

inertial measurement unit (IMU), which sends the position of the head to the microcontroller

Arduino mega 2560. The controller then follows a control algorithm and sends the commands

to the motor driver H-bridge circuit to drive the motors accordingly. Old homes, hospitals and

bed ridden soldiers are the application of this type of wheelchair.

IV
Table of Contents

ACKNOWLEDGEMENTS ....................................................................................................... I

ACHIEVEMENTS .................................................................................................................. III

Industrial Open house .......................................................................................................... III

Commercialization ............................................................................................................... III

ABSTRACT .............................................................................................................................IV

Chapter 1 INTRODUCTION ..................................................................................................... 1

1.1 Block Diagram ............................................................................................................ 2

Chapter 2 LITERATURE REVIEW .......................................................................................... 4

2.1 Stages of paralysis ....................................................................................................... 4

2.2 Types of paralysis........................................................................................................ 4

2.3 History ......................................................................................................................... 5

2.3.1 Manual Wheelchair.................................................................................................. 5

2.3.2 Electronic Wheelchair ............................................................................................. 5

2.3.3 Eye Ball controlled Wheelchairs ............................................................................. 6

2.3.4 Hand Gesture Controlled Wheelchair...................................................................... 7

2.3.5 Voice Recognition Based Wheelchair ..................................................................... 7

Chapter 3 PROJECT DESIGN .................................................................................................. 8

3.1 Standard Wheelchair ................................................................................................... 8

3.2 Specifications of Motors ............................................................................................. 9

3.3 Electrical components ................................................................................................. 9

V
3.4 Mechanical Assembly ............................................................................................... 11

3.5 Gear ratio ................................................................................................................... 14

3.6 TORQUE ............................................................................................................... 15

3.7 FORCE .................................................................................................................. 15

3.8 Inertial Measurement Unit (IMU) ............................................................................. 16

3.9 Microcontroller interface........................................................................................... 17

Chapter 4 WORKING OF PROJECT...................................................................................... 19

4.1 Working Principle ..................................................................................................... 19

4.2 Control Algorithm ..................................................................................................... 21

CONCLUSION AND FUTURE WORK ................................................................................ 22

Conclusion ........................................................................................................................... 22

Future Works ....................................................................................................................... 22

Controlling of speed ......................................................................................................... 22

Obstacle detection system ................................................................................................ 23

Health monitor ................................................................................................................. 23

REFERENCES ........................................................................................................................ 24

Appendix .................................................................................................................................. 25

VI
Table of Figures

Figure 1 Block Diagram............................................................................................................. 3

Figure 2 Manual Wheelchair ..................................................................................................... 8

Figure 3 Motor Drive Module.................................................................................................. 10

Figure 4 50 A Dual H-Bridge ................................................................................................. 11

Figure 5 Helical Gears ............................................................................................................. 12

Figure 6 Gear Assembly .......................................................................................................... 13

Figure 7 Complete Mechanical Design.................................................................................... 14

Figure 8 Gear Assembly .......................................................................................................... 14

Figure 9 IMU Sensor ............................................................................................................... 16

Figure 10 Headset Assembly ................................................................................................... 16

Figure 11 Movement Commands............................................................................................. 21

VII
Table of Tables
Figure 1 Technical specs……………………………………………………………………11
Figure 2 Microcontroller specs……………………………………………………………..18

VIII
Chapter 1

INTRODUCTION

This wheelchair is specially designed for those patients who are unable to move their limbs

except their head. This wheelchair is operated by detecting the motion of the head and

providing such paralysed patient, a certain degree of independence and freedom in their

movement. We used accelerometer, one of the components of the inertial measurement unit

(IMU). Accelerometer detects the orientation of the head and send signals to the micro-

controller which is Arduino mega 2560.

The design we proposed is cost effective and simple. No specific calibration is required before

use. Additional characteristic of wheelchair in the hardware design is that it can be operated in

2 modes i.e. either manually or by using patient head.

Standard wheelchair has been purchased from the market and modified mechanically by

applying helical gears which are coupled with the motors. These gears can be attached and

detached according to the patient’s requirement and that can be done by simply unscrewing a

bolt at the back of the wheelchair.

The main objective is to convert a normal wheelchair available in market into an electronic

wheelchair controlled by head which is not being manufactured in Pakistan commercially.

1
1.1 Block Diagram

Block diagram represents the main components and basic functioning of our project.

The inertial measurement unit is mounted on the headset. Headset consist of four main parts

including pressure sensor, three-axis gyroscope, triaxis accelerometer and 3-axis magnetic

field. We are only using accelerometer in our project.

Accelerometer detects the orientation of the head and sends raw value signals to the micro-

controller which is Arduino mega 2560. It provides ten degree of freedom to the user for the

measurement of a body. Arduino process the information according to control algorithm we

proposed. The processed information is send to the H-bridge to drive the motors accordingly.

If the person moves head towards right the wheelchair right wheel stop and left wheel began

to move hence wheelchair moves in the right direction. If the person moves head towards left

the wheelchair left wheel stop and right wheel began to move hence wheelchair moves in the

left direction. If the person keep his head straight wheelchair both wheel halts and hence it

stops. If the person bend his head forward both wheels began to move and hence wheelchair

began to move in forward direction.

2
Figure 1 Block Diagram

3
Chapter 2

LITERATURE REVIEW

After introduction, now we look into the development that has been made in technology related

to health sector. Design of different types of wheelchairs has been proposed for the disabled

person to provide some degree of independence in their movement. Manual, hand, voice

recognition, head movement and eye ball movement controlled wheelchairs have been

developed yet for the patients

2.1 Stages of paralysis

Following are the reasons for paralysis

 Accidents

 Injuries on spinal cord

 Stokes

2.2 Types of paralysis

Paralysis types are:

 Quadriplegia: Paralysis are due to spinal injury that results in disability of all four

limbs. This type of paralysis also result in tetraplegia, which leads to the loss of

sensation and movement in three limbs. This the worst case in which paralysis patient

is not able to move his limbs.

 Paraplegia: Paraplegia type of paralysis which incurred due to injury in the thoracic

vertebra causing loss of movement in both legs.

 Monoplegia: Monoplegia is type of paralysis incurred due to injury in spinals which

affects only one of the limbs and also affect nervous

4
 Diplegia: Diplegia is type of paralysis which affects only symmetrical parts of the

body, normally both of the face or two sides of the hands or legs.

 Hemiplegia: Hemiplegia is type of paralysis which results in loss of only one side of

the body.

Above discussed paralysis are caused due to brain stroke, clots in specific parts of brain. Due

to increased road accidents peoples are becoming severe victim of spinal cord injuries. Soldiers

get injured in war or from frost bites results in loss of both hands and legs.

2.3 History

Concerning human disability following wheelchairs has been developed

 Manual wheelchairs

 Electronic wheelchairs

 Hand gesture controlled wheelchairs

 Voice recognition controlled wheelchairs

 Eye ball controlled Wheelchairs

2.3.1 Manual Wheelchair

The cheapest of all wheelchairs available for those patients, who are unable to move their lower

limb or cannot walk properly without any assistance or support. These type of wheelchairs are

used by patients having lowest or first degree of paralysis.

2.3.2 Electronic Wheelchair

These type of wheelchair are made for those patients who are unable to move wheelchair

manually. These electronic wheelchairs are driven by motors and are powered by batteries.

5
“ In [1],Electric power wheelchairs are cost-effective chairs designed for quadriplegic

patients who cannot use joystick. It is a wireless system controlled by neck movement of

person. This Proposed chair can be operated in almost all kinds of environments as these

components are less sensitive to environmental variations.”

2.3.3 Eye Ball controlled Wheelchairs

Eye sensing wheelchair works on the principle that wheelchair is driven by the movement of

the eye. If eye move towards left wheelchair must move towards left and similarly if eye move

towards right it must move towards right and so on. Camera is mounted on headset focusing

on the person eye. Video of the movement of eye ball is made for specific time interval and

then snapshots are drawn from that video. In the Matlab these images are compared to get the

movement of the eye ball. Then Matlab sends command serially to Arduino and then it sends

command to H-bridge to drive the motor according to the directed motion.

“From [2] In this paper, we use the optical-type eye tracking system to control powered

wheel chair. User‘s eye movement are translated to screen position using the optical type eye

tracking system. When user looks at appropriate angle, then computer input system will send

command to the software based on the angle of rotation of pupil i.e., when user moves his

eyes balls up (move forward), left (move left), right (move right) in all other cases wheel

chair will stop. Once the image has been processed it moves onto the second part, our

microprocessor. The microprocessor will take a USB output from the laptop and convert the

signal into signals that will be sent to the wheelchair wheels for movement. The final part of

the project is the wheelchair itself. The rear wheels will provide forward. The front two

wheels will be used for steering left and right. All four wheels will be connected to our

microprocessor that will send signals to control the wheels and thus the overall movement.”

6
2.3.4 Hand Gesture Controlled Wheelchair

This type of wheelchair is driven by the direction guided by the motion of the sensor attached

on the hand. Accelerometer is used to detect the orientation of the hand and corresponding

signals are sent to the controller to drive the motors in the desired direction.

As suggested by the papers:

“In [3], This paper is to develop a wheel chair control which is useful to the physically

disabled person with his hand movement or his hand gesture recognition using Acceleration

technology. However, even these significant advances haven’t been able to help

quadriplegics navigate wheelchair unassisted. It is wheelchair which can be controlled by

simple hand gestures. It employs a sensor which controls the wheelchair hand gestures made

by the user and interprets the motion intended by user and moves accordingly”.

2.3.5 Voice Recognition Based Wheelchair

Voice recognition wheelchair moved with the help of voice commands. For example if patient

says forward wheelchair must move forward and similarly if persons says stop wheelchair must

stop. This type of wheelchair is specifically designed for those patients who are only able to

speak rather than moving any other part of the body. The drawback of this proposed design is

that it will not work properly in noisy environment. In addition different accent is also a

problem in using this type of wheelchair.

As published in a research article, the project suggested:

“In [4], This paper describes a wheelchair for physically disabled people. A dependent-user

recognition voice system and ultrasonic and infrared sensor systems has been integrated in

this wheelchair. In this way we have obtained a wheelchair which can be driven with using

voice commands and with the possibility of avoiding obstacles and downstairs or whole

detection. Moreover, Arduino boards have also used for voice recognition.”

7
Chapter 3

PROJECT DESIGN

3.1 Standard Wheelchair

Figure 2 Manual Wheelchair

The quality of our project design is that any standard wheelchair available in the market can be

converted into an electronic wheelchair. In our project we purchased a standard light weight

wheelchair from the market. We welded a steel plate at the back of the wheelchair so that

motors can be attached on this steel plate. Also a steel plate in the front bottom is welded to

place the electronic components and batteries. After welding these plates the folding features

of the wheelchair has been eliminated.

8
After this welding process, the frame of the wheelchair became misaligned and it required

enough time and effort to realign the frame and maintain the stability. We repainted the

wheelchair to cover the welded parts and steel plates.

3.2 Specifications of Motors

We did research and perform calculations regarding the motor specification to be used in our

project. We come up with decision that two permanent DC motors having 24V 120W and 5

ampere rating and RPM 180 should be used. The reason behind selecting high power rating is

because we want our wheelchair to move smoothly on rough surface or terrains. Gear ratio 1:6

is used providing us enough torque to move the wheelchair smoothly from stationary position

without jerks. Furthermore in order to have smooth motion and lesser noise we use helical

gears instead of spur gears.

3.3 Electrical components

Two lead-acid batteries connected in series to make total of 24 voltage, which is the

requirement of our design. These two batteries have specification of 12 V 4.2 Ah with a starting

current approximately 4A. Motors attached to these batteries drive the wheelchair according to

the input command. These batteries also provide the power to electronic components which

includes Arduino Mega 2560 controller and the Motor driver circuit (H-bridge circuits).

The function of the H- Bridge is to drive the motors in both clockwise and anticlockwise

direction. As to move the wheelchair in forward direction both the motors should run in same

forward direction, and to move wheelchair in right direction the left motor should rotate

anticlockwise and right motor clockwise. In this way couple will be provided to the wheelchair

and it will turn towards left. So to move the wheelchair right, the left motor should rotate

clockwise and right motor anticlockwise.

9
Figure 3 Motor Drive Module

The H-bridge we used is Dual channel – dual motor driver module. This motor driver works

with single channel max 50A load capacity. So the advantage of using this motor driver module

is that it will not burn out easily because of its higher specifications and rather than using two

h-bridges , our work is being done by only one module, as both the motors are being controlled

by a single H-bridge circuit.

10
Figure 4 50 A Dual H-Bridge

A and B are the two outputs for the two motors. The power vcc pins are attached to battery

where 24 V are provided to the H-bridge, which are being transferred to the motors. The control

vcc is connected to Arduino, from where the signal or command is transferred to the h-bridge

to control the motors accordingly. To move the motors in forward direction the LPWM pins

are set HIGH and if we want to move the motors in reverse direction RPWM pins are set HIGH.

1 Weight Capacity 100kg

2 Maximum Speed 1 m/s

3 Diameter of Wheelchair Wheel 0.6 m

4 Battery Charger 5A 12 V

5 Battery for motors 12 V 4.5 Ah

6 Battery for electronic components 12 V 4.5 Ah

7 Motor 120W 24 V

8 Batteries run time on full load 3 hours

9 Current drawn on full load 4A

Figure 1 Technical specs

11
3.4 Mechanical Assembly

Two types of gears most widely available and used in Pakistan are spur and helical gears. Gears

having straight teeth are known as spur gears and they can be fabricated easily. Teeth of the

helical gears are at an angle and are difficult to make in comparison to spur gears. Helical gears

have advantage over spur gears because of the fact that they make less noise.

Figure 5 Helical Gears

Helical gears teeth engage smoothly and gradually but they are less efficient than spur gears.

Helical gears are more durable and run smoothly on high loads. Friction is greater in spur gears

and because of this they wear out quickly as compared to helical gears. Considering these facts

helical gears are chosen in our mechanical design. Gear ratio was set 1:6 means driving gear

has one third the teeth as the driven gear. So basically gears are being used to reduce the

revolutions of the motor which was 180 revolutions per minute, which was too much for the

wheelchair to move directly with the motors without using gears. This gear ratio was chosen

keeping in mind the safety feature along with the required speed. Considering the weight of the

12
wheelchair accompanied with electrical and mechanical components and weight of the person

gear ratio was set to obtain torque according to our requirement.

Figure 6 Gear Assembly

Mechanical design of wheelchair has been modified in such a way that gears between motors

and shaft can be attached and detached according to user requirement.

13
Figure 7 Complete Mechanical Design

This has been done by attaching both motors on single plate attached to the main frame of the

wheelchair and bolt is used to lose or tighten the plate hence changing the gear position

3.5 Gear ratio

Figure 8 Gear Assembly

14
RPM of motor = 180 rpm = 18.85 rad/ sec

Required wheel velocity = 1 m/s

Radius of wheel = 0.303 m

Angular velocity of the wheel = 𝑣𝑡 /𝑟𝑡 =3.3 rad/ sec

𝑤𝑡 /𝑤𝑔 =3.3 rad/ sec

𝑟𝑔 𝑤𝑔 = 𝑟𝑚 𝑤𝑚

𝑟𝑔 /𝑟𝑚 = 𝑤𝑚 /𝑤𝑔 = 18.85/3.3

= 5.7≈ 6

So approximately the gear ratio is 1:6

3.6 TORQUE

𝑃
𝜏=
𝜔
120 𝑊
𝜏=
3.3 𝑟𝑎𝑑/𝑠

𝜏 = 36.36 𝑁. 𝑚

The electric motor provides a torque of 36.36 N.m at 3.3 rad/s to each wheel of the wheelchair.

3.7 FORCE
𝜏
𝐹=
𝑟
36.36 𝑁. 𝑚
𝐹=
0.303 𝑚

𝐹 = 120 𝑁

For a torque of 36.36 N.m, a force of magnitude 120 N acts on each wheel of the wheelchair.

15
3.8 Inertial Measurement Unit (IMU)

Figure 9 IMU Sensor

The inertial measurement unit was placed on a headset. The module was fixed on the headset

by using double tape on the hair band. A picture of the head set assembly is represented as:

Figure 10 Headset Assembly

16
The sensor that we have used for the orientation of the head is an IMU GY-80. It includes an

accelerometer, gyroscope, magnetometer and a barometer. In our project we are only using 3-

axis accelerometer (ADXL345).

So there are 3 axis x, y and z. The forward motion is due to x-axis acceleration and the right

and left motion is done by y-axis where z-axis is used as a reference acceleration. When

accelerometer is tilted to some angle it gives us some raw acceleration value e.g. when it is

tilted downwards, x-axis acceleration is compared with the gravitational acceleration to give

us raw values of acceleration in x-axis, similarly is the case for y-axis

These raw values of x and y-axis accelerations are converted into degrees with reference to z-

axis using arc tan formula given as:

𝑎𝑥
tan−1 =∅ For forward and stop motion
𝑎𝑧

𝑎𝑦
tan−1 =∅ For left and right motion
𝑎𝑧

Where positive angles are used for forward and right direction, whereas negative angles are

used for left and stop motion.

3.9 Microcontroller interface

The microcontroller that we have used in our project is Arduino Mega (2560). The

specifications of microcontroller are as follows:

17
Figure 2 Microcontroller specs

If we want to trail the head movement, we continuously obtain the readings from the headset

to generate the movement commands to the motors. The controller here gets these readings

from the IMU sensor and then translate them using the control algorithm to determine the

movement commands.

18
Chapter 4

WORKING OF PROJECT

4.1 Working Principle

Now we look the working principle of our project by using step by step method. The IMU

sensor attached on the headset gives the movement commands by detecting the orientation of

the head.

Following are the commanding options available for patient.

 Forward command

By tilting his head in forward direction at the angle of 20 degrees

 Stop Command

By keeping the head in straight position

 Right Command

By tilting his head towards right at the angle of 20 degrees

 Left Command

By tilting his head towards left at the angle of 20 degrees

When the user is sitting on the wheelchair with a straight head position, the stop condition is

being met and wheelchair shows no response. Now if the user want to move in forward

direction he has to tilt the head 20 degrees downward. As long as the users head orientation is

greater than 20 degrees downward, the wheelchair will continue to move forward unless user

return the head to less than 20 degrees, where stop condition sets true. Similarly is the case for

left and right conditions. The micro-controller, Arduino Mega 2560, receives new values from

the accelerometer after every 100ms.

19
So if the forward command is true, the H-bridge allows both the motors to power up at the

same instant and hence wheelchair moves forward. When forward loop is executed the LPWM

pin of H-bridge of both the left and right motors is set to HIGH hence both wheels start to move

in forward direction. When the Stop loop is executed the ENABLE pins for both motors are set

to LOW hence both wheels stop. When the Right loop is executed the LPWM pin for left motor

is set to HIGH and RPWM pin for Right motor is set to HIGH, Hence wheelchair turns towards

right. When the Left loop is executed the LPWM pin for Right motor is set to HIGH and

RPWM for left motor is set to HIGH. Hence wheelchair turns towards Left.

Arduino is also powered by the 24 V batteries source. As the microcontroller Arduino Mega

2560 operates on low voltage and current, so a circuit was needed to lower the voltage coming

from the battery to power the controller. This was done by LM7809 regulator IC which steps

down the voltage from 24 V to 9 V

Another feature of moving the wheelchair backward is not added in the project keeping in

account the safety features of the patient as he is unable to look back.

20
4.2 Control Algorithm

Figure 11 Movement Commands

Head tilted forward > 20° Wheelchair moves forward

Head tilted backward < 20° Wheelchair stops

Head tilted right > 20° Wheelchair turns right

Head tilted left < -20° Wheelchair turns left

21
CONCLUSION AND FUTURE WORK

Conclusion

Main components used in our project is IMU sensor, Arduino Mega 2560, H-bridge and

motors. Values from the movement of head is given by the accelerometer mounted on the IMU

sensor, micro-controller receives that values and processed it. Theses processed commands are

then send to the h-bridge to operate the motors accordingly. Processing of the commands in the

micro-controller are performed according to our designed control algorithm.

Four commanding action can be performed by patient; forward, right, left, stop. By tilting his

head towards forward wheelchair moves in forward direction and same goes for right and left

command. When person keep his head straight wheelchair stops. In addition by simply unscrew

the bolt on the motor plate so that gears can be detached user can operated wheelchair manually.

This product can be commercialized in Pakistan and patients can get benefit from it and we

have taken steps to commercialize it.

We all are extremely thankful to our advisor Prof.Dr habibullah Jamal and co-advisor Dr.Dur-

e-Zehra Baig for their guidance and support through the final year project from the very

beginning to the completion.

Future Works

Controlling of speed

Presently our wheelchair is moving with a constant speed. The speed cannot be varied by users

or patients desire. So two types of modifications can be done i.e. either by PWM pins in the

Arduino code or by providing variable voltage to the motors of the wheelchair.

22
Obstacle detection system

Currently there is no such mechanism for obstacle detection, however a system can be

introduced in such a way that if some obstacle is detected the wheelchair should stop to avoid

any collision or incident.

Health monitor

A health monitoring system should be introduced in the wheelchair such that it can measure

basic information about health, such as temperature, blood pressure and pulse etc. Upper and

lower ranges should be defined and immediate emergency indication should be provided to the

care taker on crossing these ranges.

23
REFERENCES

[1] Manuel Mazo, Francisco J. Rodríguez, José L. Lázaro, Jesús Ureña, Juan C.

García, Enrique Santiso, Pedro Revenga, J. Jesús García, Wheelchair for physically

disabled people with voice, ultrasonic and infrared sensor control

[2] Gunda Gautam, Gunda Sumanth, Karthikeyan K C, Shyam Sundar,

D.Venkataraman , “Eye Movement Based Electronic Wheel Chair For Physically

Challenged Persons”.

[3 ] Prof. Vishal V. Pande, Nikita S.Ubale, Darshana P. Masurkar, Nikita R. Ingole,

Pragati P,” Hand Gesture Based Wheelchair Movement Control for Disabled Person

Using MEMS”.

[4]Mohammed Asgar, Mirza Badra, Khan Irshad and Shaikh Aftab, “Automated

Innovative Wheelchair.”

24
APPENDIX

#include "I2Cdev.h"

#include "ADXL345.h"

ADXL345 accel;

int en_a = 2;

int a_rpwm = 3;

int a_lpwm = 4;

int en_b = 5;

int b_rpwm =6;

int b_lpwm = 7;

int16_t ax, ay, az;

float axf, ayf, azf;

float pitch, roll;

#define LED_PIN 13 // (Arduino is 13, Teensy is 6)

bool blinkState = false;

void setup() {

// join I2C bus (I2Cdev library doesn't do this automatically)

Wire.begin();

// initialize serial communication

// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but

// it's really up to you depending on your project)

Serial.begin(38400);

// initialize device

//Serial.println("Initializing I2C devices...");

accel.initialize();

25
// verify connection

//Serial.println("Testing device connections...");

//Serial.println(accel.testConnection() ? "ADXL345 connection successful" : "ADXL345

connection failed");

// configure LED for output

pinMode(LED_PIN, OUTPUT);

void loop() {

// read raw accel measurements from device

accel.getAcceleration(&ax, &ay, &az);

axf=((float)ax)/256;

ayf=((float)ay)/256;

azf=((float)az)/256;

pitch=atan2(ax, az)*180/PI;

roll=atan2(ay, az)*180/PI;

/display tab-separated accel x/y/z values

Serial.print("accel:\t");

Serial.print(pitch); Serial.print("\t");

Serial.print(roll); Serial.print("\t");

Serial.println(az);

if (pitch<150 && pitch>100)

digitalWrite (en_a,HIGH);

digitalWrite(en_b,HIGH);

26
analogWrite(a_rpwm,170);

digitalWrite(a_lpwm,LOW);

analogWrite (b_rpwm,150);

digitalWrite(b_lpwm,LOW);

Serial.println("FORWARD");

else if (roll<150 && roll>100)

digitalWrite (en_a,HIGH);

digitalWrite(en_b,HIGH);

analogWrite(a_lpwm,170);

digitalWrite(a_rpwm,LOW);

analogWrite (b_rpwm,150);

digitalWrite(b_lpwm,LOW);

Serial.println("LEFT");

else if (roll>-150 && roll<-100)

digitalWrite (en_a,HIGH);

digitalWrite(en_b,HIGH);

analogWrite(a_rpwm,170);

digitalWrite(a_lpwm,LOW);

analogWrite (b_lpwm,150);

digitalWrite(b_rpwm,LOW);

Serial.println("RIGHT");

27
}

else

digitalWrite(en_a, LOW);

digitalWrite(en_b, LOW);

digitalWrite(a_rpwm,HIGH);

digitalWrite(a_lpwm,HIGH);

digitalWrite(b_rpwm,HIGH);

digitalWrite(b_lpwm,HIGH);

Serial.println("STOP");

28

Вам также может понравиться