Home > Microcontroller >Microcontroller Production > How to use ADXL335 to realize the design of gesture control robot

How to use ADXL335 to realize the design of gesture control robot

Source: InternetPublisher:containsmachine Keywords: Robot wireless control ADXL335 Updated: 2023/12/25

    This wirelessly controlled robot car uses gestures: the tilt/direction of the hand to drive forward, backward, left or right.

    Talking about robots, gesture controlled robots are one of the most common project types for hobbyists and students to understand and implement microcontroller knowledge in physics and real-life projects. The concept behind it is simple: the direction of the palm controls the movement of the robot car. But if you want to ask how is it done? Then let us break it down carefully.

    To understand better, we will go through understanding the role and functionality of each component and then combining them to achieve the desired performance.

    1. ADXL335 (accelerometer)

    The accelerometer's function is simple: sense the direction of your wrist. Accelerometers measure acceleration, including the acceleration due to gravity "g". Therefore, we can use the accelerometer to sense the orientation of the wrist by measuring the "g" component on any particular axis of the ADXL335 as shown in the image below:

pYYBAGJ2PMCAT4zaAAQPc98DUbE171.png

    Due to the tilt of the hand, the angle of the X and/or Y axes changes with the vertical direction, so a component of the "g" acceleration also acts on them, which can be measured and therefore indicates the direction of the hand.

    The ADXL335 can measure acceleration up to 3g and interfaces with the Arduino by connecting its axis pin to the Arduino's analog pin. The accelerometer outputs a voltage value proportional to acceleration.

    In this project, the accelerometer is connected to an Arduino Nano and attached to the palm of the hand. The ADXL335 output voltage ranges from 0 to Vcc (applied voltage is typically 3.3V) and is read by the Arduino's analog pins. So to the user we get a value ranging from 0 to 1024 (10-bit ADC). Different orientations produce different simulated values ​​for each axis, which are then mapped to different robot motions.

    The circuit diagram of the accelerometer is:

pYYBAGJ2PLyAGexOAAJsTRCEnwM667.png

    The test code to understand the working of ADXL335 is as follows:

pYYBAGJ2PLiAG9ByAADNNyHx_4k112.png

    You can run this program to see the values ​​for tilting your palms and wrists forward, backward, left, and right, which values ​​will ultimately be used to control the robot.

    2. RF-433 Transmitter and Receiver

    The function of the RF module is simple: transmit command data from the wrist Arduino Nano to the motors that control the Arduino Uno. The RF module uses radio waves at 433hz frequency, hence the name RF-433. They use amplitude modulation to send data, but without going into too many technical details and keeping it simple, they will be used to transmit commands to the robot, namely: move forward, backward, right or left. In the absence of data, there is stillness. Their operating range is up to 10 meters.

    Now to understand how to implement the RF module in our project, let us deal with the transmitter and receiver circuits sequentially.

    transmitter circuit

    The transmitter circuit consists of two parts: transmitter RF and encoder HT12E. The transmitter consists of a data pin, an antenna, a ground and power supply. It is the job of the HT12E encoder to provide data to the transmitter. The encoder consists of 4 data pins that can send data. We will use these 4 data pins to represent the four motions, a high level on these pins will each represent one of the four motions, and a low level on all pins will represent rest.

    The circuit diagram is shown in the figure:

pYYBAGJ2PLSAeJi0AAJoBVpwHAg607.png

    The left pins (A0-A7) are the address pins and define the pair that will exchange data (a transmitter and receiver with the same address will only share data). We set A0-A7 to LOW (ground).

    The data input pins are connected to the Arduino digital pins (6 to 9 in this project) and they will output the command data as:

    Digital pin commands (when high)

    9 forwards

    10 reverse

    11 left

    12 right

    We will write the digital pin high based on the input of the ADXL335 to perform the desired movement.

    receiving circuit

    The receiver circuit is exactly similar to the transmitter circuit shown, but instead of the data pins being outputs to the Arduino, in this case they will be read as inputs to receive commands from the Arduino Uno and run the motors as needed:

pYYBAGJ2PK-ADbS8AAIj-Kuz-_8557.png

    To simplify, instead of the complex circuit as shown, you can put the LED in series with a 1K resistor at pin 17 to indicate the correct connection to the transmitter.

    3. Motor shield

    The motor shield is the easiest part to handle due to the availability of Adafruit library AFMotor, link:- https://github.com/adafruit/Adafruit-Motor-Shield-library

Download and copy the library in the Arduino libraries folder so you can include it in your program sketch.

    An example of the AFMotor library is shown below:

    #include

    4. Combine all the parts

    The last and final part consists of putting all the above parts together to form a complete robot that follows the commands of the hand!

    Since the motor shield uses almost all digital pins, we will use the analog pins of the Arduino Uno to read the receiver data. The final circuit diagram looks like this:

pYYBAGJ2PKiAZv_1AAGiLR1eVf4419.png

    The motor shield handles the connection to the motor. Connect the 9V battery to the shielded power input.

    NOTE: I personally prefer to connect a 2 or even 3.9V battery in parallel to the shield power input to provide enough power to run all four motors. I have connected the four motors in a group of 2 (the same side motors are connected together in parallel so only motor points 3 and 4 are needed to run).

pYYBAGJ2PKSABYZ-AAN5EXyf5_M083.png

    Final code
Arduino Nano:

    int x_axis = 0;
int y_axis = 0;
int forward = 9;
int backward = 10;
int right = 11;
int left = 12;
void setup()
{
pinMode(A0, INPUT); //X-Axis
pinMode(A3 , OUTPUT); //Y-Axis
pinMode(forward, OUTPUT); //HIGH to move Forward
pinMode(backward, OUTPUT); //HIGH to move Backward
pinMode(right, OUTPUT); //HIGH to move Right
pinMode( left, OUTPUT); //HIGH to move Left
Serial.begin(9600);
}
void loop()
{
x_axis = analogRead(A0);
y_axis = analogRead(A3);
Serial.print(" X = ");
Serial. println(x_axis);
Serial.print(" Y = ");
Serial.println(y_axis);
if (y_axis >= 390)
{
Serial.println("Forward");
digitalWrite(forward, HIGH);
}
else
{
if (y_axis <= 310)
{
 Serial.println("BACK");
 digitalWrite(backward, HIGH);
}
else
{
 if (x_axis >= 380)
 {
  Serial.println("RIGHT");
  digitalWrite(right, HIGH);
 }
 else
 {
  if (x_axis <= 320)
  {
Serial.println("LEFT");
digitalWrite(left, HIGH);
  }
  Serial.println(" ");
 }
}
}
delay(200);
if (x_axis > 320 && x_axis < 380 && y_axis > 310 && y_axis < 390)
{
digitalWrite(forward, LOW);
digitalWrite(backward, LOW);
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}
}

    #include

    Transmitter circuit:

pYYBAGJ2PJqANy-AAASARTr7zHc438.png

    Accelerometer:

pYYBAGJ2PJWAKZkCAAbxzIXTWbo830.png

    Complete all modules:

poYBAGJ2PJCAUgYmAAYv8Uop1Qk663.png

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号