What is a pin-‘Uino? The term is a portmanteau of the words pinball and Arduino. As you are probably reading this article in Pinball News’s Learn How section, you may be familiar with pinball machines. However, you may not be familiar with the Arduino.

Arduino is an open-source platform for ATmega 168 and 328 microcontrollers. You can use the microcontroller as part of your own custom pinball add-ons, modifications and toppers.

Arduino is the American-branded version. Genuino is the version branded for the rest of the world. Save labeling differences, both boards are very similar. An Arduino UNO board and Genuino UNO board are juxtaposed, below.

The Arduino and the Genuino
The Arduino and the Genuino

For more information about using an Arduino microcontroller, see the instructions put together for middle schoolers, Intro to Arduino. Be sure to read this instruction article before continuing with this project article (pin-‘Uino).

Don’t be fooled by the simplicity of the instructional article or this project article. Some very complex programs (sketches) can be run on most Arduino microcontrollers and their clones. In fact, entire pinball machines have been built using the surprisingly powerful Arduino and clever programming.

Old vs. New

In a set of previous Pinball News articles, we shared with you relay controllers you could use to make your own custom pinball add-ons, modifications, and toppers.

Note: See these articles for information, description of discrete electronic parts and where to purchase those parts.

As in the previous two articles, although we are still going to use a light dependant resistor (LDR), this third article moves on from using a simple relay controller to a microcontroller; namely the Arduino UNO (R3, 5 Volts).

Note: See the end of this article for additional parts and purchasing information.


Relay vs. Microcontroller

The discrete electronic component known as a relay is considered a ‘dumb’ device. We will be using a ‘smart’ (programmable) device; a microcontroller.

Though not capable of handling high power like a relay, with the 40 milliamp maximum peak (per pin) current handling capabilities of the UNO we can safely run a handful of Light Emitting Diodes (LEDs) to add new lamps to our pinball machines or pinball projects.

For the learning purpose of this project and as to NOT overload the microcontroller, we will be using a single indicating Light Emitting Diode (LED). An alternate sketch and additional add-on method for using a UNO microcontroller to light multiple LEDs are both mentioned later in this article, but they are not covered in much detail. If you want to light multiple LEDs see the links in the Intro to Arduino article and at the end of this article for more information.

In this primer article, we will be using either a single T-1 3/4 (ø5 mm) or T-3 1/4 (ø10 mm) radial leaded discrete electronic component. One of several colors will work. This type of LED usually requires about 20mA of direct current. Unfortunately, you can’t just plug an LED straight into your +5 Volt UNO. You must use a dropping resistor in series with the LED.

General +5V Rules for Indicator LEDs and their Dropping Resistors
LED Color RED ORANGE YELLOW GREEN BLUE WHITE
Nominal LED Voltage (DC) 1.5 2.0 2.0 2.5 3.0 3.5
Calculated Dropping Resistor Value (Ohms) 175 150 150 125 100 75
Nominal Dropping Resistor Value (Ohms) 200 150 150 150 100 100

The LED/resistor table was made specifically for use with +5 Volt Arduino boards. From the table, you can see that the smaller the voltage for a specific LED, the larger the Ohm value for its dropping resistor. The larger Ohm value of the dropping resistor, the greater voltage ‘dropped’ across that resistor.

For our purpose, a 1/4 Watt axial leaded resistor should work just fine. This dropping resistor needs to be rated at a 1/4 watt to handle the electrical power going through it. And, its lead thickness is good for plugging into the headers of the UNO.

Look back at the LED/resistor table, notice there are five different calculated dropping resistor Ohm values. From an electronics engineering viewpoint and in practical use, only three nominal Ohm values are needed: 200, 150, and 100 Ohm. This is because the calculated Ohm values are close enough to the nominal values when lighting discrete indicator-type LEDs.

From a literal human viewpoint, due to the way we humans perceive brightness it is hard for us to even notice the slight change in brightness; when we use a near value resistor versus the calculated value when lighting a LED. This is an example of the inverse-square law of light in effect with human eye physiology.

The LED/resistor table shows both actual calculated values and nominal values. The calculated values are real values, whereas the nominal values are easily chosen close values, either for convenience or practical availability. In this case, calculated resistor values are based on useful nominal voltage values for each LED color.


Calculate Dropping Resistors Values for Your Own LEDs

HINT 1: Remember, even if you calculate the actual dropping resistor value, you may only be able to easily purchase a close nominal value.

