Tag Archives: diy

Using a SIM800L GSM module with the Raspberry Pi (no battery)

sim800l gsm module with raspberry pi

The SIM800L is a GSM/GPRS modem widely used in electronics due to its very low price and wide availability. It’s an affordable way to send SMS with a Raspberry Pi or an Arduino, to connect to 3G or to implement a GPS.

However, it is almost impossible to find satisfactory explanations on its use and in particular on its connection.

In this tutorial we will therefore see how to connect and power a SIM800L from a Raspberry Pi (note that this also works for an Arduino), without external power supply or battery!

Hardware

We will go into the details and explanations later in this tutorial, but be aware that to connect a SIM800L to a Raspberry some hardware is required. So, you will need:

  • SIM800L GSM Module
  • 100 µF capacitor or more
  • 1N4007 diode
  • Breadboard
  • Jumpers

Of course, you will also need a Raspberry with Raspbian installed and a SIM card with a subscription. Note, the SIM card must be in micro sim format. If yours is a smaller format (nano format), you will need an adapter.

How to use the SIM800L module with a Raspberry Pi?

The SIM800L is a modem. It is the responsible for registering with your operator’s network, etc. Overall it behaves like a phone that you could control directly from your Raspberry.

To be able to control the SIM800L, from the Raspberry, you will have to provide power to the first and physically and software connect the two using a TTL port, more often called a serial port or interface.

From there you can control the SIM800L by sending so-called Hayes commands to the serial port – we actually speak more often of AT commands – which are commands specific to the functions of a modem. For example, send an SMS, enter a PIN code, check the network status, and much more!

In theory, to use a SIM800L with the Raspberry Pi you must do like this:

  • VDD of the SIM800L to +5V on the Raspberry.
  • GND of the SIM800L to GND on the Raspberry.
  • TXD of the SIM800L to RXD of the Raspberry.
  • RXD of the SIM800L to TXD of the Raspberry.

Only here, all that is the theory, but you will see that in practice things are a little more complicated.

Why is so difficult to plug in a SIM800L?

If the theory seems simple, in reality, you will find quite a few tutorials on the internet explaining how to use the SIM800L with a Raspberry. Worse, you will essentially find incorrect tutorials which, at best, will make your installation completely unstable, why not, will damage your SIM800L.

But then, how come there are not more quality resources available for such a well-known module? Because the SIM800L is particularly difficult to power and sensitive.

1. SIM800L is designed for phones and batteries

Originally the SIM800L was designed for use in phones by manufacturers. Its use in consumer electronics is much more recent and was not considered at all by the manufacturer.

As a result of its use in telephones, the module is designed to be powered by lithium-ion batteries, which offer voltages of around 3.6 to 3.7 volts. This feature will pose a first problem for us, because in digital electronics we generally use 3.3 volts or 5 volts, but not 3.6 volts.

2. SIM800L is an energy-intensive module

The second problem, the SIM800L performs radio operations that require large, very punctual current peaks. Typically the operations involved are registering on the operator’s network, sending messages, etc. If during these phases the module does not obtain the necessary current, its behavior becomes completely unpredictable, ranging from the error message to the restart through the loss of network.

Unfortunately, the power supplies in general and the GPIO ports of the Raspberry Pi in particular have a hard time responding to this kind of consumption peaks.

In fact, the amount of energy consumed is so great and over such a short period of time that using power cables that are too long and too thin can be enough to crash the module! This is also typically the case if you connect several Dupont cables in series.

No worries, we will explain how to solve these two problems!

So, how to power a SIM800L directly from a Raspberry?

We have seen so far that two problems arise for us to power a SIM800L from a Raspberry: an incompatible voltage and peaks in power consumption.

To begin, we will tackle the tension problem.

1. Decrease the voltage supplied by the Raspberry Pi

If we read the datasheet (technical sheet) of the SIM800L, we can see that the manufacturer indicates a supply voltage between 3.4 and 4.4 volts, with an optimal voltage of 4 volts.

The Raspberry Pi have two outputs that can supply two voltages, 3.3 and 5 volts. So we should increase our tension a bit or decrease it.

