Tag Archive | "resistance"

Tutorial: Using analog input for multiple buttons

Use multiple buttons with one analog input in chapter twenty-five of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe.

[Updated 14/03/2013]

The purpose of this article is demonstrate how you can read many push buttons (used for user-input) using only one analog input pin. This will allow you to save digital I/O pins for other uses such as LCD modules and so on. Hopefully you recall how we used analogRead() in chapter one, and how we used a potentiometer to control menu options in exercise 10.1. For this article, we will be looking at reading individual presses, not simultaneous (i.e. detecting multiple button presses).

To recap, an analog input pin is connected to an analog to digital (ADC) converter in our Arduino’s microcontroller. It has a ten bit resolution, and can return a numerical value between 0 and 1023 which relates to an analog voltage being read of between 0 and 5 volts DC. With the following sketch:

and in the following short video, we have demonstrated the possible values returned by measuring the voltage from the centre pin of a 10k ohm potentiometer, which is connected between 5V and GND:

As the potentiometer’s resistance decreases, the value returned by analogRead() increases. Therefore at certain resistance values, analogRead() will return certain numerical values. So, if we created a circuit with (for example) five buttons that allowed various voltages to be read by an analog pin, each voltage read would cause analogRead() to return a particular value. And thus we can read the status of a number of buttons using one analog pin. The following circuit is an example of using five buttons on one analog input, using the sketch from example 25.1:

example25p2

And here it is in action:

Where is the current coming from? Using pinMode(A5, INPUT_PULLUP); turns on the internal pull-up resistor in the microcontroller, which gives us ~4.8V to use. Some of you may have notice that when the right-most button is pressed, there is a direct short between A5 and GND. When that button is depressed, the current flow is less than one milliamp due to the pull-up resistor protecting us from a short circuit. Also note that you don’t have to use A5, any analog pin is fine.

As shown in the previous video clip, the values returned by analogRead() were:

  • 1023 for nothing pressed (default state)
  • 454 for button one
  • 382 for button two
  • 291 for button three
  • 168 for button four
  • 0 for button five

So for our sketches to react to the various button presses, they need to make decisions based on the value returned by analogRead(). Keeping all the resistors at the same value gives us a pretty fair spread between values, however the values can change slightly due to the tolerance of resistors and parasitic resistance in the circuit.

So after making a prototype circuit, you should determine the values for each button, and then have your sketch look at a range of values when reading the analog pin. Doing so becomes more important if you are producing more than one of your project, as resistors of the same value from the same batch can still vary slightly. Using the circuit from example 25.2, we will use a function to read the buttons and return the button number for the sketch to act upon:

And now our video demonstration:

So now you have a useful method for receiving input via buttons without wasting many digital input pins. I hope you found this article useful or at least interesting.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in analog, arduino, learning electronics, lesson, microcontrollers, multiple buttons, tutorialComments (9)

Introduction to the Inductor

Hello everyone!

Today we are going to explore the use of the Inductor. This is a continuation from the series of articles on alternating current. An inductor is a component that can resist changes in AC current, and store energy in a magnetic field from a current that passes through it. A changing current (AC) causes a changing magnetic field which induces a voltage that opposes the current produced by the magnetic field. This is known as the inductance.  One could think of an inductor as an AC resistor. But first of all, what is an inductor comprised of?

In simple terms an inductor is a coil of wire, wrapped around a core. The core forms a support for the coil of wire – such as ceramic cores, or in some cases can affect the properties of the magnetic field depending on the chemical composition of the core. These may include cores formed from ferrite (usually zinc and manganese, or zinc and nickel) or powdered iron (which has a tiny air gap allowing the core to store a higher level of magnetic flux (the measure of magnetic field strength)allowing a higher level of DC current to flow through before becoming saturated.

So, the amount of inductance is influenced by several factors – the core material (as above), the size and shape of the core, as well as the number of turns of wire in the coil and its shape. The unit of inductance is the henry (H), however common values are usually in the millihenry (mH) or microhenry (uH) range.

Furthermore, there is an amount of DC resistance due to the properties of the coil wire, however this is usually negligible and kept to a minimum. For example, looking at a data sheet for a typical line of inductors – inductors.pdf – the DC resistance of a 10uH inductor is a maximum of 0.05 ohms. With inductors of higher values, the DC resistance will need to be taken account of. But more about that later.

This is the usual symbol for an inductor in a schematic:

However this may also be used:

And here is a variety of inductors in the flesh:

10microhenryss

radial ferrite core, generally for PCB use, handles around 1.5 amperes

radial leaded, very low resistance, handles around 2.5 amperes

ferrite core, convenient for through-hole PCB

phenolic core

toroidal – handles large currents ~10 amperes depending on model

surface-mount, can still handle around 500 mA

All of the pictured inductors have an inductance of 10 uH. Now let’s examine how inductors work with alternating current. Consider the following circuit:

1

 

Just like capacitors in AC circuits, an inductor has a calculable reactance. The formula for the reactance (X, in ohms) of an inductor is:


where f is the frequency of the AC and L is the value of the inductor in Henries (remember that 1uH is 10 to the power of -6). The formula to calculate the impedance of the above circuit is:

where Z is in ohms. And finally, the formula for AC Vout is

The formula for DC Vout is the usual voltage dividing formula. In this case, as we consider the inductor to not have any resistance, DC Vout = DC Vin.

So, let’s work through an example. Our DC Vin is 12 volts, with a 2V peak to peak AC signal, at a frequency of 20 kHz. The resistor R has a value of 1 kilo ohm, and the inductor L is 10 millihenries (0.01 H). A quick check of the data sheet shows that the 10 mH inductor has a resistance that cannot be ignored – 37.4 ohms. So this must be taken into account when calculating the DC Vout. Therefore we can consider the inductor to be a 37.4 ohm resistor when calculating the DC Vout, which gives us a result of 11.56 volts DC. Substituting the other values gives us a reduced AC signal voltage of 1.24 volts peak to peak.

Another interesting fact is that there is a relationship between AC Vout and the frequency of the AC signal. In the video below, I have used a 10k ohm resistor and a 10 uH inductor in the circuit described above. The frequency counter is measuring the frequency of AC Vin, and the multimeter is measuring the AC Vout:

This is an interesting relationship and demonstrates how an inductor can resist alternating current, depending on the frequency.

Thus ends our introduction to the inductor. We will continue with the inductor in the near future. I hope you understood and can apply what we have discussed today. As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement, you can either leave a comment below or email me – john at tronixstuff dot com.

Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts. Or join our Google Group and post your questions there.

Posted in education, inductor, learning electronics, lesson, test equipment, tutorialComments (0)


Subscribe via email

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: