Analog(ue) and Digital Inputs and Outputs

By nuff
July 24, 2023
2 min read

Dimming a Light with a Potentiometer

For our lab, Digital and Analog In with an Arduino, we connected our Arduino through a potentiometer to an LED.

Side note: I still don't know what a potentiometer is. I should review that.

Ahhhhhhhhh. It's a manually adjustable variable resistor. The two outer terminals have lower and higher resistance and the middle one ("wiper") adjusts the ratio between the two. OK.

Side side note: I still can't read or write circuit schematics. Review this.

I realise I haven't talked about code at all so far. That's mostly because I don't understand it even a little bit.

Basically, the potentiometer has 256 levels of...dial. The LED has 1024. So we read the potentiometer's level and map it to the LED (by multiplying by 4).

void loop() {
    analogValue = analogRead(A0);    // read the pot value
    brightness = analogValue /4;       //divide by 4 to fit in a byte
    analogWrite(ledPin, brightness);   // PWM the LED with the brightness value
    Serial.println(brightness);        // print the brightness value back to the serial monitor

Speaker Test

I wasn't able to finish the Analog Input with Tone lab but I did at least get the speaker to generate a tone. The general idea is to be able to control the tone with pressure on the force-sensing resistor (can I start saying FSR yet?).

I need to come back to this lab and finish it—I'm not likely to do tone generation in Arduino but it seems like understanding the fundamentals here might help when it comes to working with something like Ableton Live, P5.js or Touchdesigner to trigger audio.


No Comments.

Leave a replyReply to