Production: Slap on the Wrist
Updated: Jan 16, 2020
Below is the setup of a basic analog input to a digital output. In this case the input is a light sensitive sensor and the output is an LED light. The goal was to create a whacky use of the analog/digital I/O. My idea was to use a stretch sensor that would turn a speaker tone when pulled. I used this sensor, attached it to a wrist so that when that person reached for ice cream, the “alarm” would go off warning them not to eat the ice cream.
In place of the light sensor, I simply wired the stretch sensor into the breadboard. In the code I defined the sensor as A0 because it was the analog input. I had to check the serial monitor and program the speaker to turn on when the monitor read less than 220, or the stretch sensor was being pulled to its extent.
I connected the speaker in the same ports as the LED light with the same resistor. I defined the speaker as port 4 on the digital output. In the if statements, the speaker went in digitalWrite. So when the sensor was pulled the speaker would turn on.
I had trouble getting a non-scratchy sound from the speaker when the stretch sensor wasn’t being pulled. After some tinkering and playing around with the wires, the speaker sound finally cleared up. However, I wasn’t sure how to edit the tone of the speaker or the amplitude so the sound was quieter than anticipated.