In this project, you are going to be building a button that gives almost no satisfaction when pressed. It just beeps. And if you want it to beep again, you have to take your finger off and put it back on again.
Parts list
What you’ll need
Step 1
Let’s build this
This is the positive leg of the buzzer. It will have a ‘+’ over top and will also be longer than the other leg.
Don’t forget to plug the board into your computer with the supplied USB cable.
The touch sensor is like a button, except that you only have to touch it lightly.
Connections
Buzzer
The +LEG is the longer leg.
+ LEG11
– LEGGND
Touch Sensor
Use wires to join these.
SIG11
VCC5V
GNDGND
Step 2
Code some chaos
Don’t forget to select your port, like usual
Copy and paste the sample code
curiosity_killer.ino
int touchSensor = 3;
int buzzer = 11;
int beepLength = 50;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(touchSensor, INPUT);
}
void loop() {
if(digitalRead(touchSensor)==HIGH) {
digitalWrite(buzzer, HIGH);
delay(beepLength);
digitalWrite(buzzer, LOW);
delay(beepLength);
while(digitalRead(touchSensor)==HIGH){
}
}
else {
digitalWrite(buzzer, LOW);
}
}