Help on making a very simple audio level meter

Any help is appreciated ^^
I'm VERY new to Arduinos and my school design project happened to involve one. I've been experimenting quite a lot recently, however I've only gotten some parts of it to work.
For now, I've gotten the LEDs to change color whenever I give it any sound, from blue to red everytime noise is detected, however I want to give it a medium sound level. Basically, turning from white to blue when it's low sound to normal, then blue to red when it's very noisy. Or simply from white and straight to red when it's extremely noisy.
The code I have so far is:

int redPin= 7;
int greenPin = 6;
int bluePin = 5;
int sensorPin = 2;
boolean val = 0;
void setup() {

  • pinMode(redPin, OUTPUT);*
  • pinMode(greenPin, OUTPUT);*
  • pinMode(bluePin, OUTPUT);*
  • pinMode(sensorPin, INPUT);*
    }
    void loop() {
  • boolean val =digitalRead(sensorPin);*
  • Serial.println (val);*
  • // when the sensor detects a signal above the threshold value, LED flashes*
  • if (val == LOW) {*
  • setColor(0,0,255);*
  • }*
  • else if (val == HIGH){*
  • setColor(255,0,0);*
  • delay(75);*
  • }*
  • else {*
  • setColor(255,255,255); //*
  • }*
    }
    void setColor(int redValue, int greenValue, int blueValue) {
  • analogWrite(redPin, redValue);*
  • analogWrite(greenPin, greenValue);*
  • analogWrite(bluePin, blueValue);*
    }

Don't use boolean, which is a logic state, instead use 'int' variable and read the values for various sound levels.

Then set your code ranges for high low medium or whatever level you want. You will need to allow a spread for the range as the reading will vary. You can also average by taking a number of readings and adding them, then dividing by that number to get the average. Sometimes called smoothing.

tasmod:
Don't use boolean, which is a logic state, instead use 'int' variable and read the values for various sound levels.

Then set your code ranges for high low medium or whatever level you want. You will need to allow a spread for the range as the reading will vary. You can also average by taking a number of readings and adding them, then dividing by that number to get the average. Sometimes called smoothing.

Hi I've changed all the 'booleans' to 'int' instead, however I'm still not sure how to set the actual code ranges of the sound levels. I'm sorry if it's an inconvenience, I'm honestly pretty clueless about Arduinos in general ^^
Thank you for all your help~

Not really this section of the forum, this is for displays.

However,
I don't know your sensor but in the serial window it will be producing values. I can 'guess' your value for a 'silent' room as say between 50 and 100 so the range code for your low led would be

if (val > 50 && val < 100)

{ setColor(0,0,255);}

So that's greater than 50 and less than 100 will light your led.

That's just an example for you to work on, normally it wouldn't have such a spread but I know sound sensors (mics) can respond even to you breathing close by.

At the top of this page under Resources are some excellent Tutorials and a Reference.