/*
Potentiometer -> LED bar + Serial output
- Potentiometer op A0
- LEDs op pinnen 2 t/m 9 (met 220 ohm weerstand)
*/
const int analogInPin = A0; // Potmeter
const int ledPins[] = {2,3,4,5,6,7,8,9}; // LED pins
const int numLeds = 8;
int sensorValue = 0; // ruwe analoge waarde (0-1023)
int ledLevel = 0; // hoeveel LEDs aan
void setup() {
Serial.begin(9600);
// LED pins instellen als output
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Lees potentiometer
sensorValue = analogRead(analogInPin);
// Zet om naar aantal LEDs (0 t/m 8)
ledLevel = map(sensorValue, 0, 20, 0, numLeds);
if (ledLevel>8) {
ledLevel = 8;
}
// LEDs aan/uit zetten
for (int i = 0; i < numLeds; i++) {
if (i < ledLevel) {
digitalWrite(ledPins[i], LOW);
} else {
digitalWrite(ledPins[i], HIGH);
}
}
// Serial output
Serial.print("Sensorwaarde: ");
Serial.print(sensorValue);
Serial.print(" | LEDs aan: ");
Serial.println(ledLevel);
}
For some reason the LEDs turn on constantly and the sensor output doesnt change much when you scream into it, we want that LEDS turn on gradually the louder it gets, do i need to change the code for that?
tomvulkaan112:
ledLevel = map(sensorValue, 0, 20, 0, numLeds);
Change the above code as follows and then try: (Sensor value spans from 0 to 1203 because of 10-bit ADC.)
ledLevel = map(sensorValue, 0, 1023, 0, numLeds);
no LEDs turn on at all, this is what i get on the monitor
First make the LEDs turning On/Off by running simple sketch like:
1. Connect a Potentiometer at A0-pin
2. Upload the following sketch:
const int analogInPin = A0; // Potmeter
const int ledPins[] = {2,3,4,5,6,7,8,9}; // LED pins
const int numLeds = 8;
void setup()
{
Serial.begin(9600);
// LED pins instellen als output
for (int i = 0; i < numLeds; i++)
{
pinMode(ledPins[i], OUTPUT);
}
}
void loop()
{
// Lees potentiometer
sensorValue = analogRead(analogInPin);
// Zet om naar aantal LEDs (0 t/m 8)
ledLevel = map(sensorValue, 0, 1023, 0, numLeds);
// LEDs aan/uit zetten
for (int i = 0; i < numLeds; i++) {
if (i < ledLevel)
{
digitalWrite(ledPins[i], LOW);
}
else
{
digitalWrite(ledPins[i], HIGH);
}
delay(2000);
}
3. Slowly turn the Pot and check that On/Off conditions of the LEDs change.
jim-p
February 11, 2026, 11:06am
9
Can you show the datasheet please?
Welcome to the forum
As your topic relates to an individual Arduino project and not the Arduino Project itself, which is the forum category that you posted in, it has been moved to a more relevant forum category
jim-p
February 11, 2026, 11:12am
12
How is it connected to the Uno?
Which pins do you have connected?
tomvulkaan112:
it gives this error
Copy/paste error. Upload the following sketch:
const int analogInPin = A0; // Potmeter
const int ledPins[] = {2,3,4,5,6,7,8,9}; // LED pins
const int numLeds = 8;
int sensorValue = 0; // ruwe analoge waarde (0-1023)
int ledLevel = 0;
void setup()
{
Serial.begin(9600);
// LED pins instellen als output
for (int i = 0; i < numLeds; i++)
{
pinMode(ledPins[i], OUTPUT);
}
}
void loop()
{
// Lees potentiometer
sensorValue = analogRead(analogInPin);
// Zet om naar aantal LEDs (0 t/m 8)
ledLevel = map(sensorValue, 0, 1023, 0, numLeds);
// LEDs aan/uit zetten
for (int i = 0; i < numLeds; i++) {
if (i < ledLevel)
{
digitalWrite(ledPins[i], LOW);
}
else
{
digitalWrite(ledPins[i], HIGH);
}
delay(2000);
}
gfvalvo
February 11, 2026, 11:58am
14
tomvulkaan112:
its this one
A picture is not a datasheet.
Hi, @tomvulkaan112
Welcome to the forum.
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.
What pins of the sound pickup are you using?
Have you written some code just to test the sound module?
Have you written some code just to test the LED array?
Thanks... Tom....
jim-p
February 11, 2026, 4:54pm
17
Connect the microphone module like this:
(+) to Uno 5V
G to Uno GND
A0 to Uno A0