HINT 2: In the case of round-up to the neared available nominal value, you can see from the LED/resistor table and its explanations that an increased difference of even 25 Ohms won’t make any practical difference.

HINT 3: We’ve had great luck and even better results with (and l-o-v-e) ‘Gumdrop LEDs’. Use your favorite search engine if you want to find them.

You may either use the table provided as a practical reference, or you may choose to calculate the actual dropping resistor value (Rdrop) for your own LED. If you wish to calculate the actual value of you own dropping resistor, start by using the operating voltage of your UNO. Additionally, you will need to know the following:

  • Voltage In (Vin)
    This value is 5.0 for five volt UNO boards.
  • LED Voltage (Vled)
    See the seller’s specifications.
  • LED Current (Iled)
    See the seller’s specifications.

The following formula is based on Ohm’s Law. Use the actual values above in the formula below:

Rdrop = (VinVled) / Iled

When reviewing manufacturer’s specification, you many need to substitute the following technical names in the formula below:

  • Voltage In (Vin)
    This value is 5.0 for five volt UNO boards.
  • LED Voltage (Vf)
    See the manufacturer’s specifications.
  • LED Current (If)
    See the manufacturer’s specifications.

R = (VinVf) / If

If you chose to perform the dropping resistor calculation (Rdrop or R), why not use your UNO?

Enter the following sketch into your UNO to easily calculate the value of Rdrop or R.

NOTE 1: This program has been released under GPL. Freely use and modify the CalcLEDDropResist sketch.

NOTE 2: In order to use communication via the Serial Monitor window, you will need to keep a USB cable connected between your computer and your UNO.

The Calc_LED_Drop_Resist.INO sketch is a simple Ohm’s Law calculator/solver for single resistor/LED combinations.

Open the Arduino application and copy/paste the following sketch over the entire staring program in a new sketchbook window. Save the sketch as Calc_LED_Drop_Resist.INO. For information on how to do this, see Intro to Arduino.

