arduino mega buzzer output
Any time you have the same sequence of code repeated over and over with slight variations, that is a &quot;code smell&quot; (an indication that you may be using the wrong approach.)
You should use arrays of pin numbers as you have in the first couple of commented-out lines, and write code that loops through those arrays, as well as functions that take parameters and can do the same thing using different values that are passed in.
Don't try to tackle a problem like this without learning the skills and concepts you need. You said &quot;...I am new to Arduino and arrays , and now I'm focusing on solving buzzer problem.&quot; That is a mistake. Code like you have posted is hard to write, hard to read, and much harder to maintain.