Notifications
37 Sensor x Cogsworth City DLC 01 – Lesson 1: The Joystick Navigator
Lesson 1: The Joystick Navigator Objective
Astrid will learn how to use the KY-023 Joystick module to control the movement of a character on a simple LED matrix display, simulating navigation through the bustling streets of Cogsworth City.
Materials Needed
- HERO R3 board
- USB cable
- Breadboard
- Male to Male Dupont cables
- KY-023 Joystick module
- 9 LEDs (3×3 grid)
- 9 Resistors (220 ohm)
- Computer with Arduino IDE installed
Introduction
Gear: “Astrid, the streets of Cogsworth City are becoming increasingly complex with all the new clockwork constructions. We need to create a navigation system to help citizens find their way through the maze-like avenues.”
Astrid: “That’s a great idea, Gear! How about we start with a small-scale model using a joystick to simulate movement through the city?”
Gear: “Excellent thinking! Let’s use the KY-023 Joystick module to control a light on an LED grid, representing a person moving through the city streets.”
Lesson Steps
Setting Up
- Connect the HERO board to your computer using the USB cable.
- On the breadboard, create a 3×3 grid of LEDs. Connect both ground
- lines of the breadboard to the GND pin of the HERO via 220-ohm
- resistors. Connect the cathode (shorter leg) of the LED to the ground
- line of the breadboard.
- Connect the anode (long leg) of each LED to a digital pin on the HERO board (use pins 2-10).
4. Connect the KY-023 Joystick module to the HERO board:
- VCC to 5V
- GND to GND
- VRx to A0
- VRy to A1
Writing the Code
Explanation
● We define an array of LED pins and variables for the joystick’s X and Y analog inputs.
● In setup(), we initialize all LED pins as outputs and joystick pins as inputs.
● In loop(), we read the joystick values and update the current position accordingly.
● We use modulo operations to prevent moving off the edges of the LED grid.
● Finally, we turn on the LED corresponding to the current position.
Uploading the Code
1. Open the Arduino IDE on your computer.
2. Copy and paste the code into a new sketch.
3. Select the correct board (Arduino Uno) and port from the Tools menu.
4. Click the upload button to send the code to the HERO board.
Testing the Project
1. Once the code is uploaded, you should see one LED light up in the center of your 3×3
grid.
2. Move the joystick in different directions. The lit LED should move correspondingly,
simulating movement through the city.
3. Try to navigate to all corners of the “city” using the joystick.
Conclusion
Gear: “Fantastic work, Astrid! You’ve created a miniature navigation system for Cogsworth City.
This will greatly help in designing the full-scale version for the citizens.”
Astrid: “Thanks, Gear! It’s amazing how we can represent complex city movements with just a
joystick and some LEDs. I can’t wait to expand on this idea.”
Storyline Hook
Gear: “Your ingenuity never ceases to amaze me, Astrid. But our challenges are far from over.
I’ve detected some unusual heat signatures in the industrial district. Perhaps we should
investigate using a temperature sensor in our next project?”
Astrid: “Sounds intriguing, Gear! Let’s get started on that right away. The safety of Cogsworth
City might depend on it!”