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.

[youtube https://www.youtube.com/watch?v=51opc4rydkY&w=640&h=360]

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.

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.

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

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.

Part 2: Wiring it up.

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.

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.

Part 3: Change the code.

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.

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

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

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.

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”.

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.

Part 5: Potentiometers.

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.

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.

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”.

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.

So much has happened recently that the Roundup of New Maker Products is split into two. This is all the rest of the stuff. So, go and hide your wallets! Continue reading Weekly Roundup #64 – New Maker Products→

So much has happened recently that the Roundup of New Maker Products is split into two. This is all the Crowd Funding and Tindie stuff. So, go and hide your wallets! Continue reading Weekly Roundup #63 – New Maker Products→

This first Weeky Roundup of the year and we're already seeing lots of new goodies from SBCs, to WiFi modules, but really a tonne of new SBCs. Continue reading Weekly Roundup #62: New Maker Products // News→

There's been a lot of speculation from the SBC community about what the Raspberry Pi 4 will look like and the Raspberry Pi Foundation has really kept the lid on it. However, I was recently given a pretty honorable opportunity. To road-test a prototype of the Raspberry Pi 4. Yeah!

The NanoPi NEO4 is probably the smallest RK3399 based SBC on the market currently. Does it have enough to take on the competition? Find out in this video. Continue reading NanoPi NEO4: Smallest RK3399 SBC. What is real, NEO? // Review→

The Orange Pi RK3399 is yet another board to join the ranks of RockChip RK3399 based SBCs. In true Orange Pi fashion, they give you everything, but is this SBC worth it? Continue reading Orange Pi RK3399: HDMI recording on a budget // Review→

This quick project shows you how to build an MQTT controlled RGB LED matrix panel in under 30 minutes, but I reckon it should take you a lot less. Continue reading Build an MQTT based RGB LED panel! // Project→

Do you want to be able to send an SMS over 20kms without using a mobile phone network? Here's one small project you can knock up in less than a day allowing you to send an SMS over LoRa. Continue reading SMS over LoRa: Long distance SMS without 4G //

If you're a fan of GoLang then your options are limited in the embedded world. So, here's a couple of options for you with a working bare metal example for an STM32 MCU written entirely in Go. Continue reading Running GoLang on an STM32 MCU. A quick tutorial.→

This is the second part of my video on building a simple PCB using EasyEDA. This time we'll be taking a look at how to use a solder stencil, placing SMD components, soldering using kitchen equipment and how to fix up your mistakes. Continue reading Make a PCB from scratch

A follow-up to my video tutorial: "Program an Atmel SAM without an IDE". I've created a Docker container on GitHub with a complete ASF build chain. Ready to go. Go for it! Continue reading Atmel Software Framework and build chain in a Docker container→

A bit of a different mailbag this week. Containing a lot of bits and pieces for upcoming projects and other odds and ends. Continue reading MickMake Mail #30: Gakken, JLCPCB, wicking and skulls // News→