Help with simple programming

I am a beginner and this will most likely be an easy question for most of you. I am trying to have my buzzer sound when the analog input from my pot gets too low. Just messing around with some tutorials ive watched.

So I programmed my LED to adjust brightness as the voltage changed thru the pot and it works. Then I thought itd be cool if the buzzer would sound as the LED got dimmer so I tried to wire it up and program it and I had no luck.

So the buzzer is wired correctly because if I load sunfounders buzzer program the buzzer sounds correctly. The lef and pot are also wired correctly and the led functions as expected, adjusting brightness as the pot is turned.

I just cant get the buzzer to sound when the led gets too dim.

here is my code;
const int potINPUT = A0;
const int ledPin = 9;
int outputVALUE = 0;
int inputVALUE = 0;
int digitalBUZZ = 12;

void setup(){
digitalBUZZ= LOW;


void loop()
inputVALUE = analogRead(potINPUT);
outputVALUE = map(inputVALUE, 0, 1023, 0, 255);
analogWrite(ledPin, outputVALUE);
if(inputVALUE < 150){
digitalWrite(digitalBUZZ, HIGH);

Any help is appreciated and please dont assume I know anything, haha.

Thanks again

digitalBUZZ= LOW;


This is basically saying

digitalBUZZ = 0;

then I think you set pin 0 as the output, not pin 12 as you're expecting.

In other words, Change

digitalBUZZ= LOW; pinMode(digitalBUZZ,OUTPUT);


pinMode(digitalBUZZ,OUTPUT); digitalWrite(digitalBUZZ, LOW);

and read the post on top of the forum to learn how to use it.
and press Ctrl+T in your Arduino IDE before copying your code.

You will also need to turn the buzzer off if >150

if(inputVALUE < 150)
      digitalWrite(digitalBUZZ, HIGH);

Tom… :slight_smile: