RETRO AREA 51 / MODERN VINTAGE LAB

C64 Sensor Lab

Old Computers. New Ideas.

What happens when you connect modern sensors to a computer from the 1980s? I wanted to find out. So I tried three little experiments with my Commodore 64 and SX-64. All three are working prototypes, and there is still plenty to discover. You do not need to be an electronics expert to follow along.

Light Sensor · Heartbeat Monitor · Ultrasonic Sonar · Downloads


01 / Measuring Light

Does the light in the fridge really go out when you close the door? I connected a light sensor to my C64 to find out. The computer displays changes in brightness as a graph. A simple experiment, but a fun way to see an old computer doing something new.

Hardware & how it works

Hardware

  • Commodore 64
  • MOS Technology 6510 processor
  • MOS 6526 CIA interface
  • PCF8591 analogue-to-digital converter
  • HW-011 module with integrated light-dependent resistor
  • 24-contact user port edge connector (12 contacts on each side)
  • Connecting wires

Physical Measurement Principle

A light-dependent resistor (LDR) is an electronic component whose electrical resistance changes depending on the amount of incident light.

Under brighter illumination, the resistance generally decreases. In darkness, the resistance increases. A voltage divider converts this resistance variation into a measurable analogue voltage.

Optical Signal Processing

Light intensity → Resistance variation → Analogue voltage → Digital value → Graphical display

The relationship between illumination and LDR resistance is generally nonlinear. Without calibration, the recorded values represent relative changes in light intensity rather than absolute illumination in lux.

User Port and Sensor Connections

The HW-011 module communicates with the Commodore 64 through two programmable digital signal lines. The prototype receives its power from the user port.

ConnectionFunction
VCC5 V supply
GNDCommon ground
SDASerial data
SCLSerial clock

The onboard light sensor is connected to an analogue input of the PCF8591 through the module configuration jumpers.

The exact user port pin assignment, analogue channel and jumper configuration will be documented after verification against the working hardware and original source code.

Always disconnect the computer from its power supply before modifying the circuit. Verify the connector orientation and electrical connections before switching on.

See Shared Technology above for the converter and I²C interface. Exact user port signal pin assignments and jumper settings remain subject to verification.

Software & programming

Data Acquisition

  1. Ambient light reaches the light-dependent resistor.
  2. The sensor resistance changes.
  3. The resulting analogue voltage is converted into an 8-bit value.
  4. The Commodore 64 reads the digital value via I²C.
  5. The software processes and displays the measurement.
  6. The measurement cycle is repeated.

Software and Programming

The experimental software combines Commodore BASIC with 6510 assembly language routines.

Assembly language provides direct access to the digital hardware and handles communication with the analogue-to-digital converter. BASIC can be used to process the acquired values, control the experiment and generate graphical output.

In one version of the experimental software, the machine language routine starts at memory address $C000. The acquired measurement value is stored at address $C800.

FunctionHexadecimalDecimal
Machine language routine$C00049152
Measurement value$C80051200
SYS 49152
PRINT PEEK(51200)

This example calls the previously loaded machine language routine and reads the resulting measurement value. It is not a standalone sensor program.

The exact sampling frequency and measurement timing depend on the software version and will be documented after verification.

Graphical Visualisation

Several graphical interfaces were developed to visualise the acquired light sensor data on the Commodore 64.

  • Numerical display of raw sensor values
  • Horizontal bar graph
  • Relative light intensity scale
  • Time-dependent graphical representation

The graphical design was inspired by historical scientific instruments and early computer-based data acquisition systems.

Results, limitations & next ideas

Practical Experiment

One practical application of the system is the investigation of light changes inside a refrigerator.

The sensor can be used to observe the transition between darkness and illumination when the refrigerator door is opened or closed.

Although a relatively simple experiment, it demonstrates the ability of a vintage computer to observe physical processes outside its own electronic environment.

Results and Limitations

The working prototype demonstrates that the Commodore 64 can acquire, process and visualise analogue sensor information using modern electronic components.

The measurement characteristics are influenced by several factors:

  • Nonlinear response of the light-dependent resistor
  • Sensor orientation and illumination geometry
  • Spectral characteristics of the light source
  • Analogue-to-digital converter resolution
  • Reference voltage stability
  • Software sampling interval

Absolute illumination measurements would require calibration against a suitable reference instrument. The current prototype is intended for relative optical measurements and experimental demonstrations.

Future Development

  • Calibration against a reference light meter
  • Long-term environmental monitoring
  • Adjustable measurement intervals
  • Storage and export of recorded measurements
  • Simultaneous acquisition of multiple sensor channels
  • Adaptation to the Commodore PET series

02 / Watching Your Heartbeat

Watching Your Heartbeat experiment

Could my portable Commodore SX-64 from 1984 display a heartbeat? A small optical sensor picks up changes in the light passing through a fingertip. The computer turns these changes into a moving waveform. It is an experiment, not a medical instrument.

Hardware & how it works

Hardware

  • Commodore SX-64 (1984)
  • MOS Technology 6510 processor
  • MOS 6526 CIA interface
  • KY-039 optical pulse sensor
  • PCF8591 analogue-to-digital converter (HW-011 module)
  • 24-contact user port edge connector
  • Connecting wires

