Every control starts with a reading. A chip can only regulate what a sensor reports – and a sensor read the wrong way is the most common reason a controller “goes crazy”. This page shows which sensor delivers what and how to read the values safely.
One kit for five sensors
The Kit (Sensors) from the Electronics Printer builds five different sensors. All of them mount in the 0.5 m grid on a wall, floor or ceiling.
| Sensor | Power | Port | key values |
|---|---|---|---|
| Gas Sensor | 1 W | data | Pressure, Temperature, TotalMoles, RatioOxygen and every other gas fraction, Combustion |
| Daylight Sensor | 10 W | power and data | SolarAngle, Horizontal, Vertical, SolarIrradiance |
| Motion Sensor | 0 W | power and data | Activate, Quantity |
| Occupancy Sensor | 0 W | power and data | Activate, Quantity |
| Proximity Sensor | 0 W | power and data | Activate, Quantity, Setting (radius) |
For gas in pipes there are separate devices, for example the Pipe Analyzer (5 W). It delivers the same gas values for the pipe network it sits on.
The gas sensor
It measures the air where it is mounted. All values are read only. The fractions (Ratio…) are numbers between 0 and 1: 0.21 means 21 %.
A worked example every base needs: for breathing, what counts is not the fraction but the partial pressure of oxygen. According to the game data you breathe at full effect from 16 kPa oxygen partial pressure.
- 100 kPa × 0.21 = 21 kPa oxygen – enough.
- 60 kPa × 0.21 = 12.6 kPa – too little, although the fraction is the same.
- 80 kPa × 0.25 = 20 kPa – enough again.
A chip works this out with a single multiplication of Pressure and RatioOxygen.
Combustion does not only report a real fire but already a spark. A wall heater creates one every tick – so next to one the sensor reports fire all the time. For a fire alarm, check Temperature as well.
Combining several sensors
A large room often needs more than one sensor. Give them all the same name and read them with batch mode 0 (Average). Three sensors at 96, 100 and 104 kPa give 100 kPa – exactly what you want.
With batch mode 1 (Sum) you would get 300 kPa. The mistake does not show as long as only one sensor is installed, because with one device average and sum are the same. Only the second sensor suddenly doubles the pressure.
And if no sensor is found? Then mode 0 returns NaN. So check with bnan after every lbn – otherwise your program quietly keeps calculating with NaN, and every comparison after it is wrong.
The daylight sensor
It measures where the sun is. SolarAngle is the sun angle, Horizontal and Vertical give the direction, SolarIrradiance the strength of the sunlight. With Mode you choose between Default (0), Horizontal (1) and Vertical (2). Use it to track solar panels or to switch lights when it gets dark. How a panel is aimed is explained on the Solar Panel page.
Motion and occupancy
The motion, occupancy and proximity sensors all have an Activate and a Quantity, but they cover quite different areas. According to the game code:
| Sensor | covers | Activate | Quantity |
|---|---|---|---|
| Motion Sensor | every movable object in its 2 m cell, dropped items included | 0 or 1 | number of objects |
| Occupancy Sensor | player characters in the same closed room | number of people | same as Activate |
| Proximity Sensor | player characters within a sphere of radius Setting | number of people | same as Activate |
You turn the proximity sensor's radius by hand on its knob, 1 m per step, with the C key held 10 m. It ranges from 0 to 250 m and starts at 2 m. A chip can write Setting as well. Walls do not stop it – it only measures distance. The occupancy and proximity sensors can be limited to authorised people with an access restriction.
Two consequences in practice: a motion sensor only covers a 2 × 2 × 2 m cube – a long corridor needs several. And the occupancy sensor always reports 0 outside a sealed room. It also has 18 memory slots that a chip reads with get: a list of the people in the room with their inventory. How the entries are built is explained on its device page.
Program 1: breathing air guard
All sensors named “Habitat Sensor” are averaged. The housing shows the oxygen partial pressure, a Flashing Light named “Habitat Warning” turns on below 16 kPa – and also when no sensor answers.
# Breathing air guard: oxygen partial pressure in the habitat
define SENSOR -1252983604 # Gas Sensor (StructureGasSensor)
define FLASH -1535893860 # Flashing Light (StructureFlashingLight)
define NSENSOR HASH("Habitat Sensor") # name of all sensors
define NFLASH HASH("Habitat Warning") # name of the warning lights
define O2MIN 16 # kPa, warning below
alias pressure r0
alias ratio r1
alias partial r2
alias warn r3
start:
yield
lbn pressure SENSOR NSENSOR Pressure 0
bnan pressure missing
lbn ratio SENSOR NSENSOR RatioOxygen 0
bnan ratio missing
mul partial pressure ratio # kPa of oxygen
s db Setting partial
slt warn partial O2MIN
sbn FLASH NFLASH On warn
j start
missing:
move warn 1 # no sensor: better warn
sbn FLASH NFLASH On warn
j start
The safe direction applies here: if the reading is missing, the warning goes on, not off.
Program 2: light with run-on
A motion sensor switches the wall lights in a corridor. After the last movement they stay on for 30 seconds – that is 60 ticks of 0.5 s each.
# Corridor light with motion sensor and run-on
define MOTION -1713470563 # Motion Sensor (StructureMotionSensor)
define LIGHT -1860064656 # Wall Light (StructureWallLight)
define NSENSOR HASH("Corridor Detector") # name of the motion sensor
define NLIGHT HASH("Corridor Light") # name of the lights
define RUNON 60 # ticks, 60 x 0.5 s = 30 s
alias seen r0
alias left r1
alias run r2
start:
yield
lbn seen MOTION NSENSOR Activate 0
bnan seen alwayson # no sensor: keep the light on
select left seen RUNON left
sub left left 1
max left left 0
sgtz run left
sbn LIGHT NLIGHT On run
j start
alwayson:
sbn LIGHT NLIGHT On 1
j start
Every detection sets the counter back to 60. Only when it reaches 0 does the light go off. If the sensor is missing, the light stays on – standing in the dark is worse than a few watts.
For a corridor longer than 2 m, hang one sensor per 2 m section and give them all the name “Corridor Detector”. Batch mode 0 then returns the average of Activate: with one of four sensors triggered that is 0.25. select treats every value other than 0 as “seen”, so the program works unchanged.
Next steps
- IC10: control a device by name – batch mode and NaN in detail
- Displays and consoles: LED displays, consoles, circuit boards – showing readings
- Light and alarm: lamps, flashing light, klaxon – lamps, flashing light and klaxon
- Academy: batch modes, catching NaN, breathing air, day and night