Microcontrollers: Quick introduction to the Arduino & Raspberry Pi

Microcontrollers: Quick introduction to the Arduino & Raspberry Pi

This article is designed to give a quick (and dirty) introduction to the building electronic projects using the Arduino or Raspberry Pi, but it is in no way extensive. There are many guides on the internet that go into greater detail, but this article is to get you familiar with the basics. The main lesson to notice is that none of this stuff is as hard as it may seem, but it can seem daunting especially for a newbie. I hope that once you read this, you'll be confident enough to research more and start your own projects.

Before we begin, I will briefly explain what a Breadboard is and how it works. It is instrumental in using the Arduino, Raspberry Pi or indeed any experimental circuit. A breadboard enables you to prototype circuits quickly, without having to solder the connections. The diagram below shows you how it works. Easy enough.

Now to the main course. A microcontroller is a tiny self-contained computer system on a single integrated circuit that can be used as an embedded system. You can find programmable microcontrollers in many of the devices that we use today including but not limited to phones, peripherals, cars and household appliances. There are many types of microcontrollers and the Arduino and Raspberry Pi are just two examples of such which we will look at in this guide.

The Arduino

The Arduino micrcontroller has a nearly limitless array of innovative applications for everything from robotics and lighting to games and gardening! It's a fun way to automate everything, enabling you to control simple devices or manage complex displays.

Coding:

The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board. The language is similar to C/C++ as shown below. You simple plug the Arduino into the computer using a USB cable, and the software will be able to recognize it and upload the code at your request.

Here is example code to make an LED blink on and off continuously every second. You will not need the breadboard, or any other components for this sketch. You can use the built-in LED located at pin 13. The code will work the same if you replace LED_BUILTIN with the number 13.

Alternatively, if you want to use an external (5mm) LED you can do so by attaching it to a different pin as shown above. Here we also use a 220Ω resister in order to limit the current. In the code above, you simply replace LED_BUILTIN with the pin number connected to the the positive leg of the LED, which in this case is also pin 13. GND is the ground rail and is connected to the negative side of the circuit.

Recommended purchases:

The Arduino board is open-source and so there are many different clones available and all of them work in exactly the same as the Arduino. In fact we usually refer to these clones as an 'Arduino' too, but they are much cheaper in price.

Here is the official Arduino board:

It costs £17.30 and is a little pricey. Most of the clones are so much cheaper and do exactly the same thing. I have personally used the Elegoo board:

This costs £6.99 which is less than half the price as the original Arduino. There are also other clones which may be cheaper and although I have not had any experience with them, they will (in principle) function exactly the same.

For a beginner interested in electronic projects, I would recommend the following Kit as it contains things like wires, sensors, resistors, LEDs, diodes and so much more. It also comes with its own tutorial that is very easy to follow. You'll be building electronic projects in no time.

Links:

Here are some links to Arduino projects with instructions, even if you have no experience as it is good to take a look at these links to see the potential of the technology and be inspired.

Instructables: Arduino Projects

Raspberry Pi

The Raspberry Pi is a dynamic microcontroller that is capable of just about anything a computer is. It has 4 USB ports, an Ethernet port and inbuilt wifi+bluetooth (with the Raspberry Pi 3). It can do most of the same functions as the Arduino and much more. All the components used with the Arduino are also compatible with the Raspberry Pi.

The Raspberry Pi on its own is an impressive piece of kit, and it can be used for so many things outside electronic projects. Examples include using it as a Kodi multimedia system to retro gaming console - these don't require any programming or electronic assembly (links given below).

The Arduino has a very limited memory of 32kb and although this is sufficient for most of the projects (since the code doesn't take up much space) - the Raspberry Pi has no such issues. It runs a Linux based operating system and the maximum storage is 32GB on the MicroSD card. This allows you to make much more advanced electronic projects, from multimedia systems to robotics.

Here is an example of a robot that can follow a black line using a camera sensor, it has a Raspberry Pi 3 running TensorFlow (an open-source Neural Network Library developed by Google DeepMind)

Our example will start off much simpler of course. We will attempt to replicate the same blink function that we had on the Arduino above but using a Raspberry Pi.

Coding:

It can be programmed using the Python language. There are many ways to interface with the Raspberry Pi, since it is a computer running Linux. The simplest way is to plug the Raspberry Pi into a monitor using HDMI or VGA, with a keyboard attached. Other ways include a direct connection from the Raspberry Pi to the computer using an ethernet cable, or connecting via VNC.

The best way is to install SSH on your Raspberry Pi, and make sure that it connects to your wifi on boot (you will need a wifi Dongle for the Raspberry Pi 2 or below). You can then use putty or any SSH client to connect to your Raspberry Pi and get a terminal. From this terminal you can create the Blink python script (shown below).

Since the Raspberry Pi doesn't have an inbuilt LED like the Arduino, this will only work when you attach it to the circuit as we did before. The positive leg of the LED is connected to the pin 17 and the negative to GND.

Here is a pin layout for the Raspberry Pi pins:

Recommended purchases:

The latest Raspberry Pi is the v3 Model B, although everything that is written above will also work on the older versions. I personally own a Raspberry Pi 2, and I haven't found the need to upgrade as of yet. However if you are buying for the first time, it makes sense to buy the latest model as the price is about the same (in fact the Raspberry Pi 3 is cheaper for some reason). It has more memory, inbuilt wifi+bluetooth and other features (see the link below).

Here is a great kit to get you started, if you already own a microSD card and a HDMI cable then you can get the Basic kit which includes a heat sink and a clear case. If you don't own those items or you are a complete noob, then you should buy the complete kit which includes a 16gb memory card preloaded with noobs (Linux operating system for the Raspberry Pi designed to be user friendly and easy to use).

If you want to get your hands dirty with electronic assembly and programming, and you don't own the Arduino then you can buy the following kit for sensors. If you do own the Arduino kit, then you don't need these as all the components used with the Arduino are also compatible with the Raspberry Pi.

Links:

Here are some links for ideas about possible Raspberry Pi projects. Again you should see it even if you have no experience as you'll be able to get an idea of how the technology works and perhaps be inspired.0

'Non-electronic' projects require little or no assembly. In most cases you simply have to install software to get it to work. I will include links for Kodi and Retro gaming as I have mentioned these above.


Here are some electronic projects that require assembly and programming, for beginners. These projects can also be made on the Arduino because of its simplicity.


Here are some more advanced projects, but follow from what we have discussed above.

End.

I hope this article has been helpful. Please let me know if you would like to me to include anything specific that I may have missed out or any other changes.



To view or add a comment, sign in

More articles by Dr. Usman Kayani

Insights from the community

Others also viewed

Explore topics