domingo, 2 de abril de 2017

Potentiometer in Snap4Arduino

POTENTIOMETER IN SNAP4ARDUINO

OBJECTIVES:


See the analogue value of a potentiometer by the Arduino serial port shown on the Snap4Arduino screen.


Today we will learn to read the position value of a potentiometer to regulate the on and off of a few leds.


In this practice, we will learn which are the analog values of a signal and the analog-digital conversion.


WHAT IS A POTENTIOMETER?

A potentiometer is a variable resistor in which we can choose the value it can take. If it is totally closed we will obtain as output the maximum voltage (the input voltage), if we have it totally open, we will obtain 0 volts and if we have it in an intermediate position we will obtain a fraction of the input voltage proportional to the position in which it is. This is called 
a voltage divider.








There are several types of potentiometers but the most common are:
  • Linear potentiometers, whose resistance is directly proportional to the angle of rotation. 
  • Logarithmic potentiometers, whose resistance value depends logarithmically on the angle of rotation.
In the linear potentiometers, in the middle of the path we get 50% of the voltage but this does not occur in the logarithmic since in the middle of the route we will return a higher percentage, the proportion in this case is not linear and describes an upward curve, these potentiometers Are mostly used for audio applications.

In our use with Arduino, we can use for example to regulate the light intensity of a Led, the speed of a DC motor, or the position of a servo.

The potentiometers usually have 3 pins, and we have to identify the functionality of each before connecting. One pin will be connected to the power supply, another to earth or GND and finally the third pin will be the output of the potentiometer.
 


ASSEMBLING THE PRACTICE

In the Arduino UNO board we have 6 analog pins, from A0 to A5 and their common use is the reading of data of analog devices as is the case of the potentiometer. They have a resolution of 10 bits which means that we have 1024 different values, ie we can read a range of voltages from 0V to 5V detecting voltage changes of 0.004V (5/1024). So the values we get will go from 0 to 1023.


And as the best way to understand something are the examples, we start with one that through the serial monitor we can see what values we are obtaining in an analog pin as we change the position of the potentiometer.



And the code you should load into Snap4Arduino is as follows:



Now that you've seen the operation of the analog-digital conversion, performs this circuit:






CODING

Once you've made the circuit, I propose these challenges:

  1. Using a 1KΩ potentiometer, let the leds light up gradually following this table: 
    1. <150Ω: all leds off
    2. >150 and <250Ω: Only one ledis lit
    3. >250 and <500Ω: Two leds are lit 
    4. >500 and <750Ω: Three leds are lit
    5. >750Ω: All leds on

     And the code is:





    2. In the second challenge, you have to blink all the leds at once, but as you           turn the potentiometer, the leds will flash faster and faster.




      3. In the third challenge, you have to make the leds illuminate more or less           intensity according to the position of the potentiometer.

In this challenge, we have to use Pulse Width Modulation (PWM), this is a small advance of what we will do in the next sessions, but it is a good example for the beginning. You will see that in the code we do a mathematical operation, this operation is used to limit to 255 at most the output that Arduino will have.






MORE IDEAS TO IN CLASS WITH SNAP4ARDUINO 

  1. Modifies the challenge code 1 Snap4arduino to do the following:
  • > 150Ω: the first ledstays on steady 
  • > 250Ω: the first ledstays steady and the second flashes 
  • > 500Ω: the first and third ledare fixed, the second flashes
  • > 750Ω: first and third ledfixed and second and fourth flash 
    2. The lights will go from side to side as a fantastic car, but the speed will be           controlled by the position of the potentiometer. 

   3. Led lighting control "Leduino". When the potentiometer is at the ends, the leds are off, when the potentiometer is ¼ of the way, the leds light up consecutively from right to left, when the potentiometer is in the middle, the leds remain lit and when the potentiometer is To ¾ of the maximum, the leds change of direction.


CONCLUSION

In this session we have learned several important things:

  • How a potentiometer works.
  • We are ready to use the analog inputs.
  • We have learned to regulate the output voltage.










No hay comentarios:

Publicar un comentario