Advertisement
microrobotics

20K Potentiometer Module

Apr 26th, 2023
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. To use a 20K Potentiometer Module with an Arduino, you will need to connect the potentiometer to an analog input pin on the microcontroller. Here's an example of how to read the potentiometer value and print the value to the Serial Monitor:
  3.  
  4. Hardware Requirements:
  5.  
  6. 20K Potentiometer Module
  7. Arduino board
  8. Jumper wires
  9. Connection:
  10.  
  11. Connect the 3 pins of the potentiometer module to the appropriate pins on the Arduino. In this example, we'll use the following connections:
  12.  
  13. VCC pin of the potentiometer module to the 3.3V or 5V pin on the Arduino(depending on the module's voltage requirements)
  14. GND pin of the potentiometer module to a GND pin on the Arduino
  15. Signal pin (usually marked as S or SIG) of the potentiometer module to an analog input pin on the Arduino (e.g., A0 for Arduino)
  16.  
  17. This code read the analog value from the potentiometer and print it to the Serial Monitor. The value will range from 0 to 1023 for Arduino, depending on the position of the potentiometer knob. You can customize the code to perform different actions depending on the potentiometer value, such as controlling the brightness of an LED, the speed of a motor, or other components in response to the input.
  18.  
  19. Code:
  20. */
  21.  
  22. const int potPin = A0;
  23. int potValue;
  24.  
  25. void setup() {
  26.   Serial.begin(115200);
  27. }
  28.  
  29. void loop() {
  30.   potValue = analogRead(potPin);
  31.   Serial.print("Potentiometer value: ");
  32.   Serial.println(potValue);
  33.   delay(500);
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement