Joystick Module With Arduino
Welcome back to my blog. We have already described the types of data required for Arduino encoding in the previous post. We create programs using that knowledge. Okay, today we are going to do a small project and learn Arduino. For that, I have used “digital read,” “analog read” and “analog write”. The following are articles describing these.
Supplies
Okay, let’s go to the post today. We have mainly used the joystick module for this project. We have seen this component in game consoles and in remote controls. They cannot be customized. But with the module we are talking about today, we can do whatever we want through the Arduino board. Let’s do this project using simple code. The following is this module.
Using this component we can create remote controls and game consoles. We will talk about these projects in the next articles. This joystick module has five pins. These are GND, + 5v, VRx, VRy, and SW. It uses GND and + 5v pins to power this component. Analog values can be obtained via VRx and VRy pins by moving this module to both the X and Y axes. A digital value can be obtained from the SW pin. To do this, the module must be pushed down. Let’s do this project practically, using a servo motor and an LED bulb. The required components are as follows.
- Arduino Uno board.
- Joystick module.
- Servo motor.
- LED bulb.
- 220ohm resistor
- 10k resistor.
- Breadboard.
- Jumper wires.
Connect these components to the breadboard.
Connect these components to your Arduino Uno board using the circuit diagram below.
Use only the PMW pins to connect the servo motor. The 220ohm resistor is used to control the current flowing through the LED bulb. The 10k resistor is used for the pull-up circuit.
Let’s Look at the Code Below
Explanation of the code
This code sets the second pin as an input pin, the third pin as an output pin and the fourth pin as an output pin.
Then this code reads analog and digital values and puts them into the variables. The integer data type is named ‘x’ and the boolean data type is named ‘b’. This process is called variable declaring.
This code converts the analog value from 0 -1024 to 0 -180. The servo motor then rotates.
The digital value is checked using an IF condition. Then it is checked whether it is equal to 0. The LED bulb turns on when the digital value is 0 and the LED bulb turns off when the digital value is 1.
Now Select Board and Port. After, Click the Upload Button.
OK, now you can test this project. The following is a project using the Arduino Nano. It uses a serial monitor to view the joystick module readings. The circuit diagram and code are given below.