Lecture 2: Electronics for the Internet of Things

Slides are available from the link

This course will treat throughout its duration topics such as: electric signals- definition, explenations and examples, a brief lesson of basic electronics, presentation of GPIO pins- examples of usage, PWM pins. In addition, analog to digital converters will be discussed, microcontrollers and computers will be put in contrast.

Electric signals

A signal is a function that conveys information about a phenomena.

Imagine a sound wave. An analog representation of the signal would correspond to the original one, but a digital one would create steps. Digital representations of a signal have a different accuracy rates as follows.

The representation of a signal can be referred to as a stream of measurements. The precision of the measurements, thus, of the interpretation of the signal depends on two important factors:

  • The number of bits assigned to a measurement; it will either improve or damage the quality of the received signal. The signal as a whole is recomposed after gathering multiple samples. For each sample, or measurement, the hardware can allocate one or more bits. A one-bit sample will split the signal's values in two: above half and under half. The former will transform to 1 and the latter to 0. This signal's representation will be far from accurate. Now, if there is a larger scale of bits, the hardware can adapt the signal closer to the original one.

Supposing you have n bits to represent your signal, when taking a sample, the hardware decides which of the values from 0 to 2^n-1 to assign to the measurement.

  • The sampling rate is just as important as the number of bits. The samples will be taken from time to time. In the interval between measurements the signal is lost. This way, the signal can be more or less approximated. The ideal case is when the sampling is made frequently, so little signal is missed.

The time intervals will be shown on the graphics, following the horizontal axes.

Nyquist theorem says that in order to reproduce an accurate signal, you need to sample at least twice faster than the highest frequency of the signal. This means that if the bandwidth is lower than the highest frequency, the signal will be altered.

Introduction to Electronics

Basic electronics knowledge is required to be able to complete the simplest IoT projects. All the necessary devices, pieces and boards follow the laws that rule this field. These laws are presented and explained in the next few paragraphs. Not knowing and respecting the electronics laws can get you into real trouble with your board or any other sensor or device you are using.

Ohm’s Law

The Ohm’s law states that in a circuit the current (I) is directly proportional to the applied voltage (U) and inversely proportional to the resistance (R) of the circuit. I = U * R (1)

Kirchhoff’s Circuit Laws

Before you state the two laws, you need to understand the following notions:

  • Junction/Node - the place where at least three conducting branches meet
  • Loop - a closed path, including at least two nodes

Kirchhoff’s First Law

Kirchhoff’s First Law states that in a node, the sum of the currents is 0. ∑ik = 0 (2) Please keep in mind that currents have directions. Currents incoming have negative values, while currents outgoing have positive values.

Kirchhoff’s Second Law

Kirchhoff’s Second Law states that the sum of the voltage in a circuit loop is equal to the power source voltage. ∑RkIk (3)

Example:

You have a 3V source and three resistors of different resistance. The sum of voltage drops on each of them is equal to the source voltage.

R1 + R2 + R3 = VCC1 ⇒ 0.25v + 1.25v + 1.5v = 3v (4)

The Voltage Divider

A voltage divider is a circuit which turns a large voltage into a smaller one, using two resistors and an input voltage. This way we can obtain an output voltage.

One of the resistors should always differ from zero, otherwise we will have a short circuit.

GPIO - General Purpose Input/Output

There are two types of pins: input and output.

Input pins act like a voltage meter. They measure the voltage that comes in. Digital pins will send 0 for a voltage under half of the maximum expected and 1 for values above the half. Analog pins, on the other hand, will send values from 0 to 1024, depending on what the respective sensor is detecting.

Output pins are split into digital ones and PWMs. Digital pins will give 5V or 3.3V if given the value 1. The voltage depends on the type of the board. On Intel Edison breakout board you can configure it so that the pins can operate either 5V or 3.3V. For the Raspbery pi, the GPIO pins output 3.3 V and the Arduino board 5V, but some models also give 3.3V.

In a nutshell, output pins have the functionality of a battery, like you can see in the previous figure. The anode of the LED is connected through the resistor to the output pin. The cathode will be connected to the ground.

Another type of outputs are represented by the PWMs. You might not know what a PWM (Pulse Width Modulation) pin does. It is basically a digital way of control, which means it oscillates between the values 1 and 0.

First of all, you should know that the boards have a clock that counts quanta of time. You can decide to split this quanta in two different parts: one during which you will send the value 0 and the other in which you send the value 1. Essentially, what the PWM brings in addition is a counter that memorizes the percent of the quanta during which the output value was 1.

The period while the signal has the value 1 will be the pulse width.

In a nutshell, you simulate an analog pin by changing the pulse width. The value of the PWM increases when you send more values that equal 1. However, this is not at all equivalent to having an output of 2.5 volts, for instance, instead of 5. This is why the PWM cannot be used with peripherals that require less than 5 V.

