// PRP 5 — a single threshold decision.
//
// THRESHOLD is a design decision. Replace this value with one you
// chose from your own recorded readings, and be able to defend it.
//
// Expect this sketch to chatter when the reading sits near the
// threshold. That fault is the point of the activity — PRP 6 fixes it.
const int SENSOR_PIN = A0;
const int OUTPUT_PIN = 13;
const int THRESHOLD = 500; // <-- your number, from your data
void setup() {
pinMode(OUTPUT_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int reading = analogRead(SENSOR_PIN);
Serial.println(reading);
if (reading < THRESHOLD) {
digitalWrite(OUTPUT_PIN, HIGH);
} else {
digitalWrite(OUTPUT_PIN, LOW);
}
delay(100);
}