PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Projects

Clap switch

MediumBudget $16Python · gpiozero

The classic clap-on lamp: a sound sensor (powered from 3.3 V, DO on GPIO27, high while it is loud) and a lamp behind a high-trigger relay on GPIO26.

  • Two claps less than 1 s apart toggle the lamp (it starts off).
  • A single clap does nothing.

A clap makes DO chatter for about 0.1 s, so treat the first rising edge as the clap and ignore DO for the next 0.3 s. The test claps once at 1 s, twice at 3.0 s and 3.5 s, and twice at 6.0 s and 6.4 s.

Budget: the Relay + lamp kit doesn't fit; a loose Relay("high") and Lamp() do.

More in Projects