LCD timer with other parts

Hello, Im currently making a capstone project that requieres an lcd to act as a timer. Followed with lcd I’m using a buzzer, three LEDS and a reset button wired automatically to the arduino in the reset pin. And GND wired with pin 8 acting as sensor, the GND wired with be connected to a piece of metal and pin 8 connected to a tweezer so when the tweezers touch the metal the buzzer will buzz.
Problem
Everything works except the primary display message that is start and when button is touched it starts the timer. Also I need to make that when button is touched after a round it will reset to the “start” message. I’m a beginner and I’m not sure how to fix this error. I would provide my code down below.

If anyone can help I would really appreciate it

#include <LiquidCrystal.h> 
const int rs = 12, en = 10, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 
  LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

int touchSensor;
int buzzer = 9;
int counter;
int green = 6;
int red = 7;
int yellow = 13;

void setup() {
pinMode(green, OUTPUT);
 pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
pinMode(8, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.clear();
lcd.home();
lcd.print("Start");
counter=0;
}

void loop() {
 touchSensor=digitalRead(8);
  lcd.clear();
lcd.setCursor(0,0);
lcd.print(counter);

delay (1000);

counter=counter+1;
  
if(touchSensor == 0){
  do {
  digitalWrite(green, LOW);
  digitalWrite(red, HIGH);
  digitalWrite(yellow, LOW);
  tone(buzzer, 1000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Game Over!");
    delay(5000);
} while (touchSensor == 0);
    }
  
  else if(counter == 20){
    do {
    digitalWrite(green, LOW);
  digitalWrite(red, HIGH);
    digitalWrite(yellow, LOW);
  tone(buzzer,1000);
  delay(100);
 lcd.clear();
lcd.setCursor(0,1);
lcd.print("Game Over!");
    delay (5000);
    } while (counter=20);
  }
    
    else if (counter == 10){
  digitalWrite(yellow, HIGH);    
  digitalWrite(green,LOW);
  digitalWrite(red, LOW);
      delay(1000);
  digitalWrite(yellow, LOW);    
  digitalWrite(green,LOW);
  digitalWrite(red, LOW);
}
      
else{
  digitalWrite(green,HIGH);
  digitalWrite(red, LOW);
  digitalWrite(yellow, LOW);
  noTone(buzzer);
}
}

Please translate the text to schematics.

More tips here: How to get the best out of this forum - Development Tools / IDE 1.x - Arduino Forum

The very first thing you need to do is format your code so you can see what's going on.

#include <LiquidCrystal.h>
const int rs = 12, en = 10, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int touchSensor;
int buzzer = 9;
int counter;
int green = 6;
int red = 7;
int yellow = 13;

void setup() {
   pinMode(green, OUTPUT);
   pinMode(yellow, OUTPUT);
   pinMode(red, OUTPUT);
   pinMode(8, INPUT_PULLUP);
   lcd.begin(16, 2);
   lcd.clear();
   lcd.home();
   lcd.print("Start");
   counter = 0;
}

void loop() {
   touchSensor = digitalRead(8);
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print(counter);

   delay(1000);

   counter = counter + 1;

   if( touchSensor == 0 ) {
      do {
         digitalWrite(green, LOW);
         digitalWrite(red, HIGH);
         digitalWrite(yellow, LOW);
         tone(buzzer, 1000);
         lcd.clear();
         lcd.setCursor(0, 1);
         lcd.print("Game Over!");
         delay(5000);
      } while( touchSensor == 0 );
   }

   else if (counter == 20) {
      do {
         digitalWrite(green, LOW);
         digitalWrite(red, HIGH);
         digitalWrite(yellow, LOW);
         tone(buzzer, 1000);
         delay(100);
         lcd.clear();
         lcd.setCursor(0, 1);
         lcd.print("Game Over!");
         delay(5000);
      } while( counter = 20 );
   }

   else if (counter == 10) {
      digitalWrite(yellow, HIGH);
      digitalWrite(green, LOW);
      digitalWrite(red, LOW);
      delay(1000);
      digitalWrite(yellow, LOW);
      digitalWrite(green, LOW);
      digitalWrite(red, LOW);
   }

   else {
      digitalWrite(green, HIGH);
      digitalWrite(red, LOW);
      digitalWrite(yellow, LOW);
      noTone(buzzer);
   }
}

And the next thing is to turn your compiler warning level to ALL so the IDE will warn you about "did you REALLY mean to do that?" kind of things:

arduino-cli compile -b arduino:avr:uno --warnings all --output-dir ~/tmp --no-color (in directory: /home/me/Documents/sketchbook/Uno_R3/test)
/home/me/Documents/sketchbook/Uno_R3/test/test.ino: In function 'void loop()':
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:58:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
       } while( counter = 20 );
                ~~~~~~~~^~~~
Sketch uses 6390 bytes (19%) of program storage space. Maximum is 32256 bytes.
Global variables use 88 bytes (4%) of dynamic memory, leaving 1960 bytes for local variables. Maximum is 2048 bytes.
Compilation finished successfully.
  • Tell us what this does ?

    } while (counter=20);

Edit

Oops @van_der_decken covered this.

Hi, @dan111
Is this related to:

What model Arduino are you using?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

@LarryD

Hi so the while my teacher told me to add it, he said that there wasn’t any problem with it. Why the whole does in this case is that when the timer reaches a certain point it will buzz.

The arduino I’m using is an arduino uno r3

Yes it is I figure the coding but having some problem I’m currently doing the drawing like @Railroader also suggested.

Can you see the difference between:

while (counter=20);

while (counter == 20);

To be honest no, and I don’t have my guides because I’m not home. Can you tell me what it means.

"Along"

In C++, the difference between = and == is fundamental: one gives a value, while the other checks a value.

And "it" is what, exactly?

So it will be better to add == in order to not assign but check when it equals to that number?

  • Not better, it’s mandatory.

The internet...

https://docs.arduino.cc/language-reference/en/structure/comparison-operators/equalTo/

I understand my guides than the internet, as I said in the previous post this is my last resource.

The { while (counter = 20) but @LarryD helped me with it.

Hi so I’m trying to understand the diagram but I don’t understand it, is it fine if I do a simulator with all the materials being used?

A simulator is a great place to learn. Here is my favorite:

It means you are not ready for this or any project yet. Start by learning the C language for basic syntax.