PyRaspBeta

Lamp

A lamp is a light source you can switch. The shop's part costs $5 and is a world-coupled load: on the board it is a small 5 V stand-in, but in the simulated world it adds light to its zone — a light sensor in the same room reads the lamp on top of the daylight — and gives off a little warmth too (its lux value ÷ 20, in watts). That makes it the actuator for lighting control: switch it on when a motion sensor fires in the dark, or keep a plant's shelf lit. It cannot be driven from a GPIO (the stand-in alone draws 100 mA); it goes behind a relay.

Lamp

Pins

PinWhat it isType
+Supply + (switched through a relay)passive
-Supply −passive
SettingTypeRangeDefault
luxnumber10–20000400
  • Lamp() — Lamp — $5
  • Pins: 2
  • Chain ends: + >> lamp >> -

The two leads are a supply loop: + takes the switched supply (through the relay's NO contact) and − returns to the supply ground. Wire the relay into the + side, as the relay + lamp kit does.

Wiring it in circuit.py

A high-trigger relay switching the lamp from the Pi's 5 V rail:

circuit.py
from wiring import *

pi = Pi()

relay = Relay("high")        # IN high = contacts closed
lamp = Lamp()                # Lamp(lux=1000) for a brighter one

pi.V5 >> relay.dc_plus
pi.V5 >> relay.com            # switched supply in at COM
relay.no >> lamp.plus         # out at NO, into the lamp
lamp.minus >> relay.dc_minus
relay.dc_minus >> pi.GND
pi.GPIO17 >> relay.signal

Lamp takes its lux setting by name (10–20000 lux, default 400). It is a world-model number, not something Python can measure.

Driving it in main.py

main.py
from gpiozero import OutputDevice
from time import sleep

light = OutputDevice(17)

while True:
    light.on()
    sleep(5)
    light.off()
    sleep(5)

The program drives the relay; the lighting happens in the world. A real controller reads a light sensor first — the LDR page and the night light recipe show a sensor driving an output.

Electrical notes

  • On the board, every load is a 50 Ω stand-in: 5 V across it draws 100 mA, well past a GPIO's safe 16 mA. The relay's contacts switch it instead.
  • Its effect on the world scales with (V ÷ 5 V)², clamped to 1.5, and below 2 % of full it counts as off.
  • The lamp adds its lux to the zone's illuminance and lux ÷ 20 watts to the zone's heat: the default 400 lux also warms the room by 20 W. A 20000 lux workshop light would add 1 kW of heat — physics has a sense of humour.
  • Illuminance adds on top of daylight. In an indoor zone the daytime baseline already sits around 300 lux, so a 400 lux lamp is clearly visible day and night — but a light sensor check "dark vs lit" works best at night or in a zone with no daylight.
  • A relay switches a lamp on and off only; it cannot dim. For fading light, use PWM on an LED instead.

Simulator vs real hardware

  • The behaviour is the shared load model: a 50 Ω resistor across +/−, a level that follows the supply, and a world effect of lux × level plus lux ÷ 20 W of heat. While off it reports no load.
  • The lamp acts on the zone it is placed in (indoor by default, changeable in the inspector). A light sensor in the same zone, on its world feed, sees illuminance rise while it is on — day or night.
  • In the judge, an objective's environment pins the sensor readings (e.g. illuminanceLux: 1000) so checks are repeatable; the load still adds light to the zone for sensors left on their world feed.
  • The canvas shows a glow and the zone's light level while it is on; there is no colour temperature, beam angle or lamp heat-up curve in the model.
  • Real mains lamps need proper fixtures and insulation; this is a low-voltage stand-in, and what carries over is the switching lesson, not the wiring.

Going deeper

Further reading