Week 9: Input Devices

Overview

This week's assignment focuses on input devices and their integration with microcontrollers to collect and interpret environmental data. For my individual assignment, I selected a GUVA-S12SD analog ultraviolet (UV) sensor to interface with my custom-designed PCB from previous electronics assignments.

The purpose of this exercise is to explore analog signal acquisition, analog-to-digital conversion (ADC), sensor integration, and the interpretation of sensor measurements through programming. This assignment also supports the development of my final project by exploring how environmental sensing can be incorporated into a portable device.

Group Assignment

Individual Assignment

Remote Student Note on Group Assignment

As a remote student at the UNC Charlotte node, I am coordinating with my instructor regarding the group assignment requirements, including the characterization of analog and digital signals using a multimeter and an oscilloscope.

Input Device Signal Characterization

Input device characterization involves examining the electrical signals produced by sensors and determining how those signals are interpreted by a microcontroller.

Analog Signal Measurements

A multimeter can be used to measure the output voltage of an analog sensor under varying environmental conditions.

Multimeter photographs

Digital Signal Measurements

An oscilloscope allows digital signals to be observed over time to evaluate voltage levels, timing, and transitions between logic states.

Group Assignment Reflection

Input devices provide information to a microcontroller through analog or digital signals. Analog sensors can produce a continuously varying voltage representing a physical property, while digital signals communicate information through discrete logic states.

A multimeter is useful for measuring voltage levels, while an oscilloscope allows signals to be observed over time, including their timing, amplitude, and transitions.

These concepts directly relate to my individual assignment because the UV sensor provides an analog voltage that must be interpreted by the microcontroller using its analog-to-digital converter (ADC).

My Input Device : A UV Sensor

Why a UV sensor?

My final project is a reflective journaling companion designed for educators, inventors, and makers. The system combines physical interaction, environmental sensing, and digital journaling to support personal reflection.

While the wristband detects physical interaction through touch, the console introduces environmental sensing through an analog ultraviolet (UV) sensor. This allows the system to collect additional environmental information that could accompany journal entries.

Due to space limitations within the wristband, I selected the console as the location for the UV sensor. For this assignment, I am using my previously designed and fabricated PCB as a development platform for testing sensor integration.

Understanding Light and Wellbeing

There are three real documented relationships between sulight and wellbeing.

Environmental light exposure can influence daily routines, sleep patterns, and wellbeing. These relationships informed my decision to explore environmental sensing within my final project.

Mechanism Description Relation to Final Project
Circadian Rhythm Visible light exposure helps regulate the body's internal clock. Environmental sensing can encourage reflection on daily routines.
Seasonal Changes Seasonal variations in daylight can influence sleep and mood. Environmental observations may provide additional context for journal entries.
Vitamin D UVB radiation contributes to vitamin D synthesis in the skin. The UV sensor detects ultraviolet radiation but cannot measure vitamin D production.

Why UV specifically and not just a plain (ambient) light sensor

An ambient light sensor measures visible light intensity, while a UV sensor responds to ultraviolet radiation. I selected a UV sensor because I wanted to explore environmental information beyond general indoor lighting conditions.

Although UV measurements can provide information about the presence of ultraviolet radiation, they cannot independently determine whether a user is outdoors or how much daylight exposure a user has received.

Important Note: This Is Not a Medical Instrument

The environmental sensing component of my final project is intended to support personal reflection rather than medical assessment or treatment.

The intended feedback loop pairs reflective journal entries with environmental observations. This could help users identify patterns in their daily routines without making medical claims or establishing causal relationships between UV exposure and mood.

The Board: Week 4 and 8 of my Fabacademy Journey | Reusing My Custom PCB - Circularity

The individual assignment requires integrating a sensor with a personally designed microcontroller board. Rather than designing an entirely new board, I selected my previously designed and milled PCB as the development platform for this week's input device.

This assignment builds upon my earlier electronics design and production work:

What Changed This Week?

Reusing the existing PCB allows me to focus on sensor interfacing, analog signal acquisition, and programming rather than repeating the electronics fabrication process.

How the sensor works

