toneMelody error message,"NOTE_A2 not declared in this scope"

So I’m trying to get an analog sensor to work with a piezo on the Arduino uno. Basically I want a proximity sensor to tell a piezo to start singing a melody when someone gets near enough, and blare a noise when they get too close.

I’m trying the if/else statement, and looking at the toneMelody in the library.

The problem is, that I keep getting this error message. “NOTE_A2 was not declared in this scope”

I can’t figure out why it keeps saying that. It’s not the NOTE_A2 either cause it does that with all the notes. What am I doing wrong?

this is my code so far.

#include “pitches.h”

// notes in the melody:
int melody = {

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations = {
4, 8, 8, 4,8,8,8,4 };

void setup() {

void loop() {
int sensorValue = analogRead(A0);

if (sensorvalue > 300) {
for (int thisNote = 0; thisNote < 8; thisNote++) {

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note’s duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
// stop the tone playing:

Do you have pitches.h copied into a tab (called pitches.h) with your sketch in the IDE?

wow.. that was dumb of me not to realize. THANK YOU!!

No problem. Gotta have all the pieces in the same place :wink: