Programming help for my project

So, this is the code that I am working on for my project. The IDE said the program is running well, but I see no result in my actual project. I am a beginner btw, so bear with me, guys, and I'd be grateful for your help.

const int ledGreen = 11;
const int ledRed = 10;
const int pButton = 12;
int greenState = HIGH;
int redState = 0;
int buttonCurrent = 0;
int buttonPrev = LOW;
const int buzzer = 3;
const int soundPin = A1;
const int thresh = 200;


void setup() {
  // put your setup code here, to run once:
  pinMode(ledGreen, OUTPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(pButton, INPUT);
  pinMode(soundPin, INPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonCurrent = digitalRead(pButton);
  int soundSens = analogRead(soundPin);
 
  if (buttonCurrent == HIGH && buttonPrev == LOW){
     if (greenState == HIGH && redState == LOW){
            digitalRead(greenState = LOW);
            digitalRead(redState = HIGH);
            if (soundSens>=thresh){
            tone(buzzer,100);
            delay (5000);
            noTone(buzzer);
            delay(200);
          }
            else{
            noTone(buzzer);
            }
    }
  else{
      greenState = HIGH;
      redState = LOW;
    }
 }
  digitalWrite(ledGreen, greenState);
  digitalWrite(ledRed, redState);
  buttonPrev = buttonCurrent;
  delay (100);
}
const int ledGreen = 11;
const int ledRed = 10;
const int pButton = 12;
int greenState = HIGH;
int redState = 0;
int buttonCurrent = 0;
int buttonPrev = LOW;
const int buzzer = 3;
const int soundPin = A1;
const int thresh = 200;


void setup() {
  // put your setup code here, to run once:
  pinMode(ledGreen, OUTPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(pButton, INPUT);
  pinMode(soundPin, INPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonCurrent = digitalRead(pButton);
  int soundSens = analogRead(soundPin);
 
  if (buttonCurrent == HIGH && buttonPrev == LOW){
     if (greenState == HIGH && redState == LOW){
            digitalRead(greenState = LOW);
            digitalRead(redState = HIGH);
            if (soundSens>=thresh){
            tone(buzzer,100);
            delay (5000);
            noTone(buzzer);
            delay(200);
          }
            else{
            noTone(buzzer);
            }
    }
  else{
      greenState = HIGH;
      redState = LOW;
    }
 }
  digitalWrite(ledGreen, greenState);
  digitalWrite(ledRed, redState);
  buttonPrev = buttonCurrent;
  delay (100);
}

So, it compiles and uploads without errors?
What result were you expecting and what result do you actually get?

Yes, it compiles and uploads without error. The supposed working of it is if the button actuates the RED LED, the sound sensor and Buzzer will be activated.

Please describe, you better yet show with a schematic drawing, how your button is wired.

The supposed working of it is if the button actuates the RED LED, the sound sensor and Buzzer will be activated.

But how is the button wired? Describe or draw a picture: the microcontroller pin, the switch, the other side of the switch and any resistors you have connected.

If I press the button in a simulation, then the buzzer makes sound.

But it should also turn the RED LED on by the time you actuate the PB


This is the schematic of the project

Other duplicate topic DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to [url=https://forum.arduino.cc/index.php?topic=710766.0]Learn How To Use The Forum[/url].

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

eh? these make 0 sense

      digitalRead(greenState = LOW);
      digitalRead(redState = HIGH);

Did you mean:

      greenState = LOW;
      redState = HIGH;

No, it is not a schematic. It is a picture of a project layout and as useless as a Fritzing picture.

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