The Adafruit 1918 breakout board uses a GUVA-S12SD photodiode that responds to ultraviolet wavelengths between approximately 240 and 370 nm.

When ultraviolet radiation reaches the photodiode, it generates a small electrical current. An operational amplifier on the breakout board converts and amplifies this signal into an analog output voltage.

The microcontroller reads this voltage through an analog-to-digital converter (ADC), allowing the physical sensor response to be represented numerically.

From Light to a Number

According to the manufacturer's documentation, the relationship between photocurrent and output voltage is approximately:

Vout = 4.3 × Photocurrent (µA)

Using a 12-bit ADC with a nominal 3.3V reference, the raw sensor reading can be converted into voltage using:

Voltage = ADC Reading × (3.3 / 4095)

Adafruit provides an approximate conversion from output voltage to UV Index:

Estimated UV Index = Voltage / 0.1

This conversion provides an estimated value rather than a calibrated UV Index measurement. The primary objective of this assignment is to successfully acquire and interpret the analog sensor signal.

Sensor Testing Considerations

Because the GUVA-S12SD responds to specific ultraviolet wavelengths, ordinary indoor lighting may produce a limited sensor response.

Comparing readings under different environmental conditions, including indoor lighting, filtered sunlight, and outdoor daylight, provides a method for evaluating changes in the sensor output.

Sensor Reference: Adafruit GUVA-S12SD Analog UV Sensor

Circuit and Wiring

