In this experiment you will learn what a poteniometer is and you can use it to find voltage ranges when microcontroller reads LOW and HIGH state on his digital input pins.
Table of contents
A voltage divider is a simple circuit which turns a large voltage into a smaller one. Using just two series resistors and an input voltage, we can create an output voltage that is a fraction of the input. Voltage dividers are one of the most fundamental circuits in electronics.
We may see it drawn a few different ways,
but they are always the same circuit. In this subsection we will denote the resistor closest to the input voltage $V_{in}$ as $R1$, and the resistor closest to ground as $R2$. The voltage drop across $R2$ is called $V_{out}$, and that is the divided voltage our circuit exists to make.
Generally speaking, formula used to calculate $V_{out}$ takes a form
$$V_{out} = \frac{V_{in}R_{2}}{R_{1}+R_{2}}$$
Many sensors in the real world are simple resistive devices. A photocell is one of a such variable resistor, which produces a resistance proportional to the amount of light it senses: the more light we provide the lower resistance of photocell is.
It turns out voltage is really easy for microcontrollers (at least those with analog to digital converters, ADC’s) to measure. Things are not so simple with resistance. But, by adding another resistor to the resistive sensors, we can create a voltage divider. Thus instead of measure resistance, we can measure voltage.Once the output of the voltage divider is known, we can go back and calculate the resistance of the sensor.
Consider the following schema
where the symbol of resistor with two arrows pointing to it is a symbol of photoresistor. Taking the photoresistor with resistance between 0kO in the full light and about 10kΩ in the dark accompanied by 10kO resistor, we will get 0.0V when there is full light and 2.88V in the full dark. If accompanying resistor has 1kO, we will get 0.62V when there is full light and 4.86V in the full dark.
R1 | Voltage in full | |
light | dark | |
10kO | 0.2 | 2.88 |
1kO | 0.62 | 4.86 |
A potentiometer is a three-terminal resistor with a sliding or rotating contact (wiper):
that forms an adjustable voltage divider. If only two terminals are used, one end and the wiper, it acts as a variable resistor.
We can think of a potentiometer as a variable voltage divider. Images below show all the possible states of a potentiometer and voltage dividers corresponding to them (notice that in this case voltage input and ground doesn't matter, so we skipped this element in the picture as well as we reverse order of resistors which again doesn't matter -- after all, it's just a matter of the agreement, which one we will call $R1$ and wich one $R2.)
Take the Arduino board and make the following test
- Turn potentiometer to one of its final position.
- Use middle potentiometer's pin output signal as input signal for digital and analog Arduino's pins
- In Arduino
- read digital pin value and print HIGH if this pin is in
HIGH
state and LOW if is inLOW
state - read analog pin value and print voltage
- read digital pin value and print HIGH if this pin is in
- Change, not to fast, potentiometer position to oposite final position. Doing this, read and print digial and analog values (see previous step). Note when digital state will switch to
HIGH
when voltage is increased from 0V to 5V, and when digital state will switch toLOW
when voltage is decreased from 5V to 0V.
Below tere is a code we can use to make this test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#define LED 13 #define SIGNAL 7 #define VOLTAGE A0 // the setup function runs once when you press reset or power the board void setup() { pinMode(SIGNAL, INPUT); pinMode(LED, OUTPUT); Serial.begin(9600); } // the loop function runs over and over again forever void loop() { byte value = digitalRead(SIGNAL); int sensorValue = analogRead(VOLTAGE); float voltage = sensorValue * (5.0 / 1023.0); Serial.println(voltage); if(value == HIGH) { digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level) } else { digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW } } |
Read an appropriate documentation if you don't know how function we used are working
In my case
- when voltage is increased from 0V to 5V, digital state switches to
HIGH
for 2.7Vfilm.mov - when voltage is decreased from 5V to 0V, digital state switches to
LOW
for 2.16V.
In result you will see three different ranges:
- Range in which, regardless whether the voltage was increased or decreased, digital state is always
LOW
. - Range in which, regardless whether the voltage was increased or decreased, digital state is always
HIGH
. - Range in which, sometimes digital state is
LOW
but other times it isHIGH
.
In consequence, whenever voltage is in red range depicted below you cannot be sure about digital value microcontroller will read.