No matter who you are, a learner or an engineer, you can use it to achieve your creative desire.Making a string of led flicker for a set period of time is quite a good project for the beginners to learn how it functions. But here we do another small experiment as a beginning in which we can read the 3-axis dimensions from a ps2 joystick module in console by USB serial port.
All we need is a joystick module, some jumper wires and most important Arduino UNO which is a great starter Arduino, it provides a solid foundation for those just getting started. We can connect the module to the Arduino board according to the photo below.
As the joystick is moved in any direction, X port and Y port on the joystick board ouput X and Y dimension of analog signal as voltage whose value is in the range of 0 to 5V, the Readanalog() command can convert the analog value to digital value in the range of 0 to 1023. Z port on joystick board output Z dimension of digital signal when pressed. So X port and Y port of the joystick need to be connected to the analog input pin0 and pin1 on UNO respectively. Z port needs to be connected to the digital pin7.
X, Y and Z dimension input to the computer is by means of USB port. Now we can upload and click the serial monitor later to see what’s going on, X,Y and Z dimension from joystick module is showing up in the monitor constantly.
Serial.begin(9600) command means that we setup Arduino with the transfer rate, in the case 9600bits per second. Please notice the board and serial port should be correctly selected in tools menu. And the baud rate we select in monitor must be the same as the baud in the code above, otherwise the monitor would show a series of messy codes.
Relating code:
Code: Select all
int sensorPin = 7;
int value = 0;
void setup() {
pinMode(sensorPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
value = analogRead(0);
Serial.print(“X:”);
Serial.print(value, DEC);
value = analogRead(1);
Serial.print(” | Y:”);
Serial.print(value, DEC);
value = digitalRead(sensorPin);
Serial.print(” | Z: “);
Serial.println(value, DEC);
delay(300);
}