Optical Measurement Principle

The KY-039 sensor uses an infrared light-emitting diode and a light-sensitive detector to observe changes in light transmission through a fingertip.

With each heartbeat, changes in blood volume affect the amount of light reaching the detector. These variations produce an electrical signal that can be recorded and visualised.

This optical measurement technique is known as photoplethysmography (PPG).

Photoplethysmography – PPG

Heartbeat → Blood volume variation → Optical signal → Electrical signal → Digital measurement

Unlike an electrocardiogram (ECG), this experiment does not measure the electrical activity of the heart directly.

Sensor Connections

The KY-039 sensor provides three electrical connections: signal, positive supply voltage and ground.

KY-039ConnectionFunction
SPCF8591 AIN0Analogue signal
++5 VPower supply
−GNDCommon ground

The prototype uses the 5 V supply from the Commodore user port. The sensor, converter and computer share a common ground.

On the HW-011 module, any onboard sensor connected to the same analogue input must be disconnected when using an external sensor.

The complete user port pin assignment and module jumper configuration will be added after verification against the working hardware and software.

Disconnect the computer from its power supply before modifying the circuit. Verify all connections and the connector orientation before switching on.

See Shared Technology above for the converter and I²C interface. Exact user port signal pin assignments and jumper settings remain subject to verification.

Software & programming

Data Acquisition

  1. Place a fingertip between the optical components of the sensor.
  2. Record the analogue sensor signal.
  3. Convert the voltage into an 8-bit digital value.
  4. Transfer the measurement to the SX-64 via I²C.
  5. Process and visualise the measurement.
  6. Repeat the acquisition cycle.

Software and Programming

The project combines Commodore BASIC with machine language routines. Assembly language provides direct access to the digital interface and supports more efficient communication with the analogue-to-digital converter.

Successive digital measurements are used to visualise variations in the sensor signal over time.

The exact sampling interval and timing characteristics will be documented after further verification of the software.

Signal Visualisation

The graphical interface presents changes in the optical pulse signal on the original CRT display of the Commodore SX-64.

Instead of simply displaying numerical values, the computer visualises successive measurements as a waveform, making periodic signal variations easier to observe.

The display design combines the visual aesthetics of historical electronic measurement equipment with modern sensor technology.

Results, limitations & next ideas

Results and Limitations

The working prototype demonstrates that the Commodore SX-64 can acquire and visualise analogue sensor information using an external digital interface.

The recorded optical signal is influenced by several factors:

  • Finger position and movement
  • Pressure applied to the sensor
  • Ambient light
  • Electrical noise
  • Analogue-to-digital converter resolution
  • Software sampling interval

IMPORTANT – EXPERIMENTAL DEVICE

This project is an educational electronics experiment. It is not a calibrated medical instrument and must not be used for medical diagnosis or health monitoring.

Future Development

  • Improved signal filtering
  • Automatic pulse peak detection
  • Experimental BPM calculation
  • Adjustable graphical measurement scale
  • Recording and exporting measurement data
  • Adaptation to the Commodore PET series

03 / Building a Sonar

C64 sonar experiment

Inspired by old submarine movies, I wanted to see whether a C64 could measure distances and display them on a sonar-style screen. A small ultrasonic sensor sends out sound and listens for the echo. The computer measures the time it takes to return. The sensor does not rotate automatically yet — that could be the next experiment.

Hardware & how it works

Hardware

  • Commodore 64
  • MOS Technology 6510 processor
  • MOS 6526 CIA interface
  • HC-SR04 ultrasonic sensor
  • 24-contact user port connector
  • Two 1 kΩ resistors
  • Connecting wires

Unlike analogue sensor experiments, the ultrasonic sensor does not require an external analogue-to-digital converter. Distance information is obtained by measuring the duration of a digital pulse.

User Port Connections

The HC-SR04 is connected to two programmable digital lines of the Commodore 64 user port. A 1 kΩ series resistor is installed in each signal line.

HC-SR04C64 User PortFunction
VCCPin 2+5 V
GNDPin 1Ground
TRIGPin C / PB0Output via 1 kΩ
ECHOPin D / PB1Input via 1 kΩ
C64 USER PORT HC-SR04
Pin 2 +5V -------- VCC
Pin 1 GND -------- GND
Pin C PB0 --1kΩ--- TRIG
Pin D PB1 --1kΩ--- ECHO

In the current single-sensor configuration, the module receives its 5 V supply directly from the Commodore 64 user port. Disconnect the computer from its power supply before connecting or modifying the circuit. Verify the connector orientation and pin assignments before switching on.

Wiring colours used in the latest sketch: red = +5 V (pin 2), black = GND (pin 1), blue = TRIG (pin C / PB0), yellow = ECHO (pin D / PB1). Do not use the 9 V AC contacts 10 and 11.

Physical Measurement Principle

The Commodore 64 generates a short trigger pulse. The HC-SR04 responds by transmitting a burst of ultrasonic waves at approximately 40 kHz.