Let’s eliminate the first possibility which is too complicated to implement and look at the second. We are therefore looking for a reliable, simple and very inexpensive way to reduce a voltage by at least 0.6 volts, without reducing the intensity of the current (amperes). Luckily, it turns out that there is an electronic component that does exactly that, and that in addition this component is so widespread that absolutely all electronics technicians know it: the diode.

Diodes are primarily known for passing current in one direction only. But one of their characteristics is also to cause a voltage drop, which is estimated for silicon diodes at 0.7 volts.

So we just need to insert a silicon diode, we will take a 1N4007, between the 5 volt GPIO of our Pi and the VDD (power supply) PIN of our SIM800L. And here we have a voltage of 4.3 volts, MAGICAL RIGHT!!

2. Provide a power source that can meet consumption peaks

Now that we have solved our voltage problem, there remains our consumption peak problem. This time we would need a component allowing us to “store current” and provide it very quickly when the SIM800L needs it. Again, luckily, it exists and it’s called a capacitor!

Capacitors are used in many cases, but one of the most well-known uses is power supply stabilization. They charge when there is too much current and discharge when there is not enough. We will therefore insert an electrolytic capacitor (we will take at least a 100 µF 5 V, if we have more µF or volts no problem) in parallel with the VDD and GND pins of our SIM800L.

Schematics and wiring

Now that we’ve solved our problems, let’s see what our complete assembly looks like before testing everything by sending an SMS.

To hold all our components in place and connect them together we will use a breadboard and some jumpers.

Here is the final connection diagram, the red wire goes to the VDD, the black to the GND.

A few notes on assembly:

  • unplug the power supply of your Raspberry Pi while wiring. Only plug it in after checking everything and being sure that your circuit is good to go.
  • Connect the capacitor as close as possible to the VDD and GND pins of the SIM800L, ideally as shown in the diagram.
  • Capacitors are a polarized component, you must connect theme in a precise direction, anode on the VDD, cathode on the GND. The cathode is marked by a white band on the side.
  • Just like the capacitor, the diode is a polarized component. Again the cathode is marked by a white band.

Once the assembly is complete, you will be able to insert the SIM card into the slot provided on the SIM800L.

You must tuck the card on the contact side against the printed circuit, the corner cut at an angle towards the opening (it protrudes a little). If you insert the card upside down you will get a SIM not inserted type error when using the module.

Once the assembly is finished, turn on your Raspberry Pi, we will be able to test by sending an SMS!

Your first SMS from the Raspberry with a SIM800L

To finish this tutorial, we will send a first SMS to check that everything is working. We will not go further on the use of the SIM800L, but be aware that it offers many other features. For more advanced use, refer to the AT commands guide for the SIM800.

To begin, you will have to follow our tutorial to activate the serial port of the Raspberry Pi. Once you have finished activating the serial port we can connect to the SIM800L via the serial port.

To do this, open a connection to /dev/serial0 with minicom using the command line below:

sudo minicom -b 115000 -o -D /dev/serial0

Type the AT command (often the first line is not displayed when you type, this is normal) then make a line break to validate. You should get an OK response message.

Now we are going to check that the SIM card is unlocked (the PIN code is entered). To do this type the command AT+CPIN?. You should have an answer:

+CPIN: READY
OK

If you get an answer like the one below, you need to enter your card’s PIN code.

+CPIN: SIM PIN
OK

To do this, use the command AT+CPIN=0000 replacing 0000 with your own PIN code. You should then get a response of the form:

AT+CPIN=0000
OK
+CPIN: READY
SMS Ready
Call Ready

That’s it, you are connected to your operator’s network. All we have to do is send an SMS. To do this, use the commands AT+CMGF=1 to activate the text mode (it allows us to write the SMS in a format understandable for a human), then AT+CMGS="+213XXXXXXXXX" replacing +213XXXXXXXXX by the number to which you want to send the SMS.

A character > will appear, type your SMS then once you finish, press Ctrl+Z.

In the end you should have something like this:

