Class Session

This week in Physical Computing, we focused on exploring analog input and output on the Arduino and how these signals can be used creatively in projects. We started with simple analog reads using analogRead(A0) to monitor changing values from sensors, observing how the readings in the Serial Monitor responded to changes in resistance — the higher the resistor, the higher the sensor reading. We then learned about PWM (pulse width modulation) and how it allows us to simulate analog output on digital pins, often visualized as “dots” or varying brightness levels from an LED. This concept extends into controlling devices like a servo motor, which operates within a 0–180° range rather than continuously spinning. We also discussed practical hardware considerations, such as avoiding pins D1 and D2 since they’re used for the Serial Monitor, and how using a female audio jack with an amplified speaker opens up sound output beyond the small onboard speaker — with a mono connection achieved by joining two channels. On the sensing side, we explored PIR motion sensors that can detect human presence and movement, and how Arduino handles data: with 8-bit values ranging from 0–255 and an extended 10-bit resolution (0–1023) for analog readings. Finally, we experimented with sound generation using the tone() function, where tone(5, 6000, 3000); produces a 6 kHz tone on pin 5 for three seconds. These foundational skills pave the way for more advanced projects involving pulse, brainwave, or heartbeat sensing, where precise analog input and output control are essential.

Lab: Sensor Change Detection

Goal

Learn how to detect and respond to changes in a sensor’s input value — both digital (on/off) and analog (variable) — using Arduino. This involves recognizing when a sensor’s state changes, when it crosses a threshold, and when it reaches a peak.

While analogWrite() can change the duty cycle (on-off ratio) of a signal, it won't change the frequency. This means you can adjust volume but not pitch with analogWrite(). For creating different tones through a speaker, you need to use the tone() command, which specifically modifies the frequency of the output signal.

Key Concepts • State Change Detection: Rather than constantly reading a sensor’s value, we look for when it changes from one state to another (e.g., from LOW → HIGH). • Useful for counting button presses or triggering actions only once per change. • Threshold Crossing: Trigger an action only when the sensor’s reading crosses a certain value (threshold). • E.g., turn on a light when it gets dark (light sensor value drops below a set threshold). • Peak Detection: Identify the highest sensor reading during a given cycle. • Useful for capturing maximum values like a loudest sound, strongest pressure, or brightest light. • Noise Handling: Sensor readings often fluctuate. Adding a noise margin prevents false triggers by ignoring small variations.

State Change Detection (Digital)

Screenshot 2025-09-30 at 14.10.05.png

I tried out state change detection by wiring a simple push button to my Arduino and writing a sketch that checked whether the button’s state had changed from LOW to HIGH. When I pressed the button, the Serial Monitor only printed a message once per press instead of spamming output continuously, which helped me see how this method is more efficient than constantly reading sensor values. I also experimented with counting how many times the button was pressed by incrementing a variable each time a state change occurred — this worked perfectly and confirmed that the code was detecting transitions rather than just the button being held down. It was really useful to understand that state change detection is all about recognizing when something changes, not the actual value itself.

Threshold Crossing (Analog)

Screenshot 2025-09-30 at 14.15.33.png

In this part of the lab, I wrote a sketch to detect when the sensor’s reading crossed a certain threshold rather than just constantly printing values. I wired a sensor to analog pin A0 and set a threshold, then programmed the Arduino to trigger a message only when the reading rose above that value. When I tested it, the Serial Monitor only printed a message once per crossing — even if the sensor stayed above the threshold — and it didn’t trigger again until the value dropped back down and rose above it once more. This helped me see how threshold detection can be used to control events based on specific conditions instead of continuous input. It’s especially useful for real-world applications like turning on a device when a reading is high enough or detecting an environmental change that crosses a defined boundary.