Step 1 – Create a New Project on Wokwi
Go to wokwi.com, sign in, and create a new project. Select Raspberry Pi Pico W as your board. Wokwi will automatically place the Pico W on a breadboard for you.
Step 2 – Add Components
Search and drag the following components onto the breadboard: 3 LEDs (red), 3 resistors (330 Ω), and 3 push buttons (green, blue, and yellow as shown in the screenshot). Place the LEDs and resistors on the right side and the buttons below them.
Step 3 – Wire the Components
Diagram.json:
Connect each LED through a 330 Ω resistor to these GPIO pins: LED 1 to GP20, LED 2 to GP21, LED 3 to GP22. Connect each button to: Button 1 to GP15, Button 2 to GP16, Button 3 to GP17. The other leg of each button goes to GND. All LED cathodes also connect to the shared GND rail. Link that GND rail to any GND pin on the Pico W.
Step 4 – Write the Code
Open the code editor and write a MicroPython script that reads each button using PULL_UP (so pressing a button gives a 0, which you invert to 1). Each button state is then written to its matching LED. The decimal value is calculated as (button1 × 4) + (button2 × 2) + (button3 × 1). All states are printed to the serial monitor every 500 ms.
Step 5 – Run the Simulation
Click the green Play button. The serial monitor will start printing the state of all three buttons, their binary values, and the decimal equivalent. Initially everything reads 0. Press any button on screen and the matching LED lights up, and the serial output updates instantly.
Step 6 – Read the Serial Output
The serial monitor shows the state of each button (0 or 1), the 3-bit binary number, and the integer equivalent. For example, if only Button 1 is pressed, the output shows binary 100 and Integer Equivalent: 4. Since there are 3 bits, the counter can represent any value from 0 to 7.
CODE:

Comments
Post a Comment