When the sound waves encounter an object, part of the acoustic energy is reflected towards the sensor. The module generates an ECHO pulse whose duration represents the round-trip travel time of the sound.

d = (c × t) / 2

d = Distance to the reflecting object

c = Speed of sound, approximately 343 m/s at 20°C

t = Round-trip travel time

The division by two is necessary because the sound travels from the sensor to the object and back again.

DistanceTheoretical echo duration
10 cm583 µs
50 cm2.92 ms
100 cm5.83 ms
200 cm11.66 ms

These values are theoretical calculations at a sound velocity of 343 m/s, not experimentally recorded measurements.

Software & programming

Measurement Sequence

  1. Generate a trigger pulse on PB0.
  2. Wait for the ECHO signal on PB1.
  3. Measure the duration of the ECHO pulse.
  4. Calculate the corresponding distance.
  5. Update the graphical display.
  6. Repeat the measurement cycle.

The current implementation has an approximate measurement cycle of 0.12 seconds, corresponding to around eight measurement updates per second. The precise update interval still needs to be independently verified.

Software and Programming

The measurement software uses 6510 assembly language, based on the 6502 instruction set. Assembly language provides direct access to the digital interface and allows precise control of timing compared with interpreted Commodore BASIC.

RegisterAddressFunction
CIA 2 Port B$DD01Digital input and output
CIA 2 DDR B$DD03Data direction register
PB0Bit 0Trigger output
PB1Bit 1Echo input

The software was developed and tested using C64 Studio, the VICE emulator and original Commodore hardware. Development included initial BASIC experiments, assembly language programming, bitmap graphics and testing on the physical computer.

Sonar Display

The graphical interface uses bitmap graphics to create concentric distance rings and a central crosshair. The measured distance determines the radial position of a visible target marker.

  • Concentric distance rings
  • Numerical distance indication
  • Manually specified sensor angle
  • Configured display range of 2 metres
  • Echo status indication

The current prototype uses a stationary ultrasonic sensor. The angle is supplied manually rather than measured automatically. The system is therefore a sonar-inspired distance visualisation, not yet a complete rotating sonar scanner.

Results, limitations & next ideas

Results and Limitations

The prototype demonstrates that a Commodore 64 can communicate with a modern ultrasonic sensor, process its digital signal and display distance information graphically.

The measurement accuracy depends on the timing routine, the sensor characteristics, ambient temperature, target geometry and acoustic reflections. A systematic calibration against known reference distances is required before quantitative accuracy can be established.

The project is an experimental demonstration rather than a calibrated scientific measurement instrument.

Future Development

  • Systematic distance calibration
  • Temperature compensation
  • Motorised sensor rotation
  • Automatic angular position control
  • 360-degree environmental scanning
  • Adaptation to the Commodore PET series

A little more about the electronics

Two of the experiments use a small board to turn analogue sensor signals into numbers the computer can read. The sonar works differently. Here are the details if you want to explore further.

PCF8591, I²C & user port

Shared Technology / PCF8591 & I²C

The light sensor and heartbeat monitor use the HW-011 analogue-to-digital converter. The ultrasonic experiment instead measures a digital pulse directly.

The digital user port of the Commodore 64 cannot directly measure an analogue voltage. The PCF8591 provides the required conversion between the analogue sensor signal and digital computer data.

ParameterSpecification
ConverterPCF8591
ModuleHW-011
Resolution8 bit
Digital values0–255
Measurement levels256
Analogue input channels4
CommunicationI²C
Supply voltage5 V

For a nominal reference voltage of 5 V, an ideal 8-bit converter has a quantisation step of approximately 19.5 mV.

This theoretical voltage resolution must not be confused with the actual accuracy of the complete optical measurement system.

For the external KY-039 pulse sensor, the analogue signal is connected to AIN0. The converter produces a digital value relative to its reference voltage.

I²C (Inter-Integrated Circuit) Communication

The Commodore 64 does not contain a dedicated hardware I²C controller. Communication with the PCF8591 is implemented in software using the programmable digital lines of the CIA interface.

This technique, known as bit-banging, allows the computer to generate the serial clock and data signals required to communicate with modern electronic components.

SCL – Serial Clock Line · SDA – Serial Data Line

Safety: Disconnect power before wiring. Verify the connector orientation and pin assignments. User port pins 10 and 11 carry 9 V AC; do not use them for these sensor connections.

Before connecting anything: Switch off and disconnect the computer. Check the user port orientation and wiring. Pins 10 and 11 carry 9 V AC. The exact I²C pin and jumper settings still need verification.


How I made these experiments

I came up with the experiments, assembled the hardware, tried BASIC, worked on the graphics and tested everything on the original computers. AI helped me develop and troubleshoot the software, especially the assembly language routines. I am still learning, and not everything works first time. That is part of the fun.

If you have an idea for another sensor, or a different way of doing things, why not give it a try?


Try it yourself

You can download the programs and wiring diagrams in the Downloads section.

Check the hardware notes before connecting your own sensors.


RETRO AREA 51 · MODERN VINTAGE LAB

Preserving the past. Engineering the future.