Problem with Sound Sensor in my mail Program

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 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!

Smart Classroom.txt (14.4 KB)

Please use code [/] tags when posting code.

Makes it more readable.

Just started to go through your code and a few things I noticed.

ENTER_DOOR and EXIT_DOOR functions: function names are commonly written in camel case starting with capital, so that’d be EnterDoor() and ExitDoor(). Constants are normally written in all caps. Variable names commonly start with lower case, then camel case. So you’d get statusSize1 and [tt[SOUNDSENSOR2[/tt] or [tt[SOUND_SENSOR_2[/tt] (even though you didn’t declare them as const or #define they are constants). Those conventions help you tell them apart, and that way make code more readable and easier to debug. Sometimes I see you do follow those conventions, but there’s no overall convention or style for your code.

Furthermore the code has not a single comment past the list of pin definitions so it’s very hard to understand what you’re even trying to do. I’ve been unable to reading it quickly and not about to start studying it in depth. Just a few other things I noticed:

In both functions you add a delay(2000) in the end. You can do that with millis() as well, and keep your sketch much more responsive.

[tt[if ( count <= 0 )[/tt] which I see at least two times is bound to fail often. You can’t have more than one person moving through the door each two seconds, and you don’t have any safeguard for people moving in and turning in the doorway. The count is bound to be off. You may combine it with a PIR sensor that detects whether there’s movement in the classroom to prevent switching off lights when there is still someone.

Hi wvmarle, First of all thank you very much for all the comments you have made here, some of the comments I have received and correct in the program, you are correct that registration is very important in writing programming language. Unfortunately, my final project is my first time writing in a new language that was not familiar to me, the language of Erdoino and hence the lack of order in writing.

Despite everything you've shown here, we do not yet have a solution to the function - void Class_Interruption () The function ran perfectly in the small program and did not want the large program - it is expressed in the LED display.

In the small program, the lights flicker according to the frequency of the sound sensor readings, however, in the big program the bulbs simply burn out of sync ... I do not know why ???? It is the same function.

Waiting perhaps for a possible solution that will succeed ....

Thanks, Omri

Without comments in your original code it's far too hard to understand what you're trying to do. So add comments (lots of them, more is better) and maybe we can understand your code. It'll also help you understand your code a few weeks later.

Also, especially as you say you never done this before, don't write that much code without making sure it works along the way. Add function by function, feature by feature, small steps and make sure they work. Saves you lots of mess.


You are very right about the above.

Debugging system allows to analyze the code I recorded in slow form after I register another function after function. The system does indeed work in all the functions I have registered. I really work neat.
Only the above function does not work properly … I still think that Arduino can not keep up with all the sensors readings, hoping I’m not mistaken.

Yesterday, too, I tried to correct and improve and try as much as possible, but unfortunately without success …


If readable now (and well commented) do post it again and maybe someone can spot the problem.


I attach my full code here again …
Maybe someone could help me,

Thank everyone,

classroom.txt (11.5 KB)

It would help if you kept your problems to just one thread.


slipstick: It would help if you kept your problems to just one thread.


Amen. Thread locked.