Ghost Detector Error #define NUMREADINGS 25

#define NUMREADINGS 25;
int senseLimit = 1023;
int probePin = 5;
int val = 0;

int LED1 = 11;
int LED2 =10;
int LED3 = 9;
int LED4 = 8;
int LED5 = 7;
int LED6 = 6;
int LED7 = 5;
int LED8 = 4;
int LED9 = 3;
int LED10 = 2;
int readings= [NUMREADINGS];
int index = 0;
int total = 0;
int average = 0;

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.pinMode(9600);

for (int i = 0; i < NUMREADINGS; i++)
readings = 0;
}
void loop() {

  • val = analogRead(probePin);*
  • if (val >1) {*
  • val= constrain(val, 1, senseLimit);*
  • val = map(val, 1, senseLimit, 1, 1023);*
  • total -= readings[ index];*
  • readings[index] = val;*
  • total += readings[index};*
  • index = (index +1);*
  • if (index >= NUMREADINGS)*
  • index = 0;*
    average = total / NUMREADINGS;
  • if (average > 50) {*
  • digitalWrite(LED1, HIGH);}*
  • else{*
  • digitalWrite(LED2, LOW);*
  • }*
  • if (average > 150){*
  • digitalWrite(LED2, HIGH);*
  • }*
  • else {*
  • digitalWrite(LED2, LOW);*
  • }*
  • if (average > 250) {*
  • digitalWrite(LED3, HIGH);*
  • }*
  • else {*
  • digitalWrite(LED3, LOW);*
  • }*
  • if (average > 350){*
  • digitalWrite(LED4, HIGH);*
  • }*
  • else {*
  • digitalWrite(LED4, LOW);*
  • }*
  • if (average > 450) {*
  • digitalWrite(LED5, HIGH);*
  • }*
  • else {*
  • digitalWrite(LED5, LOW);*
  • }*
  • if (average >550) {*
  • digitalWrite(LED6, HIGH);*
  • }*
  • else{*
  • digitalWrite(LED6, LOW);*
  • }*
  • if (average > 650) {*
  • digitalWrite(LED7, HIGH);*
  • } *
  • else {*
  • digitalWrite(LED7, LOW):*
  • }*
  • if (average > 750) {*
  • digitalWrite(LED8, HIGH);*
  • }*
  • else {*
  • digitalWrite(LED8, LOW);*
  • }*
  • if (average > 850) {*
  • digitalWrite(LED9, HIGH);*
  • }*
  • else {*
  • digitalWrite(LED9, LOW);*
  • }*
  • if (average > 950){*
  • digitalWrite(LED10, HIGH);*
  • }*
  • else {*
  • digitalWrite(LED10, LOW);*
  • }*
  • Serial.println(val);*
    }
    }
  • }*
    //I got the code from a book this is only my third build i get an error “expected identifier before numeric constant” any help would be greatly appreciatted.

One obvious thing - there should be no semicolon at the end of

#define NUMREADINGS 25;

Compare the <<<< commented lines against yours. Next time use code tags, the </> button above

byte NUMREADINGS = 25;  // <<<<<<<
int senseLimit = 1023;
int probePin = 5;
int val = 0;

int LED1 = 11;
int LED2 =10;
int LED3 = 9;
int LED4 = 8;
int LED5 = 7;
int LED6 = 6;
int LED7 = 5;
int LED8 = 4;
int LED9 = 3;
int LED10 = 2;
int readings[25] ; // <<<<<<<<<<<<<<
int index = 0;
int total = 0;
int average = 0;

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  Serial.begin (9600);    // <<<<<<<<

  for (int i = 0; i < NUMREADINGS; i++){ // <<<<<<<<<
    readings[i] = 0;
  }
} // <<<<<

void loop() {
  val = analogRead(probePin);
  if (val >1) {
    val= constrain(val, 1, senseLimit);



    val = map(val, 1, senseLimit, 1, 1023);

    total -= readings[ index];
    readings[index] = val;
    total += readings[index]; // <<<<<
    index = (index +1);
    if (index >= NUMREADINGS)
      index = 0;
    average = total / NUMREADINGS;
    if (average > 50) {
      digitalWrite(LED1, HIGH);
    }
    else{
      digitalWrite(LED2, LOW);
    }
    if (average > 150){
      digitalWrite(LED2, HIGH);
    }
    else {
      digitalWrite(LED2, LOW);
    }
    if (average > 250) {
      digitalWrite(LED3, HIGH);
    }
    else {
      digitalWrite(LED3, LOW);
    }
    if (average > 350){
      digitalWrite(LED4, HIGH);
    }
    else {
      digitalWrite(LED4, LOW);
    }
    if (average > 450) {
      digitalWrite(LED5, HIGH);
    }
    else {
      digitalWrite(LED5, LOW);
    }
    if (average >550) {
      digitalWrite(LED6, HIGH);
    }
    else{
      digitalWrite(LED6, LOW);
    }
    if (average > 650) {
      digitalWrite(LED7, HIGH);
    }  
    else {
      digitalWrite(LED7, LOW); // <<<<<<
    }
    if (average > 750) {
      digitalWrite(LED8, HIGH);
    }
    else {
      digitalWrite(LED8, LOW);
    }
    if (average > 850) {
      digitalWrite(LED9, HIGH);
    }
    else {
      digitalWrite(LED9, LOW);
    }
    if (average > 950){
      digitalWrite(LED10, HIGH);
    }
    else {
      digitalWrite(LED10, LOW);
    }
    Serial.println(val);
  }
}

// deleted extra } at the end

Guess reply #1 works also. I don’t use #define much myself. const sometimes tho.

#define NUMREADINGS 25 // <<<<<<<
int senseLimit = 1023;
int probePin = 5;
int val = 0;

int LED1 = 11;
int LED2 =10;
int LED3 = 9;
int LED4 = 8;
int LED5 = 7;
int LED6 = 6;
int LED7 = 5;
int LED8 = 4;
int LED9 = 3;
int LED10 = 2;
int readings[NUMREADINGS] ; // <<<<<<<<<<<<<<

const byte NUMREADINGS = 25;

Also, your int's are taking 2 bytes, when the values used can be a 1 byte instead: byte led1 = 11; for example. If the values will not exceed 255, then byte will do, vs an int which can be -32768 to 32767, or unsigned int from 0 to 65535.

CrossRoads: Guess reply #1 works also

Whether one uses #define or 'const' variables should make no difference to the resulting binary since a good compiler should optimize to the same result. There are syntactic dangers when using #define as the OP has experienced and to avoid them I normally use 'const' variables but I am not religious about it.