AT+CMGF=1
OK
AT+CMGS="+213XXXXXXXXX"
> My Fist SMS with SIM800L using Raspberry Pi
+CMGS: 29

OK

There you go, you have sent your first SMS with a Raspberry Pi and a SIM800L! if you need to see more tutorials, check this link.

DIY relay board

DIY relay board

In this tutorial, you’ll learn how to make a power automotive DIY relay board. This board allows the control of DC motors or other power devices for robotic, industrial, automotive or on-board electronics applications.

Printed circuit with the 12 volt relay on its plug-in support

Presentation

When designing the board, it was intended for the production of an industrial test bench in the automotive world.
The forty power controls needed were made with relays mounted on brackets. Control is performed by the logic outputs of a measurement PC with Labview® type software. The relays actuate DC motors used in cars and also perform the necessary galvanic isolation function between computer equipment and power devices.

Other possible applications

  • Current inverter: using a N.O.-N.C. contact relay. (5 pins).
  • Control of: fog lights, additional headlights, 12-volt spotlight, siren.
  • Control for robot motors: robot mower, R2D2 robot, exploration robot.

Diagram and electrical design

Circuit diagram of the board

The relay

Detailed view of the relay terminals

According to the final application, you can choose the quality of the relay. The breaking capacity of the contacts (in amperes), the rise or fall times of the contacts (in milliseconds), the number of operations and the operating temperature (°C) are parameters that directly influence the service life of the relay (coil, mechanics and contacts). The relay terminals are of the male “6.35 faston terminal” type.
The relay used is form C and identified by five terminals. The coil has numbers 85 (+) and 86 and contacts 30 (common), 87 (NO) and 87a (NC). See the pinout and terminal identification in the following illustration.

Identification and numbering of relay terminals

The orthographic reform of 1990 proposed to return to the spelling relay (on the model of delay), but this one did not impose itself and relay remains despite everything the most common.

The relay support

The relay soldering support.

You can use this “6.35 faston” relay support to avoid soldering your relay directly to the board. Using this support, you can plug and unplug your relay anytime easily.

Protective devices

Across the coil terminals, you must wire a free-wheeling diode (therefore pay attention to the polarization of the wiring). It acts as an “energy absorber” when de-energizing the coil, which avoids propagating an overvoltage on the component that drives the relay (transistor or dry contact) and also limits the emission of transients on the cable which connects the logic output of the measurement PC to the relay card. As a precaution, we recommend protecting the output transistors of the logic board of the PC. You must find out about the equipment from the manufacturer or the instructions provided.
You can use other components to protect the relay contact controlling the inductive load. For example, if you choose to use a diode, it must be able to carry the same nominal current of the motor (or of the load in general). A varistor or an RC circuit (100 ohms + 0.1 mF for example) may be suitable in some cases.
The motor must also be protected from overcurrent with a fuse to be inserted in the power circuit (which will also protect the relay contact).

BOM

Here you can find the list of the electronic components:

  • 1N4005 diode (D).
  • MR751 diode (D2).
  • Automotive relay 12V (inverter) – form C (RL1).
  • 5-pin relay support – form C PCB version (RL1) plus the 5 terminals.
  • 4-point terminal block, 5 mm pitch (J1).
  • 5-point terminal block, 5 mm pitch (J2) with copper cages.
  • printed circuit REL12 70 to 105 μm, single-sided FR4, solder-side varnish, 40×60 mm.

The circuit board “PCB”

The recommended thickness of copper traces is 70 to 105 µm with a minimum trace width of 2.5 mm for a current of 20 amps. Additional tinning of the copper tracks may be necessary in the case of higher currents. Solder side varnish is preferable. The circuit board has four fixing holes, so you can fix it in a horizontal or vertical position.

The printed circuit artwork.

The wiring

It will be necessary to respect the direction of implantation of the diodes and the cage connectors. Solder the components in the following order:

  • Diode D1.
  • Diode D2.
  • Terminals J1 and J2.
  • The relay support.
Top view of the fully wired board.

check our latest tutorials from here.