Here we read the value of the potPin, which is a value between. analogRead has only one parameter, namely the pin to be read. The potentiometer returns an analog value, for this we use analogRead. In the previous tutorial we used analogWrite where we wrote an analog value to the Arduino. loop() 1 // The loop() function runs infinitely 2 void loop ()ĪnalogRead() 1 potVal = analogRead(potPin) To do this, we define the potVal variable. When reading out, we have to store the value of the potentiometer somewhere. We start by defining 3 variables: 1 int potPin = A2 // Potmeter pin 2 int ledPin = LED_BUILTIN // Builtin LED pin 3 int potVal = 0 // Potmeter's value (0 by default)īy using LED_BUILTIN the Arduino IDE can determine itself to which pin the built-in LED is connected. The GND on the Arduino -> right pin of the potentiometer.The analog pin A2 on the Arduino -> middle pin of the potentiometer.The 5V on the Arduino -> left pin of the potentiometer.The circuit with the potentiometer plugged into the breadboard Insert the potentiometer as shown in the image below. We use the breadboard to connect the potentiometer to the Arduino. □ If I set the potentiometer to 20%, how many volts is there on the middle pin? The circuit We are going to use it to control the blinking speed of an LED. You can use this to make a light shine brighter or softer, or to turn the volume of an amplifier up or down. When we turn the potentiometer for 50% open the middle pin will be 2.5 Volts. Suppose you connect the + to 5 Volt, and connect the - to the GND. The middle pin returns the current with the resistance of the potentiometer applied. Which one you use for what doesn't matter since a resistor works both ways. PotentiometerĪ normal resistor has 2 ends, the potentiometer has 3. This means that the resistance value ranges from 0 to 10K Ohms. In this lesson we will use a 10K Ohm potentiometer. The resistance changes by turning, just like the volume knob on an amplifier. You can actually see a potentiometer as a variable resistor. With the potentiometer this is different. In the previous tutorials we used a resistor with a fixed value. This button allows you to download the code, circuit diagram and other files relevant to this Arduino tutorial. Curious about what a potentiometer can do? You will know that after following this Arduino tutorial! □ Course materialĪt the bottom of this page you'll find the course material button. We will use this to control the blinking speed of an LED. In this lesson we are going to work with a new component: the potentiometer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |