Jump to content
OFF HOSTINGER CLOUD: Secure SSL + Professional Email + Free Domain ×
AdBlock Detection and Evasion

Arduino and analog gates


Recommended Posts

Know the potentiometers. Understand analog to digital conversion. Learn to use Arduino analog gates.

Required material.

This is the hidden content, please
This is the hidden content, please
This is the hidden content, please
This is the hidden content, please

The potentiometers

Until now we have always used fixed resistors, of a given value. But sometimes it is convenient to have a variable signal to control the circuit that interests us. Imagine the volume of a stereo, or the dial that tunes to a station on an FM radio.

A potentiometer is, simply, a mechanism for providing variable resistance.

There are potentiometers of as many sizes, shapes and colors as you can imagine, but in the end they are a fixed resistance of a given value (10 kΩ in our current case) and a mechanism that allows us to slide a conductive dial over that resistance, which allows us take a part of that value.

That’s why a potentiometer always has 3 pins in a row. The ones at the end behave as a resistance of the full scale value of the potentiometer, and a central pin that takes on resistance values ​​depending on the movement we make with the adjustment.

We are going to set up a circuit like this (in which the potentiometer is labeled Pot1):

img_12_2

The idea is to connect 5V and GND to the ends of the Potentiometer (it doesn’t matter which one is one or the other) and then connect the central pin to the positive of an LED and the negative to GND directly, passing through a limiting resistor.

In this way, when we turn the potentiometer we will be modifying the voltage that we apply to the LED input, which will vary between 0 and 5V (Although it may seem strange now, it is very simple) and we will have obtained an LED intensity regulator.

With a 10k resistor the intensity in the circuit will be: 5V / 10,000Ω = 0.5 mA
Very little to illuminate the LED, which requires about 20 mA. So for most of the turning of the potentiometer the LED will be off.

Important: Don’t forget the resistor R1. Although the potentiometer limits the intensity, there is a time when it will reach zero and there your LED will die in the act of service.

Breadboard circuit

The assembly on the breadboard would be similar to this since we are going to use the Arduino simply to provide voltage to the circuit and nothing else. You will see that the intensity of the light varies continuously when turning the potentiometer.

This is the hidden content, please

Remember that due to the excess resistance of the test potentiometer, during most of the adjustment turn the LED will be off. Note that in this case we use our Arduino simply as a power source to power the circuit.

Arduino and analog inputs

With Arduino we have seen that we can influence the outside world by applying all/nothing outputs on the digital pins and also that using PWM we can quite successfully simulate analog signals on some of those pins.

We have also seen how to detect button presses, defining the digital pins as inputs. But in many cases the sensors that we use to monitor the outside world give us an analog signal. This is the case of temperature or distance sensors, pressure or PH sensors, current intensity in a circuit or water flow in a pipe.

To read this type of continuous signals we need an analog to digital converter (or ADC) that allows us to read the value of an analog signal at a given time.

These converters take a sample of the current value of the signal and give us their instantaneous value, measured in Volts.

By repeatedly reading samples over time we can reconstruct the original signal with greater or lesser precision, depending on the accuracy of our measurement and the speed at which we can take those samples.

This is the hidden content, please
Arduino UNO has six analog to digital converters, named A0 to A5, labeled ANALOG IN:

This is the hidden content, please

Let’s see how to use the analog inputs with a circuit like this, in which we give voltage to the ends of a potentiometer and connect the central pin (the variable one) to the input of gate A5 of the Arduino:

This is the hidden content, please
It seems a good time to highlight that ADC converters read voltage values ​​and not resistance, therefore, what we are going to read is the tension fall on the potentiometer as we turn the adjustment.

The first curiosity is that we do not need to declare in the setup() that we are going to use an analog gate. And the second is that to sample (read) pin A5, we will use the instruction:

int Val = analogRead(A5) ;
The Arduino UNO and Mega converters have 10 bits of resolution so they will return values ​​between 0 and 210 = 1.024 for voltages between 0 and 5V. On the other hand, the Arduino DUE has 12-bit converters so the value of its readings will be between 0 and 10.12 that is, 4,096, that is, it has better resolution (but it can only read up to 3.3V). Make sure not to use sensors that can output more than 5V maximum (with Arduino UNO and Mega), as this will damage the main Arduino chip.

We are going to write a program that reads the value of pin A5 and sends it to the console so we can display it.

Using the analog gates

Try this program:

void setup()
    {  Serial.begin(9600);    // Iniciamos la puerta serie
    }
void loop()
    {  int Lectura = analogRead(A5) ;
       Serial.println( Lectura);
       delay(200) ;
    }

When you turn it over, start the console and you will see that as you turn the adjustment the readings vary continuously reflecting the position of the potentiometer, the readings reflect the drop in volts in it.

