Lesson 10: Piezo Buzzer controlled with Potentiometer

Here we are. Now we are going to connect previous lesson device and this week device.

Here is the scheme:


Yeah, the connection is very simple. Code a bit different than in Lesson 6. Find out what we have to change from previous Lesson 6?

#define bz 3
#define pot A0

void setup(){
pinMode(bz, OUTPUT);
pinMode(pot, INPUT);
}

int x;
void loop(){
// read value of Potentiometer
// as you remember A0-A5 pins working in range of 0-1023
// but analog TONE range is 31-4900
// to get correct result we will multiply result to 4
x = analogRead(pot) * 4;
// set tone to new value
tone(bz, x);
}

Self study:

Give to students 2 set of buttons (with 10K Ohm resistor). And ask to do kind of piano with 2 buttons. Good luck! For the help about Buttons you may look to previous lesson: Lesson 4.

Comments

  1. good tutorial
    also have a look at https://www.computeraidedautomation.com/forum/8

    ReplyDelete

Post a Comment

Popular posts from this blog

Lesson 9: Piezo Buzzer

Lesson 6: Potentionmeter & LED