I remember the first time I got ‘blink’ to work on my Arduino Uno. I never knew a blinking LED could be this exciting. But that was just the start!
In this course I’d like to take complete Arduino beginners by the hand and walk through everything you need to know to start engineering with an Arduino platform.
What you will need
- Any Arduino platform. I recommend the Arduino Uno
- The Arduino software
- USB A/B Cable
- Computer (or laptop). I’ll be using Windows 10.
Setting up the Arduino
Download the latest software from the Arduino website. Install the Arduino IDE (Integrated Development Environment).
Attach the Arduino to your computer with the USB A/B cable and wait for the drivers to install. Windows will notify you when this is done.
Testing your setup with blink sketch
Open up the Arduino IDE. You will see the following screen:
Check if under Tools > Ports the Arduino is present and select it. Now go to File > Examples > 01.Basics and choose blink. The code (sketch) will be loaded into the IDE.
In the topleft corner are the verify (left) and upload button (right).
When pressing the verify button, the code will be checked on mistakes and errors. When pressing the upload button this will also happen but when the code is alright, it will be uploaded to the connected Arduino platform. If the code contains errors and mistakes, then they will be visible in the black box at the bottom of the IDE. This black box is called the console. When the verification fails, the code wont be uploaded to the Arduino Board.
Press the upload button and wait a few seconds. While the code is being uploaded to the Arduino board, you will see some LEDs blink and text flash in the console. When this stops, you will see that one LED is blinking slowly on the Arduino Board.
Now we know your setup is working and your Arduino Board isn’t faulty.
With KiCAD it is possible to easily make your electronics dreams come true. In this tutorial we’ll go through the whole process from an idea to a 3D render of a PCB with the use of KiCAD.
First we’ll need to download KiCAD. I’ll be using version 4.0.5. for Windows (10) for this tutorial. KiCAD is totally free and can be downloaded here.
Making a schematic
After installing and starting KiCAD you’ll see the main workspace.
Most work will happen with the first and third button of the 8 big buttons. Each button represent a seperate program that is used to make the PCB.
Start a new project by pressing CTRL+N or by clicking File > New Project > New Project. Give the project a nice name and after that press the first big button on the left.
A program called Eeschema will start now. In this program we will be making our schematic. You will see a big white canvas with a red border. The schematic will be made within this border. To the right are a few buttons we will be working alot with and to the left are a few buttons we’ll leave alone for now.
We will be making a LED strip with 8 manual selectable LED’s. This is done by a DIP switch, 8 resistors and 8 LED’s. We’ll use a screw terminal as input for the power supply. Ofcourse this is a very easy project but it’s all for you to get used to KiCAD.
First press the place component button or SHIFT+A and click somewhere within the red borders. A new screen will pop up where you will have to pick the component to place in the schematic. All components are stored in libraries. There are libraries for LED’s and resistors etc. The project will have a few default libraries imported already but the one we’ll need for the DIP switch isn’t included in any of them. Therefor we’ll need to import that library ourselves.
Close the component selection screen and go to Preferences > Component Libraries. Press the most upper ‘Add’ button and find switches.lib. Open it and close the component library screen. Now go back to the component selection screen.
Go to switches and select SW_DIP_x08 and press OK. The component will be stuck to your cursor so find a nice spot and drop it there. Congratulations you placed your first component!
Now for the other components:
- 8 Resistors: Type R as filter and choose R. This is a standard resistor schematic symbol. Repeat this another 7 times or press C when hovering over a resister to copy it.
- 8 LED’s: Type in LED as filter and choose LED. This is also a standard schematic symbol for a LED. Do the same as above to get 8 of them.
- Screw terminal: Type in screw as filter and select Screw_Terminal_1x02 from the conn library.
Wire it all up
Now that we have all the components on screen, we’ll have to connect them together. Press the Place Wire button or SHIFT+W and connect them in the following way:
Don’t worry too much about overlapping labels, you can move them by hovering over them and pressing M. You can find the +5V and GND symbols by pressing the Place Power Port button or SHIFT+P.
The schematic is almost done. First we’ll want to give the resistors a value. Do this by hovering over the R of a resistor and press V. A screen will pop up where we can change the R into any value. Let’s do a quick Ohm’s law calculation to find out what value we need:
Calculating the current limiting resistors value for the LED’s
We’ll most likely be using a standard 5mm red LED. These LED’s burn nicely when 20 mA flow through them. Because we probably use an Arduino or other digital output, we’ll be working with a 5V power supply to the LED’s. Now you might think: “We got the amps, we got the voltage… we can calculate the resistance needed!”. That’s not completely true! A LED is a weird thing as it needs at least (about) 2 volts to start working. Therefor we need to subtract 2 volts from the supply voltage. Let’s see:
U = 5-2 = 3 v
I = 20 mA
R = ?
R = U / I = 3 / 20mA = 150 Ohm
Seems like we’ll need to give the resistors a value of 150 Ohm.
Finishing the schematic
When all the resistors have a value we’ll need to number all components so it is easier to refer to them. We luckily don’t have to do this manually! Press the Annotate schematic components button on the top bar. The following screen will popup:
Use the above settings and press Annotate. Before annotating the components you might have noticed that the components said things like R? and D?. When annotating these question marks change into a number.
The last step is to check if there are no bugs in the schematic like unconnected components. Press the Perform electric rules check button . In the new popup press Run.
Two error messages appear and in the schematic there will be an arrow pointing at the places where the error is found. In KiCAD you have to ‘drive’ power pins to make this error go away. To do this go back to the schematic and press the place power port button again. Type pwr_flag as filter and choose PWR_FLAG. Add two of these in the schematic and copy the power ports and connect them in the following way:
Run the Perform electric rules again and see the errors disappear.
Now that we are done with the schematic, it’s time to assign footprints to the components. Footprints contain the solder pads (and silkscreen) that correspond to the physical components. This will be used later when designing the PCB. Press the Run CvB button . It will take a while for the screen to load. The following screen will appear:
In the left column are the available footprint libraries, in the middle are our components in the schematic and to the right are the available parts in the library. Assign components in the following way:
- LEDs (D1 – D8):
- Resistors (R1 – R8):
- Dip switch (SW1):
- Screw terminal (J1):
The screen should look like this now:
Press the save button and go back to the schematic.
Generating the Netlist
By generating the netlist we make a file that the PCB designing software can understand. The netlist contains the information about the footprints and labels to name a few. To make a netlist, press the Generate netlist button on the top bar and then press generate and save the file.
Now it’s time to make the PCB!
Making the PCB
Get back to the mainscreen and press the third big button from the left. PCBNow will open.
You’ll see the same kind of screen as in Eeschema. Our PCB will be made within the red borders. Let’s import the netlist so the program knows what it’s going to work with! Press the Read netlist button in the top bar. The following screen will popup:
Use the same settings and press Read Current Netlist. Open the file we made earlier. If everything went right there won’t be any errors during opening. Press Close and see how all components are dropped on top of eachother. To spread these out press the mode footprint button . Now right click on the components and select Global spread and place > Spread out all footprints. This will evenly spread the components for a better overview.
Arranging the components
Now it’s time to arrange the components in a logical way. Hover over a component and press M to move a component. Try to make the arrangement efficient, aesthetically pleasing and logical. Try to have the gray lines overlap as little as possible. I arranged it like this:
Now it’s time to connect all the components. Press the add tracks and vias button on the right bar and start routing all components by laying tracks between all gray lines. A gray line will disappear when the connection has been made. Don’t route the grounds yet! We’ll use a trick to do that!
For this design the routing is fairly easy but what if gray lines overlap often? We are using a two sided PCB which means we have two layers to work on! To the right is a menu with all the available layers.
As you can see we are working on the F.Cu layer. F means Front and B means Back. You can use the ‘page up’ and ‘page down’ keys to switch between F.Cu en B.Cu. This is very useful cause it grants the ability to go under or over an already laid track like so:
After laying all tracks except the grounds my PCB looks like this:
Now it’s time to magically connect all grounds together. We do this by making a ground plane. Before doing that, we’ll have to define the edges of the PCB. In the layer menu select the Edge.Cuts layer. Now select the Add graphic line or polygon tool on the right sidebar. Draw a nice rectangle or other creative shape around the components but keep in mind to leave a little space when drawing next to the solder pads. My design looks like this:
Maybe I should’ve left more space between the components but for now this will be quite aesthetically pleasing. Now it’s time for the ground plane!
Go back to F.Cu or B.Cu and select the Add filled zone tool and click on any edge of the edge cuts we just made. A screen will popup asking you what plane you want to make.
Select GND in the Net menu and click OK. Now trace the edge cuts and at the end double click to make the plane. Red dashes will appear around the edge cuts. Now right click somewhere on the board and select Fill or refill all zones. The board will magically look professional! Notice how all gray lines are gone and the ground pads have small connections going to them.
The last thing to do now is to look at your PCB in magical 3D! Go to View > 3D Viewer or ALT+3 and the 3D render will pop up!
Noticed any mistakes or have questions? Just leave a comment! Feedback is always welcome.
In this first lesson we will go over what voltage, current and resistance is and how they work together in Ohm’s law.
But first… Electrons and currentflow
Electricity is all about moving electrons. They do all the work in electronic applications. Electrons create charge. Electrical engineering is all about manipulating these charges.
Most powersources have two terminals. One of them is called the negative (-) terminal and the other the positive (+) terminal. For electrons to flow, there must be a closed circuit. This is done by connecting the two terminals with a conductor. A conductor is a material that is good at transporting electrons like copper. A material that is very bad at transporting the electrons is called an insulator like air or plastic.
When working with electronics and reading schematics its important to know that the flow of current in which we work goes from positive (+) to negative (-). This is called conventional current flow. The electronflow goes the exact other way. Why do we not use electronflow instead of conventional current flow? Well… There were mistakes made in history when determining the actual flow of electrons. So remember: We use conventional current flow in which the charge flows from a positive terminal to a negative terminal.
But before charge can flow through a conductor from the positive (+) to negative (-) terminal, there has to be a difference in charge between these terminals to actually make one more positive than the other. This is called voltage (U): The difference in charge between two points. Its important to know that voltage is always measured between two points. Voltage is measured in volts.
The rate in which charge flows is called current (I) and is measured in ampères. Higher ampère or ‘amps’ means more charge travels through the conductor in a certain amount of time. How can we control this flowrate?
The conductivity of a material is determined by the resistance of the material. We talked about how copper is more conductive than air because the electrons can easely pass through it. The harder it is for a charge to flow, the less conductive the medium is in which it travels. When the electrons have a hard time going through the material, the rate at which it travels goes down. When the rate goes down, the amps go down. See where we are going to? By introducing resistance it is possible to influence the amps going through a circuit. Resistance is measured in Ohm (R).
The equation that will start it all for starting electrical engineers is called Ohm’s law. It shows the relationship between voltage (U), current (I) and resistance (R)
R = U / I
Let’s look at our first schematic:
On top we see a voltage of 5 volts. We know that voltage is the difference between two points. What point is the second point? In this schematic that’s GND or ground. Appearantly there is a voltage of 5 volts over the square box thing. That box thing is a resistor. Resistors in real life come in all kinds of values.
Let’s use the values in the schematic to find out how many amps go through the resistor!
R = 100 Ω ( U = 5 V
I = ? A
When doing a bit of algebra we can arrange Ohm’s law to calculate the amount of current:
R= U / I => I = U / R = 5 / 100 = 0.05 A
Appearantly the currentflow is 50 milliampere. So what happens if we take a bigger resistance? Let’s look at our next schematic:
When comparing this circuit with the previous one, you will notice that the value of the resistor got 10 times bigger. Let’s do the math again!
R = 1000 Ω
U = 5 V
I = ? A
I = U / R = 5 / 1000 = 0.005 A
Looks like when we made the resistor 10 times bigger, the current became 10 times smaller! Now we’ve proven that a larger resistance limits the currentflow in a circuit!
How else could we limit the current flow? Use Ohm’s law and the schematics to find out yourself!
When beginning with electronics you’ll get introduced to alot of beginner projects. One of those probably uses the 555 timer IC to generate pulses that make LEDs flash or speakers buzz. This generation of pulses is called oscillation and is used in electronics everywhere.
A more primitive way to get oscillation is with a very ancient circuit called the ‘transistor LED flasher’. This circuit uses a very nifty way to create oscillation. Also notice how the circuit is perfectly symmetrical.
R1 and R4 limit the current through the LED and R2+C1 and R3+C2 determine the speed in which the capacitors loads and thus determines the switching speed of the transistor. The speed (frequency) at which the oscillator ‘vibrates’ goes up when R2 and/or R3 go lower in value or when the capacitors go lower in value.
The values to choose for the components depend on the supply voltage. In this case with a 9 volt power supply (like a battery) the current limiting resistor for the LED’s (20mA) should be:
R1 & R4 = U / I = 9-2.8 / 20mA = 7 / 20mA = 350 Ohm. (Subtract 2.8 volts because of the forward voltage of the LEDs and transistor internal diode!)
The frequency of the circuit where C1=C2 and R2=R3 is given by:
f = 0.72 / RC
For example we use 68k Ohm as R2=R3 and 4.7 uF as C1=C2 then the frequency is:
f = 0.72 / 68000 * (4.7*10^-6) = 2.25 Hz
If the values of C1 != C2 and R2 != R3, then the following equation applies:
f = 1 / (0.693 * (R2*C1 + R3*C2))
Applying this equation to the same values give:
f = 1/(0.693 * (68000*(4.7*10^-6) + 68000*(4.7*10^-6))) = 2.25 Hz
The circuit above has been transferred to the following PCB:
As you can see I forgot that ground planes were a thing. Using ground planes would’ve got rid of a lot of unneeded traces and would’ve made the PCB single sided instead of two sided. Also the fancy edge cutting wasn’t necessary but I like to make the boards look odd. The 3D render proves that
After finishing the 3 component modules I wanted more of a challenge. I looked up the datasheet of the infamous LM386 audio opamp that is featured in many cheap audio applications.
Datasheets from IC’s like opamps often contain a ‘typical application’. These are circuits that show off the basic configuration of the IC or a simple implementation of the IC for various applications. For the LM386 I took the typical application for an audio amplifier with bass boost.
I took the schematic and remade it in KiCAD
Then I laid down the PCB
Also added a little silkscreen text to show who the creator is. The 3D render is pure art
Feedback is always welcome!
When looking at different electronics webshops that sell modules to make life easier, I got shocked by the way they turn any electrical component into a module. Then I thought let’s keep going with the easy modules and I made a module for an RGB LED.
The schematic is as easy as can be:
The labeling is a bit messy but the idea is there. The left connector represents male pin headers and the right connector represents the RGB LED. The resistors are used to limit the current to each LED. Note that every LED need a different value resistor.
The PCB layout is quite artistic again. I noticed how the solder pads for ground are rectangular and the others are circular. After a bit of research I found out that the positive voltages always use rectangular pads. Well, let’s call it a small design flaw then.
The 3D render looks pleasing again
Any feedback is welcome!