/* CalcLEDDropResist.INO
Todd Andersen
06-JAN-17This sketch requests users to enter specific values in the Serial Monitor
Those values are used to calculate the value of the LED Dropping ResistorDropping Resistor Value (Rdrop)
Voltage In (Vin)
LED Voltage (Vled)
LED Current (Iled)
R = (Vin – Vled) / Iled
*/#include “math.h” // Include the Math Library
float Vin;
float Vled;
float Iled;
float Rdrop;
char junk = ‘ ‘;void setup(){ // Setup sketch
Serial.begin(9600); // Serial Terminal baud (9600 bps)
Serial.println(“”);
Serial.flush();
}void loop(){ // Calculate Rdrop
Serial.println(“Calculate the value for your Dropping Resistor, ‘Rdrop'”);
Serial.println(“Enter the voltage for ‘Vin’, Press ENTER”);
while (Serial.available()==0); // Wait here until input buffer has a character
{
Vin = Serial.parseFloat(); // Input Vin
Serial.print(“Vin = “); Serial.println(Vin,DEC/10);
while (Serial.available()>0) // Serial.parseFloat(), User input
{junk = Serial.read();} // Clear keyboard buffer
}Serial.println(“Enter the voltage for ‘Vled’, Press ENTER”);
while (Serial.available()==0);
{
Vled = Serial.parseFloat(); // Input Vled
Serial.print(“Vled = “); Serial.println(Vled,DEC/10);
while (Serial.available()>0)
{junk = Serial.read();}
}Serial.println(“Enter the milliamps for ‘Iled’, Press ENTER”);
while (Serial.available()==0);
{
Iled = Serial.parseFloat(); // Input Iled
Serial.print(“Iled = “); Serial.println(Iled,DEC/10);
while (Serial.available()>0)
{junk = Serial.read();}
}Rdrop = ((float(Vin-Vled)/Iled)*1000);Serial.print(“Dropping Resistor = “);
Serial.print(Rdrop,(DEC/100));
Serial.println(” Ohms”);
Serial.println(“”);
Serial.println(“”);
}

You should see something similar to the following:

The CalcLEDDropResist.ino sketch
The CalcLEDDropResist.ino sketch

Use your UNO to calculate dropping resistor values:

  • Click the magnifying glass in the upper right corner of the sketchbook window
  • A Serial Monitor window will open
  • Follow the on-screen instructions
  • Enter the requested values in the top line
The Serial Monitor window
The Serial Monitor window

Use the specific values from the Manufacturer’s specifications:

  • Enter all the requested values: Vin, Vled and Iled
  • The dropping resistor value will be given with the last ‘Press ENTER’

NOTE: The sketch will then automatically reset; for you to calculate as many dropping resistor values as you need.

The dropping resistor value
The dropping resistor value

Making your Connections

In the end, programming comes down to just ones (1s) and zeros (0s). Due to limitations such as these, programmers must find creative solutions to complete their projects.

One creative solution can save us from having to solder. That solution is to use a clever combination of (2.54mm / 0.1 inch DuPont connector) male and female jumper cables.

The right combination of a variety of jumper cables works surprisingly well, using a little hot glue to shore up each junction.

The following pictures show such DuPont jumper cables, on their own and in use.

Dupont jumper cables
Dupont jumper cables
Male and female jumpers
Male and female jumpers
Using jumper cables to connect the LED
Using jumper cables to connect the LED

UNO Board LED/Resistor Jumper Cable:

  • Plug one end of your dropping resistor into the ‘GND’ pin, near pin ’11’
  • Plug the other end of your dropping resistor into one end of a jumper cable with female to female ends
  • Use a second jumper cable with male to female ends to connect between the first jumper cable and one lead of your LED
  • Use a third jumper cable with two female ends to plug into the other lead of your LED
  • Use a fourth jumper cable with two male ends to connect between the third jumper cable and pin ’11’

TROUBLESHOOTING: If your LED does not light after you run your UNO sketch, simply turn around the LED.

LED connections to the UNO
LED connections to the UNO

LDR on the UNO board:

  • Plug one end of the LDR, into the ‘GND’ pin
  • Plug the other end of the LDR, into pin ‘AO’
  • Plug one end of the 10 KOhm resistor into pin ‘AO’
  • Plug the other end of the 10 KOhm resistor, into pin ‘5V’

NOTE: You may also remotely mount the LDR on jumper cables, although it may be best to keep it on the UNO board.

Mounting the LDR and 10K resistor
Mounting the LDR and 10K resistor

IMPORTANT NOTE: When you are all done with wiring and programming, be sure to put your microcontroller LDR into a project box or use some other means to ensure your UNO project and its components don’t short to anything.

Upload the pin_uino.INO Sketch

NOTE 1: This program has been released under GPL. Freely use and modify the pin_uino sketch.

NOTE 2: In order to use communication via the Serial Monitor window, you will need to keep a USB cable connected between your computer and your UNO.

The pinUino.INO sketch turns on a single LED when the value read from the LDR is above a certain threshold, eg. during normal game play, when all the GI lights of your pinball machine are lit.

Open the Arduino application and copy/paste the following sketch over the entire staring program in a new sketchbook window. Save the sketch as pin_uino.INO. For information on how to do this, see Intro to Arduino.

/*
pin_uino.INO
Todd Andersen
01-JAN-17This example demonstrates the use of an “if (then) / else” statement.
It reads the state of an LDR (an analog input) and turns on a LED.
It prints the analog value regardless of any software or hardware inputs.The circuit:
The LDR is connected between AO and GND
The 10 KOhm Resistor is connected between AO and 5V
The LED is connected, through a dropping resistor, between pin 11 and GND
*/// Constants to set up sketch parameters
const int analogPin1 = A0;   // Pin that the sensor is attached
const int analogValue;          // Value from sensor pins
const int ledPin1 = 11;          // pin that the LED is attached
const int threshold = 500;     // threshold level in the range of the LDR in usevoid setup(){
// initialize the LED pin as an output
pinMode(ledPin1, OUTPUT);
// initialize serial communications
Serial.begin(9600);
}void loop(){
// Read the value of the LDR
int analogValue = (analogRead (analogPin1));// If the analog value is high enough, turn on the LED
if (analogValue > threshold )
{digitalWrite(ledPin1, HIGH);}
else {digitalWrite(ledPin1, LOW);}// print the analog value
Serial.println(analogValue);
delay(250);
}

You should see something similar to the following:

The pin_uino sketch
The pin_uino sketch

LDR practical values:

  • Upload the program to your UNO
  • Click the magnifying glass in the upper right corner of the sketchbook window
  • A new Serial Monitor window will open
  • Change the amount of light falling on the LED
  • Vary that the readings change in the Serial Monitor window

NOTE: These reading can give you some idea of the useful range values of your specific LDR.

The LDR readings
The LDR readings

