Learning Arduino: Pullups and Analog Inputs // Episode 4 // Tutorial


YouTube video: Learning Arduino: Pullups and Analog Inputs // Episode 4 // Tutorial


MickMake is teaching Tim how to program an Arduino so that he can build an automatic firing mechanism for his Nerf guns. In Episode 4 he learns about resistor colour codes, pullup resistors, potentiometers, and reading Analog data.

By the end of this course he will be able to not only do that, but create a world of modding opportunities that will keep him busy for years. Everything that we will cover in this video series will help you to do the same, no matter what your project goals are. If you have any questions or comments feel free to ask on Facebook or YouTube.

ERROR:not .src - map[alt: class: control: ctx:0xc01146abe0 height: href: id:51opc4rydkY inline: size: span: src: style: thumbnail: title: width: xml:]

In this fourth episode we will be taking a look at:

  • Resistor colour codes.
  • Wiring up the Button sketch tutorial from the Arduino IDE.
  • Making changes to that.
  • Wiring up the Analog sketch tutorial.
  • What is a potentiometer?

Part 1: Resistor codes.

MMM-LA4-Part1

Resistors have a colour code printed on them so you can tell what value it is. Normally you will find 4 coloured bands, but sometimes you can also find 5 or 6 bands.

MMM-LA4-Part1f

If you google for “resistor colour code” you will come up with many many examples.

MMM-LA4-Part1e

By matching up the colour to the number in the chart you can decode what value your resistor is. The first and second band define the first and second number of the resistor and the third is the “multiplier”. So in the below example we have a 25,000 Ohm resistor.

MMM-LA4-Part1c

Part 2: Wiring it up.

MMM-LA4-Part2

As shown in Episode 3 we had an issue with a “floating input”. A floating input can be solved by placing a “pullup” resistor attached to the input and Vcc which will set the default state of the input to a logical 1.

MMM-LA4-Part2b

Then the switch will pull this to Ground becoming a logical 0. When pulled to Ground, current will flow from Vcc through the resistor to Ground. Also, whilst in this state there will be an effective short between the input pin and Ground. Therefore, the input pin will always be either at Ground, (logical 0), or Vcc, (logical 1).

A high resistor value will ensure that you don’t draw too much current when at a logical 0. A good value for a pullup resistor is around 10K ohms.

MMM-LA4-Part1b

Part 3: Change the code.

MMM-LA4-Part3

Now that we have our pullup resistor wired up, we can move back to the code. The Arduino sketch being used is the Button tutorial.

MMM-LA3-Part2d

This is located under “File” -> “Examples” -> “02.Digital” -> “Button”.

In the video Tim sees just how effective a pullup resistor can be.

MMM-LA4-Part3c

In this video I also give Tim a challenge. See if you can modify the default “Button” sketch to blink the LED on and then off when you have the switch in one state, and always off in the other.

Part 4: Analog tutorial.

MMM-LA4-Part4

Now we understand the concept of digital inputs we can move on to analog inputs. We will be using the “AnalogInput” sketch of the Arduino IDE.

This is located under “File” -> “Examples” -> “03.Analog” -> “AnalogInput”.

MMM-LA4-Part4b

To be able to run the Analog sketch you will need a potentiometer. This is also called a variable resistor. In the video Tim had to re-assign the Analog input to another pin. Depending on what Arduino you have you can re-assign the pin to any of the Analog pins by changing the sensorPin variable at the top.

MMM-LA4-Part4c

Part 5: Potentiometers.

MMM-LA4-Part5

So what is a potentiometer?

A potentiometer, (or “pot” or “trimpot”), is a variable resistor. That is; it’s resistor value can be changed by turning a knob.

A pot will usually have it’s value on the side. This refers to the full scale resistor value and can be measured between the two end pins. The middle pin connects to a brush inside the pot that will move over the internal resistor. It’s value can be measured between the middle and either one of the outer pins.

MMM-LA4-Part5b

Pots are used for many reasons. They have been historically used for volume control, but also have many other uses. For example: Control of UAV flight bias/trim, fan speed, lighting levels, etc. However, the more we extend into the digital life, the less you will see pots, as the same level of control can be achieved digitally.

A pot can be used as a “voltage divider”. This is the basis of the AnalogInput sketch.

MMM-LA4-Part5d

A voltage divider applies a ratio that is set by two resistors. In the above example we have two resistors of the same value. This means the centre tap will be 2.5v if Vcc is 5v.

10k/(10k + 10k) * 5 = 2.5v

If we have a 2.2K resistor at the top and 10k at the bottom then it would be:

10k/(2.2k + 10k) * 5 = 4.1v

For the AnalogInput sketch we will connect one of the outer pins to Vcc and the other to Ground. Then the middle pin connects to the Analog input of the Arduino, in this case “A1”.

MMM-LA4-Part5c

The next episode:

In the next episode Tim will be finishing up with his Analog Input tutorial, and then taking a look at writing his own sketch that will be a combination of three different sketches; The Button, AnalogInput and Fading sketches.

Suggested post

Related

Mick Hellstrom avatar
About Mick Hellstrom
Hacker. Maker. YouTuber.

MickMake forums