basic-electronics-for-arduino-makers
basic-electronics-for-arduino-makers
These days you can do so much with an Arduino that you almost don’t need to know anything
about electronics! But there are a few basic things that, when you learn them, open you up to a
much bigger world of possibilities. In this short guide, you’ll learn:
• The basics of electricity so that you can understand how it works, instead of trying to
memorize formulas.
• How to choose resistor values for LEDs so you don’t have to rely on the calculations of
others.
• How to use transistors so that you can control things like relays, motors, fans, and LED
strips with your Arduino.
• How to use analog sensors so that you can start seeing what’s going on outside of your
Arduino too.
Wires and components are always completely filled with something called charges. When these
charges move, you have current. To get these charges to move, you need voltage.
It’s the movement of these charges that is the current, not the charges themselves. Since the
wires are always completely filled with charges, it means that they must move at the same
speed both at the beginning and at the end of the wire.
That means the current flowing out from a voltage source (such as a battery), is the same as the
current flowing back in!
Many are surprised by this fact. And I often get the question “but how does a battery die if the
current is the same coming back in?”. The thing is that the battery doesn’t store current. Current
can’t be stored. It’s the battery’s ability to push charges around in the circuit to create current
that eventually drains out.
Resistance
The final concept to understand is resistance. Resistance in a circuit resists the current. The
more resistance a circuit has, the more voltage is needed to get the same current. You can think
of resistance as a tighter tube, making it harder for the charges to move.
Ohm’s law is basically just a simple formula that makes it easy to calculate voltage, current, and
resistance. You can use it to find what resistor value you need for an LED. Or to find out how
much power your circuit uses. And much more.
This is one of the few formulas in electronics that you’ll use on a regular basis.
V=R*I
• V is the symbol for voltage.
• I is the symbol for current.
• R is the symbol for resistance.
You can switch it around and get R = V/I or I = V/R. If you have two variables, you can calculate
the third. An easy way to find the formula for one specific variable is to use this triangle:
Use your hand to cover the letter you want to find. If one of the remaining letters is above the
other, it means dividing the top one by the bottom one. If they are next to each other, it means
multiplying one with the other.
V=I*R
I = V/R
Here’s the formula for calculating the minimum resistance value you need:
You’re using an Arduino UNO with 5V pins and you want to light up an LED with a forward voltage
of 2.3V. You do not want to go above 10 mA for the LED.
VPIN: 5V
VLED: 2.3V
ILED: 0.01A
Remember, if you don't have the exact value of resistor, you can always use the nearest value
going up. It's better to use a slightly higher value of resistance than a lower one to avoid
damaging the LED.
10 mA is a common current value for LEDs that will make it light up, without damaging it. The
only way to find the maximum current that an LED can withstand is to check its datasheet.
A transistor acts as a switch, allowing a small signal from the Arduino to control a larger voltage
and current needed to run the motor.
If you need a lot of voltage or current, MOSFET is the best choice. If you only need a hundred
milliamps or so, then BJT will also work fine.
Each transistor type exists in an n-type and a p-type. The n-type is the most common one to use,
so that’s what you’ll see in this booklet.
In this example circuit, an Arduino control a motor using an NPN transistor (BJT).
The BJT needs a resistor (R1) in between the output pin and the base of the transistor to limit the
current flowing through the base. 1000 Ω is a good starting point for R1. You can learn how to
calculate it for your specific situation in this article.
Connect your load (ex your motor) between the plus and the collector of your transistor.
When you set the output pin HIGH, the transistor turns on and allows current to flow through it.
This means your motor turns on. When you set the output pin LOW, the transistor turns off and
no current can flow through it. This means your motor turns off.
The diode (D1) is there to protect the transistor from back-emf of the motor. It will work without,
but you’ll most likely damage your transistor after a short while.
The MOSFET does not need a resistor in between the output pin and the gate of the transistor.
But it’s good to place a resistor from gate and down to ground, otherwise your transistor will be
left in an ON state if you turn off your Arduino when the transistor was on.
Connect your load (ex your motor) between the plus and the drain of your transistor.
When you set the output pin HIGH, the transistor turns on and allows current to flow through it.
This means your motor turns on. When you set the output pin LOW, the transistor turns off and
no current can flow through it. This means your motor turns off.
The resistor value you choose will affect the sensitivity of your sensor. Often, resistors between
10k and 100k are used. But feel free to experiment to find the best value for your use case.
When reading the value from the Arduino pin, you’ll get a number between 0 and 1023. 0 means
0V and 1023 means 5V. With the following code, you’ll convert that number into the actual
voltage that’s on the pin:
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
delay(1000);
}
If you need to know the resistance value of your sensor, you can calculate it using this formula:
𝑉𝑠𝑢𝑝𝑝𝑙𝑦
𝑅𝑠𝑒𝑛𝑠𝑜𝑟 = 𝑅𝑓𝑖𝑥𝑒𝑑 × ( − 1)
𝑉𝑚𝑒𝑎𝑠𝑢𝑟𝑒𝑑
void setup() {
Serial.begin(9600
}
void loop() {
int sensorValue = analogRead(analogPin);
float V_measured = (sensorValue * V_supply) / 1023.0;
float R_sensor = R_fixed * ((V_supply / V_measured) - 1.0);
delay(1000);
}
1. Getting Started With Electronics is a short and beginner-friendly eBook I wrote to help
people get started. It contains clear and simple instructions to get started building
electronics. Perfect for complete beginners.
2. Our online classes at Ohmify is for those who want to learn skills like soldering, circuit
design, Arduino, and PCB design and more in order to confidently create electronic
gadgets and tools – and who are prepared to take action to make it happen.
Keep On Soldering!
Oyvind @ build-electronic-circuits.com