Back to computer sciencecomputing use cases

Computer ScienceComputingHigh schoolKey Stages 4 and 5

How to teach logic gates

Logic gates turn inputs of 1 and 0 into one output, and AND, OR and NOT are the three students learn first. This page explains each gate and its truth table, with a free activity where students wire an alarm circuit to a spec.

Title card reading 'How to teach logic gates', next to three chat cards: a student wires two OR gates, Sparky points to the truth table row where his alarm sounds with the door closed, and a right table gets a harder spec with a NOT gate.

"With any other activity, top students want to move to more complex material, and others need more time on basics. In Flint's activities, I can rotate as a facilitator and Flint automatically scales the assignments to each student's skill level."

Jake KazlowJake Kazlow, Computer science teacher at Westminster

Why this matters

A spec written in English says "the door is open and the system is armed", and many students wire an OR gate because both things sound like reasons for the alarm. Their truth table comes back with two wrong rows and no clue which word misled them. The student who wired it right sits with nothing harder to try, and the teacher has to wait for quiz day to find out who still reads "and" as OR.

What students need to know about logic gates

A logic gate is a circuit part that takes inputs of 1 (true) or 0 (false) and gives one output (BBC Bitesize).

  • An AND gate outputs 1 only when both inputs are 1.
  • An OR gate outputs 1 when either input is 1, or both are.
  • A NOT gate has one input and flips it: 1 becomes 0 and 0 becomes 1.

A truth table lists the output for every combination of inputs, so a circuit with three switches has 8 rows. Boolean algebra writes the same circuit as an expression, such as (Door AND Armed) OR Panic. Python has the same Boolean logic operators, so the alarm is one line of Python (Python documentation):

alarm = (door and armed) or panic

In the Flint activity, each student wires an alarm circuit to a client's spec in a circuit builder Sparky made, then types its 8-row truth table. A worksheet only marks a wrong table wrong, while Sparky names the first row where the student's alarm misbehaves and asks what the spec says for it.

Sparky gets Kai to catch his own OR-for-AND mistake

Kai ends up able to explain why the spec's "and" needs an AND gate, after one row of his own truth table shows him the bug. Everyone in the class gets the same alarm activity, and Sparky's replies depend on the circuit and truth table each student types.

Sparky builds the circuit Kai wiresSparky sends Kai back to the row his alarm gets wrongA right table gets a harder spec
K

Kai

Interest: Redstone circuits in MinecraftStarting point: Reads "and" in a spec as OR

Sparky

Use the circuit builder below to wire AND, OR and NOT gates between the three switches (Door, Armed, Panic) and the alarm.
A logic circuit builder Sparky made in the chat, with Door, Armed and Panic switches and an alarm. The student has wired Door and Armed into one OR gate and that gate and Panic into a second OR gate. Only Armed is on, and the alarm reads ALARM.
InteractiveLogic Gate Circuit Builder, as Kai first wired it

Kai

i used 2 OR gates: door OR armed, then that goes into another OR with panic, then the alarm

Sparky

Look at row Door off, Armed on, Panic off (0 1 0). Your table shows the alarm sounds, but should it?

Kai

i read "and" like a list, like door and armed are both things that set it off. so i swapped the first gate to AND.

Sparky

New spec: add a Pet mode switch. The motion sensor (door) should only trigger the alarm when the system is armed AND Pet mode is NOT on.

Fixed his OR-for-AND mistake from one row, then got a harder spec

Kai is an example student, and his and Sparky's messages are shortened.

What Flint did for Kai

  • Sparky attached a circuit builder to the greeting, so Kai wired and tested his alarm before writing a truth table.
  • When Kai's alarm sounded with the door closed, Sparky named row 0 1 0 instead of naming the gate.
  • Once Kai swapped in an AND gate and his table matched, Sparky gave him a harder Pet mode spec.

A teacher can't do this by hand for 30 students, and Sparky does it in every student's chat.

The activity page shows who still reads "and" as OR

While the class works, Needs attention shows the teacher which student is stuck and on which message. After three or more students submit, activity analytics lists what the class did well, where students went wrong, and a follow-up to practice next.

Flint's activity page for the logic gates alarm activity. Needs attention flags a student who wired OR where the spec says AND. Activity analytics says most students found the row their alarm got wrong after one hint, and 8 students read 'and' as OR. The follow-up suggests turning plain-English alarm rules into AND, OR and NOT expressions. The Sessions table lists three students.

Example activity page

After a computer science class wires the alarm

The school and students are made up for this page, and clicking any student opens their chat.

Set up the activity for free

The alarm activity is in Flint's public library, with the circuit builder, Sparky's guidelines and the greeting already written. Open it, select Use activity to copy it into a free Flint account, and assign it to a class. Sparky builds the four-switch circuit builder for the Pet mode spec inside each student's chat, once that student's first table is right.

For more computer science activities, see Flint for computer science.

Other use cases

See all use cases →

Learning feels different when it fits you.