Problem with Starter Kit Project 11

(UNO R4 WiFi Starter Kit) Following the basic Projects Book, July 2025 edition: The code isn't working for me. Before I dive a lot deeper, are there known changes to the code or components specified in the book that make it work [better]? (I'd rather know about this before I spend a lot of debug time.)

Most of us don't have the book and none of us can see your project

Please post the full sketch, using code tags when you do, and a schematic of the project showing all of its components, how they are connected and how they are powered. A 'photo of a hand drawn circuit is good enough

What should the sketch do and what does it actually do, if anything ?

I would say "probably flawed" because their Uno R4 datasheet has 404 links, too.

Never heard of it. Post the code in code tags plus any serial output also in code tags.

Thanks for bringing this to our attention. I submitted a formal report to the people at Arduino responsible for this content.

Starter Kit R4 Courses

A link to the online courses for the kit is provided in section 2.1:

You can follow the link below to access the official online course platform [11], where you will find the online
projects with step-by-step instructions: courses.arduino.cc/starterkitr4. To access the course, users need an Arduino
account.

and again in section 14:

11 Online Starter Kit R4 Course https://courses.arduino.cc/starterkitr4

The correct link is:

https://courses.arduino.cc/starter-kit-r4/

"Getting Started with Arduino Cloud" Tutorial

A link to the "Getting Started with Arduino Cloud" tutorial is provided in section 14:

The correct link is:

https://docs.arduino.cc/arduino-cloud/guides/overview/

ok. I've attached the full instructions, which include the schematic, my code (should have only one line deviating from the prescribed code ("if(numberOfKnocks < 3 && knockVal > 5){")), and a screenshot of the serial output. The object of the sketch/project is to have a device that rotates the servo motor (a "lock") in response to knocks on the table, sensed by the piezo.
First of all, it seems to me that the circuit diagram incorrectly shows the 220 ohm resistors on the cathode side of the LEDs rather than on the anode side. I put them on the anode side as instructed in the words. This does not bolster my confidence that these instructions have been well-vetted.
In the serial output, once the device is "locked", it runs on quickly, showing "3 more knocks to go", and "Bad knock value" counts rapidly, showing values 1-7, with no physical knocks.
I suspect that either the piezo circuit is somehow way too sensitive, or something's wrong in the recommended code. In debugging the knock value is 1-10 (without any real knock).
Now when I try to attach pdfs of the sketch and the code, I get the message "
Sorry, new users can not upload attachment". So I'm dead I guess.

Arduino Sketch 11.pdf (2.6 MB)
Project 11 code.pdf (34.9 KB)

I've just been "promoted", and I guess that allows me to upload.

To post images etc. you need trust level 1, you can get there by:

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

Users at trust level 1 can...

  • Use all core Discourse functions; all new user restrictions are removed
  • Send PMs
  • Upload images and attachments

But even when you can attach files it is not the preferred way as it then requires users to download them and a PDF cannot be loaded into the IDE for examinination

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.


```cpp
#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;
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("The box is unlocked!");
}

void loop() {
  if(locked == false){
    switchVal = digitalRead(switchPin);
    if(switchVal == HIGH){
      locked = true;
      digitalWrite(greenLed, LOW);
      digitalWrite(redLed, HIGH);
      myServo.write(90);
      Serial.println("The box is locked!");
      delay(1000);
    }
  }
  if(locked == true){
    knockVal = analogRead(piezo);
  //if(numberOfKnocks < 3 && knockVal > 0){
    if(numberOfKnocks < 3 && knockVal > 5){
      if(checkForKnock(knockVal) == true){
        numberOfKnocks++;
      }
      Serial.print(3 - numberOfKnocks);
      Serial.println(" more knocks to go");
    }
    if(numberOfKnocks >= 3){
      locked = false;
      myServo.write(0);
      delay(20);
      digitalWrite(greenLed, HIGH);
      digitalWrite(redLed, LOW);
      Serial.println("The box is unlocked!");
      numberOfKnocks = 0;
    }
  }
}

boolean checkForKnock(int value){
  if(value > quietKnock && value < loudKnock){
    digitalWrite(yellowLed, HIGH);
    delay(50);
    digitalWrite(yellowLed, LOW);
    Serial.print("Valid knock of value ");
    Serial.println(value);
    return true;
  }
  else {
    Serial.print("Bad knock value ");
    Serial.println(value);
    return false;
  }
}

Sorry, I don't see any icon in my IDE for code tags. I did use the Copy Code for Forum menu item, however. It doesn't seem to add any < or > symbols, either.

It makes not a jot of difference if a resistor is in the anode or cathode line. Any circuit will work equally as well in either configuration. This is not an error as you seem to think it is.

If you want to add code tags manually then do it in the forum reply editor window using the < CODE > icon

However, if you read what I wrote previously you will see

The Copy for forum command is available from the IDE Edit menu or by right clicking in the code in the IDE