This is the hidden content, please

I can’t resist proposing this test: Disconnect the potentiometer from port A5 and observe the results that the Arduino sends to the console. Why do those values ​​appear?

Since A5 is not connected to any valid reference, it is floating and the values ​​it captures are an example of that inconsistency. Actually what your Duino is doing is picking up random radio frequency noise and trying to make sense of it, but it’s got it wrong, as you can see. However, under normal conditions the values ​​you will read will be relatively low. Do you want the oscillations to grow in value? Easy. Put an antenna on it. A simple breadboard cable connected from the A5 to nothing works (Or if you hold the other end between your fingers, you will act as an antenna yourself). You just built the most useless radio frequency receiver in the world.

One last comment

We said in a previous section that the fidelity with which we can sample an analog signal basically depended on the resolution of the sample and the rate at which we could sample the signal (Sample Rate in English).

We already said that the Arduino family has 10-bit converters, so our resolution is 210 = 1.024 and in the case of the DUE of 212 = 4,096. But so far we haven’t seen how fast we can sample with our Arduino. Let’s check it, with this same circuit.

We have a function called millis() that tells us in milliseconds the time elapsed since we started the Arduino and we can use it to see how many samples we can take per second.

void setup()
   {    Serial.begin(9600); }

void loop()
   {     unsigned long T ;
         int n = 0 ;
         T = millis();

         while (millis() <= T + 1000)            // Mientras no pase un Segundo = 1000 mS
             {      analogRead( A5) ;
                    n++ ;                         // Contamos cada vez que leemos
             }
         Serial.println(n);
}
We have used an unsigned long to store millis because it is the type that Arduino uses internally for its clock. It would be a mistake to handle millis with an int because its maximum value is 32,767 and measuring milliseconds the counter would overflow in just over 32 seconds.

IF you run this program on an Arduino UNO it will give you, more or less, a result of 8,940 samples or readings per second. Not bad.

It is suitable for sampling signals that do not vary too quickly over time, as are almost all common sensors in the industry, but it will fall short if you want to sample audio signals.

To play with audio it is best to use an Arduino DUE. It has a clock speed 4 times faster (you will need it), sampling capacity at audio speed (40Khz) and true DAC converters (digital to analog converters). In fact, it is not difficult to increase the sampling rate to about 20,000 samples per second with an Arduino UNO, but for that we have to bypass the Arduino and jump to programming the internal Atmega 328 chip. This is not the time for that, but there are ways.

Session summary

We already know the use of the potentiometer. We have presented the basic concepts in analog to digital conversion. We learned how to read Arduino analog gates. We know that we can read the analog gates about 8,900 times per second with a resolution of 10 bits, that is, between 0 and 1,024. We met the millis() function.

Leave a reply

I’m sorry, you must be

This is the hidden content, please
to post a comment.

  • Thanks 1
Link to comment
Share on other sites

AdBlock Detection and Evasion

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