IMPORTANT NOTE: When you are all done with wiring and programming, be sure to put your microcontroller LDR into a project box. Or, use some other means to ensure your Arduino project and its components don’t short to anything.

TROUBLESHOOTING: If your LED doe not light after you run your UNO sketch, simply turn around the LED.

Software vs. Hardware

One advantage of using a microcontroller is the ease of using software changes over hardware changes.

Keeping the same hardware configuration, you can make the LED turn off when a certain value is read from the LDR. eg. during ‘blackout’ mode, just before multiball mode. Simply change one number in your software. Unlike in the other two articles mentioned at the beginning of this article, there is no need to rewire components.

To change from Light Sensing to Dark Sensing, simply change the greater-than sign in:

if (analogValue > threshold )

to a less-than sign:

if (analogValue < threshold )

 

Don’t forget to also change your comment from:

// If the analog value is high enough, turn on the LED

to:

// If the analog value is low enough, turn on the LED

 

Is the LED changing states not quite as you expected?

Simply change the number value of the threshold in:

const int threshold = 500;     // threshold level in the range of the LDR in use

to adjust the event threshold.

  • A lesser value will create a lower threshold (trip point)
  • A greater value will create a higher threshold (trip point)

NOTE 1: The values from the Serial Monitor can help you select a useable threshold.

NOTE 2: Almost any LDR can be used with an adjustment in software.


Boring . . . what else can I program my microcontroller to make the LED do?

You can make the LED blink, flash, fade, and perform other visual effects. Use the built-in examples of the Arduino software, and the built-in LED of the UNO board to see some of the ways you can light an LED. Be sure to explore all the built-in examples, not just ‘Blink’.

Navigate (drill down) to: File Examples 01.Basics Blink

The 'Blink' example
The ‘Blink’ example

Where do I get programs to use with my project?

Now may be the time for you to start writing your own sketches. However, one last sketch is included with this article:
Conditional_If_Statements_with_Hysteresis.INO
.

This sketch lights two LEDs, one for each of two different conditions.

NOTE 1: The potentiometer may be replaced with a LDR

NOTE 2: Move the jumper side of the LED in the previous set up from pin ’11’ to pin ‘9’.

NOTE 3 In order to use communication via the Serial Monitor window, you will need to keep a USB cable connected between your computer and your UNO.

NOTE 4: Use the resources previously mentioned in this article for help.

NOTE 5: This program has been released under GPL. Freely use and modify the Conditional_If_Statements_with_Hysteresis sketch.

Put the following sketch in a new sketchbook window. Save the sketch as Conditional_If_Statements_with_Hysteresis.INO and view the Serial Monitor window as previously shown in this article.

/*
Conditional_If_Statements_with_Hysteresis.INOThis example demonstrates the use of if (then) / else statements.
It reads the state of a potentiometer (an analog input) and turns on LEDs.
It prints the analog value regardless of the level.The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* 1st LED connected, through a dropping resistor, from digital pin 9 to ground
* 2nd LED connected, through a dropping resistor, from digital pin 13 to ground
* Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don’t need any extra components to use that LEDcreated 17 Jan 2009
modified 9 Apr 2012
by Tom Igoe
modified 19 Oct 2016
by Todd AndersenThis example code is in the public domain.http://www.arduino.cc/en/Tutorial/IfStatement*/// These constants won’t change:
const int analogPin = A0;    // pin that the sensor is attached to
const int ledPin1 = 9;          // pin that the 1st LED is attached to
const int ledPin2 = 13;        // pin that the 2nd LED is attached to
const int threshold = 500;   // an arbitrary threshold level that’s in the range of the analog input
const int hysteresis = 5;      // an arbitrary hysteresis levelvoid setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);// if the analog value is high enough, turn on the 1st LED:
if (analogValue > threshold + hysteresis) {
digitalWrite(ledPin1, HIGH);
} else {
digitalWrite(ledPin1, LOW);
}// if the analog value is low enough, turn on the 2nd LED:
if (analogValue < threshold – hysteresis) {
digitalWrite(ledPin2, HIGH);
} else {
digitalWrite(ledPin2, LOW);
}// print the analog value:
Serial.println(analogValue);
delay(250);        // delay in between reads for stability
}

Luckily for us, Arduino is open source. Just use your favorite search engine to search for example programs, additional help and other useful resources.


Must my UNO Stay Plugged into my Computer?

Once programmed, your Arduino can continuously run a loaded sketch without your computer. Just apply the proper power.