BOM (this week's addition)

This assignment builds upon my previously fabricated PCB. The primary additional component is the analog UV sensor.

Component Part Quantity Purpose
UV Sensor Adafruit 1918 GUVA-S12SD Breakout 1 Ultraviolet radiation sensing
Host Board Custom PCB from Week 08 1 Sensor interfacing and data acquisition
Connection Wires Three conductive connections 3 Power, ground, and analog signal

Connections

The UV sensor requires three connections: power, ground, and an analog signal output. The selected analog input is A3, allowing the existing textile input on D0/A0 to remain unchanged.

Sensor Pin PCB Connection Function
V+ 3V3 3.3V power supply
GND GND Common ground reference
OUT A3 Analog sensor signal
PCB with UV sensor soldered

Power Supply and Voltage Compatibility

The GUVA-S12SD breakout supports a supply voltage between 2.7V and 5.5V. I selected the microcontroller's 3.3V supply to maintain compatibility with its analog input.

Powering the sensor from 5V could allow its analog output to exceed the microcontroller's permitted input voltage. Using the 3.3V supply reduces this risk without requiring additional voltage conversion circuitry.

The sensor and microcontroller share a common ground to establish a consistent voltage reference for analog measurements.

Physical Sensor Integration

The UV sensor is intended to connect directly to my previously fabricated PCB rather than through a breadboard. This configuration allows the existing textile input circuit to remain available while introducing an additional analog input.

Before powering the circuit, the connections should be checked for continuity, correct polarity, and unintended shorts between power and ground.

Programming the UV Sensor | Source Code Updated with UV Sensor

I used the Arduino IDE to develop firmware that reads the analog output of the GUVA-S12SD sensor, converts the raw ADC value into voltage, and calculates an estimated UV Index.

The program isolates the UV sensor functionality for testing before integrating it into the complete final project firmware.

Arduino Source Code

  // ─────────────────────────────────────────────────────────────
  // Fab Academy Week 9 — Input Devices
  // Board: Seeed Studio XIAO RP2040 (custom milled PCB, Week 8)
  // Input: Adafruit 1918 GUVA-S12SD analog UV sensor on A3
  // Note:  velostat acknowledgment sensor stays on A0/D0 (unchanged)
  // Output: UV value streamed over USB serial at 115200 baud
  // ─────────────────────────────────────────────────────────────
   
  const int uvPin = A3;        // GUVA-S12SD analog OUT — free ADC pin
   
  void setup() {
    Serial.begin(115200);
    analogReadResolution(12);  // RP2040 ADC full range: 0–4095
    Serial.println("Week 9 — UV sensor initialized");
  }
   
  void loop() {
    int   raw     = analogRead(uvPin);          // 0–4095
    float voltage = raw * (3.3 / 4095.0);       // ADC reference is 3.3V
    float uvIndex = voltage / 0.1;              // GUVA: UV index ≈ Vout / 0.1V
   
    Serial.print("raw=");        Serial.print(raw);
    Serial.print("  V=");        Serial.print(voltage, 3);
    Serial.print("  Estimated UV index="); Serial.println(uvIndex, 1);
   
    delay(500);                                 // sample twice a second
  }
  

Compiling and Uploading the Firmware

The firmware is prepared in the Arduino IDE using the board configuration corresponding to the microcontroller installed on my custom PCB.

  1. Connect the microcontroller to the computer using USB.
  2. Select the corresponding board in the Arduino IDE.
  3. Select the appropriate serial port.
  4. Verify and compile the source code.
  5. Upload the firmware to the microcontroller.
  6. Open the Serial Monitor at 115200 baud.

Testing the UV Sensor

To evaluate the sensor response, I selected three environmental conditions with different expected levels of ultraviolet radiation. The Serial Monitor is used to observe the raw ADC readings and calculated values.

Test Condition Raw ADC Voltage (V) Estimated UV Index
Indoor Lighting Pending Pending Pending
Sunlight Through a Window Pending Pending Pending
Outdoor Daylight Pending Pending Pending
Serial Monitor Readings

Understanding the Code

Code Function
const int uvPin = A3; Defines the analog input connected to the sensor.
Serial.begin(115200); Initializes serial communication.
analogReadResolution(12); Configures ADC readings to range from 0 to 4095.
analogRead(uvPin); Collects the raw analog sensor measurement.
raw * (3.3 / 4095.0) Converts the raw ADC reading into estimated voltage.
voltage / 0.1 Calculates an approximate UV Index.
delay(500); Introduces a 500 millisecond delay between readings.

The Serial Monitor displays the raw ADC value, estimated sensor voltage, and estimated UV Index approximately twice per second. This allows changes in the sensor response to be observed during testing.

Interpreting the Sensor Measurements

The expected relationship between ultraviolet radiation and sensor output is an increase in analog voltage as the amount of detectable ultraviolet radiation increases.

Window materials, shading, sensor orientation, and environmental conditions may influence the measurements. Therefore, readings collected indoors and outdoors may differ significantly.

The calculated UV Index is an approximation based on the breakout board's voltage conversion. Without calibration against a reference instrument, the sensor should be treated as a relative environmental indicator.

Troubleshooting

One consideration when testing the GUVA-S12SD sensor is its sensitivity to a specific range of ultraviolet wavelengths. Ordinary indoor lighting may not produce a significant sensor response.

To distinguish environmental limitations from electrical or programming issues, the troubleshooting process includes verifying the power supply, common ground, analog pin assignment, ADC resolution, and serial communication settings.

Comparing the sensor response under different lighting conditions provides an additional method of evaluating whether the sensor is functioning as intended.

Final Result

assembled PCB and UV sensor

Assignment Reflection

This assignment builds upon my previous electronics design, production, and embedded programming assignments by introducing environmental sensing to my custom PCB.

Reusing an existing board demonstrates the importance of considering available GPIO pins and future component integration during the electronics design process.

The UV sensor also introduces the distinction between collecting an electrical measurement and interpreting its physical meaning. Although the analog signal can be converted into voltage and an estimated UV Index, calibration and environmental conditions influence the accuracy of these measurements.

This work supports my final project's development by establishing an approach for incorporating environmental observations into a reflective journaling system.

Original Design and Programming Files

The PCB used for this assignment was designed and fabricated during previous Fab Academy assignments. The additional programming file introduces the UV sensor functionality.

File or Resource Description Access
Arduino Source Code UV sensor acquisition firmware Pending
PCB Design Files Original schematic and PCB layout Week 06 Documentation
PCB Production Files PCB fabrication documentation and files Week 08 Documentation

Original Design and Programming Files

The PCB used for this assignment was designed and fabricated during previous Fab Academy assignments. The additional programming file introduces the UV sensor functionality.