AdBlock Detection and Evasion


  • Posts

    • Plot: An actress in a dead-end acting career gets a chance to participate in a reality survival dating show, after being eliminated, a hurricane puts all of the people on the island in danger and they try to survive for real. Genre: Comedy IMDB Rating Live: This is the hidden content, please Sign In or Sign Up IMDB Rating: 5.1/10 From 77 Users Rotten Rating: N/A Metacritic Rating: N/A Directed by: Erwin van den Eshof Starring: Carré Albers , Victor Löw , Leo Alkemade Release Name: Expeditie.Cupido.2024.WEB.Dutch.H264-RBB Size: 762MB Video: MP4 | 720×300 | 1 000 kb/s | 25.000 FPS Audio: Dutch | AAC | 192 kb/s Runtime: 1 h 30 min Subtitles: Dutch, English [Selectable] or ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download MP4: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Release Name: Expeditie.Cupido.2024.720p.WEB.Dutch.H264-JFF Size: 2.84GB Video: MKV | 1280×536 | 3 773 kb/s | 25.000 FPS Audio: Dutch | AC3 / dolby digital plus | 640 kb/s Runtime: 1 h 30 min Subtitles: Dutch, English [Selectable] or ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download 720p: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Release Name: Expeditie.Cupido.2024.Dutch.1080p.WEB.H264-TRIPEL Size: 5.90GB Video: MKV | 1920×800 | 8 529 kb/s | 25.000 FPS Audio: Dutch | AC3 / dolby digital plus | 640 kb/s Runtime: 1 h 30 min Subtitles: Dutch, English [Selectable] or ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download 1080p: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Release Name: Expeditie.Cupido.2024.720p.WEBRip.x264-YIFY Size: 831MB Video: MP4 | 1280x534 | 1 150 kb/s | 25.000 FPS Audio: Dutch | AAC | 132 kb/s Runtime: 1 h 30 min Subtitles: Dutch, English ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download 720p YIFY: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up
    • Season 5, Episode 03 – “Stephen Colbert and Evie McGee-Colbert” Ina Garten welcomes old and new friends into her home for good food, great conversation and lots of fun. Her guests include actress Julianna Margulies, broadcaster Willie Geist and chef and restaurateur Erin French. Links: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Be.My.Guest.With.Ina.Garten.S05E03.1080p.WEB.H264-EDITH MKV | AC3 / dolby digital plus | 1.42GB This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Be.My.Guest.With.Ina.Garten.S05E03.WEB.H264-RBB [P2P] MP4 | AAC | 178MB This is the hidden content, please Sign In or Sign Up - This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up
    • Season 7, Episode 81 – "Tinned Tomatoes" A pantry staple becomes the hero tonight as Adam and his guests, comedian Mel Buttle and chef Dom Wilton make magic with tinned tomatoes. Links: This is the hidden content, please Sign In or Sign Up –  This is the hidden content, please Sign In or Sign Up The.Cook.Up.With.Adam.Liaw.S07E81.WEB-DL.x264-JiVE MP4 | AAC | 198MB This is the hidden content, please Sign In or Sign Up - Subtitles – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up
    • Plot: Sideshow Bob sings his own version of a Christmas song for Halloween along with several Disney villains, Genre: Short IMDB Rating Live: This is the hidden content, please Sign In or Sign Up IMDB Rating: 5.3/10 From 56 Users Rotten Rating: N/A Metacritic Rating: N/A Directed by: David Silverman Starring: Nancy Cartwright , Chris Edgerly , Tress MacNeille Release Name: The.Most.Wonderful.Time.Of.The.Year.2024.720p.WEB.H264-JFF Size: 66.5MB Video: MKV | 1280x720 | 2 867 kb/s | 23.976 FPS Audio: English | AC3 / dolby digital plus | 256 kb/s Runtime: 2 min 55 s Subtitles: English, Czech, Danish, German, Greek, Spanish, Finnish, French, Hungarian, Italian, Japanese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Slovak, Swedish, Turkish, Chinese [Selectable] or ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | Trailer | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download 720p: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Release Name: The.Most.Wonderful.Time.Of.The.Year.2024.720p.DSNP.WEB-DL.DDP5.1.H.264-Kitsune Size: 74.4MB Video: MKV | 1280×720 | 3 302 kb/s | 23.976 FPS Audio: English | AC3 / dolby digital plus | 256 kb/s Runtime: 2 min 55 s Subtitles: English, Czech, Danish, German, Greek, Spanish, Finnish, French, Hungarian, Italian, Japanese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Slovak, Swedish, Turkish, Chinese [Selectable] or ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | Trailer | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download 720p: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Release Name: The.Most.Wonderful.Time.Of.The.Year.2024.1080p.DSNP.WEB-DL.DDP5.1.H.264-Kitsune Size: 132MB Video: MKV | 1920×1080 | 6 073 kb/s | 23.976 FPS Audio: English | AC3 / dolby digital plus | 256 kb/s Runtime: 2 min 55 s Subtitles: English, Czech, Danish, German, Greek, Spanish, Finnish, French, Hungarian, Italian, Japanese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Slovak, Swedish, Turkish, Chinese [Selectable] or ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | Trailer | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download 1080p: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up
    • This is the hidden content, please Sign In or Sign Up 2 wins & 5 nominations This is the hidden content, please Sign In or Sign Up » Plot: Sylvia is a social worker who leads a simple and structured life. This is blown open when Saul follows her home from their high school reunion. Their surprise encounter will profoundly impact both of them as they open the door to the past. Genre: Drama IMDB Rating Live: This is the hidden content, please Sign In or Sign Up IMDB Rating: 6.7/10 From 6,751 Users Rotten Rating: 86% Metacritic Rating: N/A Directed by: Michel Franco Starring: Alan Nehama , Dutch Welch , Aliya Campbell Release Name: Memory.2023.720p.BluRay.DD5.1.x264-PTer Size: 5.05GB Video: MKV | 1280x536 | 6 358 kb/s | 24.000 FPS Audio: English | AC3 / dolby digital | 640 kb/s Runtime: 1 h 43 min Subtitles: English, Chinese, French [Selectable] or ( This is the hidden content, please Sign In or Sign Up ) Samples: Video @ This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up Links: This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up | This is the hidden content, please Sign In or Sign Up Download 720p: This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up – This is the hidden content, please Sign In or Sign Up
×
×
  • Create New...

Important Information

Términos y Condiciones

×
  • Home
    Activities
    Sign In
    Search
    More
    ×