Sound Sensors Program not worked

Hello everyone,

I am new here and would like to ask a very important question about a problem I encountered when writing code in Arduino.

I am electronics engineering student and as part of my final Project I build a system called "smart classroom" Basically it allows to control the voltage electrical appliances wisely as turning off lighting and air conditioner when no one in the classroom after a long day...

Another function that my supervisor asked me to do was to measure the volume of class noise at a real time.
This is going on:

The lecturer will raise the circuit breaker and the lesson will begin and two actions will occur:

  1. On the side of the Led LCD will appear the signs "Now learning"
    2, There will be 2 lights that will flash according to the sound rate of the sound sensors, with each lamp being directed to one sensor pointing to the other side of the class (left and right).

I wrote down the next program and it works properly!

/* SoundSensor_Code */
int soundsensor1 = 2;
int soundsensor2 = 4;
int Led_Red = 3;
int Led_Blue = 5;
int statusSensor1 = 0;
int statusSensor2 = 0;
void setup()
{

pinMode(soundsensor1, INPUT);
pinMode(soundsensor2, INPUT);
pinMode(Led_Red, OUTPUT);
pinMode(Led_Blue, OUTPUT);
}
void loop()
{
** statusSensor1 = (digitalRead(soundsensor1));**
** if(statusSensor1 == LOW) {**
** digitalWrite(Led_Red, HIGH);**
** }**
** else {**
** digitalWrite(Led_Red, LOW);**
** statusSensor2 = (digitalRead(soundsensor2));**
** if(statusSensor2 == LOW) {**
** digitalWrite(Led_Blue, HIGH);**
** }**
** else {**
** digitalWrite(Led_Blue, LOW);**
** }**
** }**
}
My big problem is that when I write the same function in the my large program to which another wide range of sensors are connected, the function does not work like the program I wrote here, the LED lights are flashing according to what was included in the function.
I think maybe Becker Arawino does not know how to work well with a lot of sensors and it's from
Please I need urgent help in the matter, who can help me solve the issue I'm sitting and think about over two weeks ????
Thank you a lot!
Omri

Is this your code exactly? It looks like there is an error concerning brackets. I can't say for sure of course, but that would make more sense.

Your code :

void loop()
{
    statusSensor1 = (digitalRead(soundsensor1));
    if(statusSensor1 == LOW)  {
        digitalWrite(Led_Red, HIGH);
    }
    else  {
        digitalWrite(Led_Red, LOW);

        statusSensor2 = (digitalRead(soundsensor2));
        if(statusSensor2 == LOW)  {
            digitalWrite(Led_Blue, HIGH);
        }
        else  {
            digitalWrite(Led_Blue, LOW);
        }
    }
}

Shouldn't it be :

void loop()
{
    statusSensor1 = (digitalRead(soundsensor1));
    if(statusSensor1 == LOW)  {
        digitalWrite(Led_Red, HIGH);
    }
    else  {
        digitalWrite(Led_Red, LOW);
    }
    
    statusSensor2 = (digitalRead(soundsensor2));
    if(statusSensor2 == LOW)  {
        digitalWrite(Led_Blue, HIGH);
    }
    else  {
        digitalWrite(Led_Blue, LOW);
    }
}

I think maybe Becker Arawino does not know how to work well with a lot of sensors

I have absolutely no idea what that means.

Please remember to use code tags when posting code.

I think you're saying that you wrote a small program which works. Then you tried to combine it into another program and the combined program doesn't work correctly.

But you have only shown us the working program which is no use. If you want help with the not-working program then THAT is the program you need to post. All of it, the complete program. You also need to tell us exactly what it does which is different from what you want it to do.

It is possible that you have made some simple error when you tried to combine the two programs but we can't see what you have done so we can't really help.

BTW who or what is "Becker Arawino"?

Steve

Hi Steve,

You're really right, you understand what I'm trying to explain here.
The code is very long and complicated, I have no problem bringing it here, but I hope you can understand it.

I would be very happy to help you because I have to submit the work very soon, this is a major function that needs to work in the program.

Thank you again,
Omri

Smart Classroom.txt (14.4 KB)

In my main program, I wrote the function in question and then in VOID LOOP() I wrote a call to the function in places that I needed ...
On the face, it should work but in practice it does not do the same action.

Omri

Try using CTRL-T in the IDE to sort your formatting out a little. Just to confuse things you have a Sound_Sensor() function which is never called. But I can't compile your code because you seem to be using a very different LiquidCrystal_I2C library from the one I know.

Anyway just "it does not do the same action" isn't very helpful. You haven't said what actually does happen. Have you tried adding a few Serial prints to see if it is actually getting to the bits of code you're expecting?

Steve

Hi Steve,
The program of LEDs combined with the sensors should work as follows:

Each light will flash according to the frequency that the sensor is receiving in real time, meaning that if the first sensor detects a high volume, the light flashes louder, the same to the other side.

I note again that in the small program, the light displays work fine unlike the big program. It's not clear why? After all, I used the same functions ...

omri

You keep saying that it used to work when all the code was inline in a simple sketch but that's not relevant. Now you have a separate function and calls to it wrapped up in while and if statements. That's why I suggest checking with serial prints if it ever gets into your Class_Interruption() routine.

And you still haven't said what, if anything, it is actually doing now. Is it reacting to the sound sensors at all?

BTW what is connected to buttonPin3? Most of the functions seem to depend on it being HIGH and the useless comment just says "The pin that the pushbutton is attached to" exactly the same as it does for buttonPin1 and buttonPin2.

Steve

Hi Steve,

In fact, the lights are beginning to work with the sound sensor readings, but their feedback is displayed in a very large delay and the flash of illumination that the LEDs lamps give is for one second and it does not seem clear.
The Arduino does know the operation with the sound sensors combined with the LEDs - but the presentation is not so similar to what I expect it to be.

Switch 3 is a prerequisite for code operation regardless of switches 1 and 2.
The idea is that when the speaker picks up the switch during the lesson, the system will enter the learning mode and then activate the function and the caption "NOW LEARNING" on screen LCD.

Omri

It looks as though you are seeing what you might reasonably expect because your functions are now being called as part of a loop which is doing plenty of other things, all of which take some time and some of which include delay() and so stop anything else from happening.

What do your serial.print debug statements (if you've tried any) show you ?

Steve

Hi Steve,

As part of debugging the system, I made lcd.print of some caption within the spoken function lines and indeed saw the prints on LCD screen. That is, the system actually enters the function.

Even when I downloaded all of the delay(); from the show, it did not run properly ... I do not think there's any interest here with delay();

Omri