Learn to build and code a circuit that can count how many times you press a button.
In this project, students will build a counter using a variable. The counter records how many times a button is pressed. Tally represents a common way that a score is kept in a video game.
Students will build a tactile button that completes a circuit when pressed.
Students will use variables and loops to create a program that records the number of times someone pushes the button.
Students will integrate skills related to knowledge about variables, conditionals, and debugging in the same project.
I WILL BE ABLE TO...
Build a button that completes a circuit when pushed
Use variables and loops to record the number of times I press the button
Learning Activities
ELA Extension: Tally Report Writing
Pair students up or allow them to work independently based on grade level and writing readiness. Students will collect real-world data using the Tally Counter code and write an informative or persuasive report based on their findings.
Begin by choosing a question to investigate as a class or individually (e.g., “Which snack is most popular?” or “Do more students prefer cats or dogs?”).
Students will collect data using the button press tally counter or traditional tally marks. They organize their data into a table or chart.
Students then write a 1-, 3-, or 5-paragraph report that includes:
An introduction to the question and its purpose
A summary and interpretation of the data (e.g., “Out of 20 students, 12 chose pizza.”)
A reflection on what the results might mean or why they occurred
(Optional) A persuasive paragraph using the data to support an argument (e.g., “We should serve more pizza because it’s clearly the favorite.”)
Bonus vocabulary words to include: tally, data, input, count, analyze, record
EXTENSION: Create a Data Detectives Wall or digital gallery where students post charts, graphs, and reports alongside visuals or code snippets.
ELD Extension: Partner Tally Survey
Pair students so that each English Learner (EL) is working with a fluent or higher-level EL.
Students will begin by practicing simple survey questions with a partner using sentence starters:
"Do you like ___ or ___?"
"Which one do you choose?"
Provide visuals and a scaffolded tally chart for support.
Each student will then tally answers from 5–10 classmates using the button press counter or paper. They will practice saying their results using complete sentences:
"I asked 8 students. 5 chose __. 3 chose __."
Students will retell and present their findings with a partner or small group using sentence frames:
"Most people chose __."
"Only __ people chose __."
"The total was __."
EXTENSION: Optional Skit
Pairs can create a fun news-style interview using their results.
Example: "Back to you, Pip! 10 students voted for mangoes today!"
Math Extension: Tally, Graph, and Reflect
Pair students together or assign groups based on class needs.
Begin by brainstorming survey questions that can be answered with tally data
(e.g., "How many people wear glasses?" or "How many smiley faces are in your notebook?"). Assign different groups to different questions to add variety.
Students collect data using the Tally Counter or tally marks in groups of five. They organize their data in a chart and create a bar graph or line plot to visualize results.
Students will then calculate and discuss:
The total count
The mode (most common response)
Any patterns or surprising results
Use class discussion prompts such as:
"What surprised you about the results?"
"How would the data change if we surveyed more people?"
"What’s another way to show this data?"
EXTENSION CHALLENGE:
Turn the lesson into a Math Scavenger Hunt—students tally real-life items around the room or school (e.g., red shirts, high-fives, blue backpacks). Then organize and analyze the collected data as a class.
Have an different version? Look for more information on the Support Page.
Troubleshooting Tips
Are the console numbers failing to change when you click the button?
Ensure that your code includes the line to add 1 to the number you have in the console.
Ensure that you’ve plugged the wires into the right GPIO. Look at the Digital View to see which pin you’re affecting.
Our customer support specialists are on hand to ensure your implementation of Piper runs seamlessly. View Support Docs or Contact Support
EXPANDED RESOURCES
Term Glossary
Circuit A conductive path for the flow of current or electricity.
Power The current or flow of electric charge and voltage.
Microcontroller An integrated circuit containing a microprocessor with memory and associated circuits.
Variables A value that can change depending on conditions or information passed to the program. A storage location with a symbolic name used to keep track of a value that can change while a program is running (similar concept to using X and Y in an algebraic equation). Variables are not only numbers; they can also hold text, including whole sentences (strings) or logical values (true or false).
Input Device A hardware device that sends data to a computer, allowing interaction and control.
Output Device A piece of hardware that converts information into a form humans can sense and understand.