Joystick controlled DC motor with Arduino and TIP122

Controlling a DC motor with a joystick is an easy and fun project that can be done using an Arduino board and a TIP122 transistor. In this Arduino dc motor tutorial, we'll walk you through the steps to set up Joystick to work with Arduino and show how to control speed of dc motor and provide example code to help you get started.

What is a DC Motor and TIP122 Transistor?

A DC motor is an electric motor that runs on direct current (DC) power. It can be used in a variety of applications, from hobby projects to industrial machines. A TIP122 transistor is a type of bipolar junction transistor (BJT) that is commonly used to drive high-power DC motors.

Why Use a Joystick to Control a DC Motor?

A joystick is a commonly used input device for controlling movements in video games and other applications. By using a joystick to control a DC motor, we can easily control the speed and direction of the motor. This makes it a great choice for projects where you want to control a motor manually, such as in a remote-controlled car or a robotic arm.

The following picture shows DC motor controller with Arduino Mega and a Joystick with TIP122 as dc motor controller on a breadboard.

Joystick controlled DC motor with Arduino and TIP122

Setting up the Project

To get started, you will need the following components:

  • An Arduino board
  • A TIP122 transistor
  • 1KOhm resistor
  • A joystick
  • A breadboard
  • Jumper wires
  • A DC motor
  • A power supply

Interfacing Joystick, Arduino, TIP122 transistor

The following is the Arduino joystick schematic diagram which also shows the TIP122 transistor and the DC motor connection.

Joystick controlled DC motor with Arduino and TIP122 circuit diagram

Step 1: Connect the Joystick to the Arduino

The first step is to connect the joystick to the Arduino. Joystick have two directions, X and Y. Here for simple demonstration we will use only X-direction. So you will need to connect the X axis pin of the joystick to analog pins A0 on the Arduino board.

Step 2: Connect the TIP122 Transistor to the DC Motor

Next, you will need to connect the TIP122 transistor to the DC motor. The TIP122 has three pins: the collector, the base, and the emitter. The collector should be connected to the positive terminal of the DC motor, the base should be connected to a digital pin on the Arduino board via 1KOhm resistor, and the emitter should be connected to the negative terminal of the DC motor where the Arduino ground should also be connected.

Step 3: Connect the Power Supply to the Breadboard

Finally, you will need to connect the power supply to the breadboard. Depending upon the motor voltage and current requirement, the power supply could be 12V, 9V, 5V etc. Here for simple DC motor we will be using regulated 5V breadboard supply. The positive terminal of the power supply should be connected to the positive rail on the breadboard, and the negative terminal of the power supply should be connected to the negative rail on the breadboard.

Arduino Joystick controller Program

Now that the hardware is set up, you can start writing the code to control the DC motor with the joystick. You will need to use the analogRead() function to read the values from the X and Y axes of the joystick, and use these values to control the speed and direction of the DC motor. Here's a basic example of what the code could look like:

/*
 ee-diary.com : DC Motor control using JoyStick
*/

int xPin = A0;    // select the input pin for the potentiometer


void setup(){
  Serial.begin(9600);
  pinMode(9,OUTPUT);
}

void loop() {
  // read the value from the JoyStick
  int xValue = analogRead(xPin);
  //map xValue to PWM
  int xpwm = map(xValue,0,1023,0,255);
  analogWrite(9,xpwm);
  // print values
 Serial.print("xValue = " );
 Serial.println(xValue);
 delay(10);
}

The code is a simple Arduino sketch that controls a DC motor using a joystick. The joystick is connected to an analog pin on the Arduino and its value is read in the code. The code uses the analogRead() function to read the value from the joystick, which is connected to the analog pin A0.

The setup() function initializes the serial communication with a baud rate of 9600 and sets pin 9 as an output pin, which will be used to control the DC motor.

In the loop() function, the analogRead() function reads the value from the joystick, which is stored in the xValue variable. This value is then mapped to a value between 0 and 255 using the map() function, which is stored in the xpwm variable. The analogWrite() function is then used to write the xpwm value to pin 9, which controls the DC motor.

Finally, the Serial.print() and Serial.println() functions are used to print the xValue to the serial monitor, and the delay() function is used to pause the program for 10 milliseconds to allow the values to be read and printed.

To further enhance the functionality of the project, you could also integrate other sensors and devices, such as an ultrasonic sensor, to control the speed of the motor based on its distance from an object. For more information on using PID control with an Arduino and an ultrasonic sensor, check out the blog post "PID Control of DC Fan with Arduino and Ultrasonic Sensor".

Another helpful resource for controlling the speed of a DC motor with a TIP122 transistor is the blog post "TIP122 DC Motor Speed Control". This post provides detailed information on how to use a TIP122 transistor to control the speed of a DC motor, and includes code examples to help you get started.

Video demonstration

The following is video that demonstrates how the DC motor is controlled using Joystick, Arduino and the TIP122 dc motor controller.

Conclusion

In conclusion, using a joystick to control a DC motor with an Arduino and a TIP122 transistor is a simple and fun project that can be used in a variety of applications. With just a few basic components and some simple code, you can have a fully functional and customizable motor control system. Whether you're a beginner or an experienced engineer, this project is a great way to learn more about controlling DC motors and integrating different components and devices.

Post a Comment

Previous Post Next Post