// Knob: read the potentiometer on A0 (0 to 1023), print it,
// and set the LED's brightness to match (0 to 255).
void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);
}
void loop() {
int value = analogRead(A0);
Serial.print("A0 = ");
Serial.println(value);
analogWrite(9, value / 4);
delay(200);
}
Description
Read a potentiometer and print it to the serial monitor. It compiles and runs on a virtual Uno in the browser. Turn the knob and watch the numbers. The LED on pin 9 follows it.
Cite this design
@design{breadboardhub/arduino-knob-and-serial,
title = {Arduino Uno: knob and serial},
author = {breadboardhub},
url = {https://www.breadboardhub.com/breadboardhub/arduino-knob-and-serial},
version = {1.0.0}
}