To power a project needing 1 Amp or less of peak current, you can use a spare USB cable (like you used to program your UNO) and an AC/DC (+5 Volt DC @ 2 Amp) USB phone charger. See the following picture of a custom holiday pinball topper.

USB Phone Charger to Project:

  • Plug the charger into: an extension cord, a nearby wall outlet, or your pinball machine’s utility jack.
  • Plug the USB cord between the charger and your UNO project.
“It’s a major award!”
“It’s a major award!”

To power a more power-hungry project, use a Positive 9 to 12 Volt Direct Current (DC) power supply; rated at twice the estimated peak current of your project. For several Arduino boards, including the UNO, that power supply will need to have a 2.1 mm center-positive plug; which friction fits into the board’s power jack.


So where can I get one of these awesome microcontrollers and make my own pin-‘Uino project?

This article introduced you to the Arduino/Genuino UNO. This microcontroller has several different ‘flavours’ and ‘shrinkified’ versions. Use your favorite search engine and the links at the end of this article to learn about different boards and where to purchase them.


Add-ons

There are many useful add-ons for the UNO. These add-ons may help you in the learning and prototyping stages, and may even keep you from having to solder your final project.

A board which plugs directly into the UNO main board is called a ‘shield’. To name just a few, there are: Breadboard Shield (for directly plugging in discrete components), LED Shield (for multiple and/or multi-color LEDs), Motor Shield (for driving different motors), and Relay Shield (for controlling power to other devices).

Use your favorite search engine and the links at the end of this article to learn about different shields and where to purchase them. Any type of shield can usually be purchased preassembled. If you buy your shield as a kit, you can assemble it yourself and use the experience to practice soldering.

Pictured below is a Breadboard Shield.

The Breadboard Shield
The Breadboard Shield

What Else is Available for my UNO?

There are learning kits, project cases and various modules available for many Arduino/Genuino boards; not just the UNO.

This next example shows a 5 Volt Arduino/Genuino compatible module; a discrete RGB LED called NeoPixel. The NeoPixel has its own built it microcontroller and it can utilize ‘Libraries’. Libraries are sketches, put together by people from the Arduino/Genuino community to help make programming easier. The NeoPixel and Libraries are only mentioned in this introductory article to show just a tiny bit more of what you can do. Use your favorite search engine and the links at the end of this article to learn about different modules and where to purchase them.

Pictured below is a UNO/NeoPixel cycling through different colors and brightness levels. As the peak current requirements of this combination are only about 80 mA, a battery powered 1 Amp phone charger can easily power this set up for an entire night.

The UNO driving a NeoPixel
The UNO driving a NeoPixel

Built-In Help

Lucky for us, the Arduino software has built in help. Also, be sure to ‘Visit Arduino.cc‘.

Navigate to: HelpUser Chosen Section

The Arduino Help section
The Arduino Help section


Buy and Learn About Microcontroller Stuff from the Usual Suspects


Your pin-‘Uino Projects

Sorry, but Pinball News does not provide Arduino/Genuino support. However, we’d love to hear about and see your projects.

  • An Arduino microcontroller

    INTRO TO ARDUINO

    WHAT IS AN ARDUINO? Great question! There are several versions (different board configurat…
Load More Related Articles
  • The Deeproot Pinball team

    PINBALL EXPO 2018 – FRIDAY

    Welcome to Friday at Pinball Expo 2018, and we start the day back in the Seminars Hall for…
  • The Otto model and the beer barrel lock

    PINBALL EXPO 2018 – THURSDAY

    Thursday at Pinball Expo began as it always does with the Stern Pinball factory tour. At 9…
  • The Westin Chicago North Shore - home of Pinball Expo 2018

    PINBALL EXPO 2018

    Hello and welcome to our extensive coverage of the 34th annual Pinball Expo which is being…
Load More By Pinball News
  • Houdini machines under test at the American Pinball factory

    AMERICAN PINBALL VISIT

    In October 2018, just a couple of days before the official unveiling of American Pinball&#…
  • Pinspotting - August 2018

    PINSPOTTING: HERE AND THERE – SEPTEMBER 2018

    Welcome to the first edition of PinSpotting. This column will be submitted to Pinball News…
  • Middle-Pop Pinballs

    MIDDLE-POP PINBALL

    Throughout the decades flipper pinball has existed, numerous designers experimented with i…
Load More In LEARN

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

AMERICAN PINBALL VISIT

In October 2018, just a couple of days before the official unveiling of American Pinball&#…