However, the PWM works perfectly as an example for the LED. What's important to know is that you basically have an LED that changes its light intensity from bright to none so fast that the human eye can't perceive the change, so you and I see it as a continuous light but dimmer or brighter. This is due to the ability of human eye to integrate these values.

LED

This chapter explains how to correctly connect an LED to a board. First of all, you need to know what a diode is. A diode is an electronic component that has a positive and a negative side and it basically allows the current to flow only in one direction, from positive to negative. The LED is also a diode. When current is flowing through the LED, it lights up. So in order to light up a LED you need to put the high voltage at the anode and the low voltage at the cathode.

Schematics

Taking into account the theory stated previously, you would build a circuit like the one in next figure to light up an LED. You must take into account that the power source depicted will be replaced in the projects you are going to build with the Edison. There is only one tiny problem with the schematics in previous figure: it is a short circuit. That means there is no resistance to limit the current because the diode does not have any resistance at all. It just allows the current to flow. That can cause big problems (you can damage your Raspberry Pi, for example). To fix this, you need a resistor to limit the current flow.

Button

This chapter explains how to correctly connect a button to a board. A button, also called a switch, is an electric component that can break an electrical circuit by interrupting the current. When used in schematics, there are multiple possible symbols to depict it.

Also, here is an example of circuit that uses a switch.

When the button is pressed, it acts like a wire and it will let the current flow through the circuit. If the button is not pressed, the circuit is interrupted. When a button is connected to a board, you can tell if the button was pressed by looking at the pin’s value.

Let’s see how you can connect a button to the Edison board. The first possibility would be the one in the next figure, but it is wrong.

Why is it wrong? If the button is pressed, everything works fine. The value of pin would be HIGH and you can say “Yes, the button is definitely pressed”. But what happens when the button is off? It is important to know that a logic level can be: LOW (or 0), HIGH (or 1) and also UNKNOWN (or high impedance). When the button is not pressed you cannot say for sure what logical level the pin has: it could be 0 as well as 1 because the wire is not connected neither to Ground nor to a power supply. Let’s give it another try.

This is also incorrect. When the switch is off the button’s pin value is HIGH. The big problem appears when the button is pressed. It will create a short circuit: the ground is directly connected to VCC which is very bad because you do not have any resistor and the electric current is not limited. The correct way to connect a button to a board is this.

This time you will not have a short circuit because if the button is pressed there is the R resistor. The R resistor is called a pull up resistor and the whole system is called a voltage divider. If the button is pressed our pin’s value will be LOW.

You can also connect the resistor to the Ground. Now you have a pull-down resistor and the pin’s value will be HIGH when the button is pressed and low otherwise.

Whenever you connect anything to your board you must assure that it is not powered up. Otherwise you might accidentally create a short-circuit and burn the board.

Only after you assured that everything is correctly connected, you may safely power it up.

PWM - Pulse-Width Modulation

Pulse with modulation is generating signals like this:

Pins capable of generating PWM are generating quadratic periodical signals. PWM comes from the duty cycle of the pulse : how much of the period of the signal is one and how much is 0. \\PWM pins are controled with numbers between 0 to 255. If we ask for a signal of 0 it will generate a line with 0, which is similar to a GPIO writing Low. If we go to 255 the signal must be 1 the whole period. In between, it depends. For example if you have 64 , 25% of the time the signal will be 1 and so on.

Pay attention that athough the PWM can generate signals that have a RMS value lower than 5V, its actual peak value is still 5 V. This may lead to burning the devices and pieces involved in the circuit.

Analog to Digital Converters

An ADC turns the analog signal to a digital one. It is defined by the same two parameters: the sampling speed and the number of bits per sample. In addition to this, its quality stands in the speed by which it reads the analog pins.

First of all, the mechanism work like this: The signal can be received through one or more of the analog pins: A0, A1 and so on. The ADC on a board is multiplexed, which means there is a controller which connects the ADC to pin A0, reads the value on it and reports it back. Next, the same will happen to pin A1, then A2 so on and so forth. As a conclusion, the multiplexing speed is just as important as the sampling one.

Boards which can't read analog pins, such as the Raspberry Pi, don't have ADCs.

Micro controllers and Computers

There is a big difference between micro controllers and computers (embedded boards).

The first ones are low powered, have low memory and processing power but they are really good at controlling hardware because of the various type of pins they have ( GPIO, PWM and ADC ). Their big advantage is that they are real time as the only program running on them is the program you wrote.

On the other hand embedded boards run some OS and have a bigger processing power and large memory but they cannot really control hardware.

Usually the solution is to use a computer board to get data from a micro controller, that in turn control some hardware.

iotcluj/courses/02.txt · Last modified: 2016/07/12 14:43 by ioana_maria.culic
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0