Project 12 problem

hi i hacv a problem on the 12 project on the starter kit the yellow light is allway on but when i tap on the buzzer that dont change anythings (sry for the bad english im french) and and the servo doesnt move ``

int knockVal;
int switchVal;
const int quietKnock = 10;
const int loudknock = 100;
boolean locked = false;
int numberOfknocks = 0;
void setup(){
  myServo.attach(9);
  pinMode(yellowLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(switchPin, INPUT);
  Serial.begin(9600);
  digitalWrite(greenLed, HIGH);
  myServo.write(0);
  Serial.println("La boite est ouverte !");
}
void loop(){
  if(locked == false){
    switchVal = digitalRead(switchPin);
    if (switchVal == HIGH){
      locked = true;
      digitalWrite(greenLed, LOW);
      digitalWrite(redLed, HIGH);
      myServo.write(90);
      Serial.println("La boite est fermée !");
      delay (1000);
    }
  }
if (locked ==true){
  knockVal = analogRead(piezo);
  if(numberOfknocks < 3 && knockVal > 0){
    if(checkForKnock(knockVal) == true){
      numberOfknocks++;
    }
      Serial.print(3-numberOfknocks);
      Serial.println("coup restants");
  }
    if(numberOfknocks >= 3){
      locked = false ;
      myServo.write(0);
      delay(20);
      digitalWrite(greenLed, HIGH);
      digitalWrite(redLed, LOW);
      Serial.println("La boite est ouverte !") ;
      numberOfknocks = 0;
    }
  }
}
boolean checkForKnock(int value) {
  if(value > quietKnock && value < loudknock){
    digitalWrite(yellowLed, HIGH);
    delay(50);
    digitalWrite(yellowLed,LOW);
    Serial.print("Coup valide de value ");
    Serial.println(value);
    return true;
  }
  else {
    Serial.print("Mauvaise value de coup ") ;
    Serial.println(value) ;
    return false ;
  }
}

Your code does not have the servo library included. Find the missing parts (at the top) that look like this:

#include <Servo.h>
Servo myServo;

const int piezo = A0;
const int switchPin = 2;
const int yellowLed = 3;
const int greenLed = 4;
const int redLed = 5;

Project Book and Github Code links here: Arduino Projects Book - #2 by xfpd

i have also test with the exemple but it same

When you make a change to the code you initially post and test that new code, you should show the new code also (do not edit the original post or code). It is possible that your new code has errors. Further, "the example" does not give useful information.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.