Introduction

There is no doubt that this is the age of wireless.  From mice to doorbells, cameras to computers everything seems to connect without the hassle of hooking up cables or tripping over wires.

Today we will examine a low-cost method of sending wireless data between two Arduinos without using wifi or bluetooth. Learn how inexpensive 433MHz modules may be all you need to cut the cord on your next Arduino design.

 

Wireless World

There are many methods a designer can employ to add wireless capability to their creations. Each of them has its own advantage and disadvantage and as adding wireless communications will add to the cost of your product you need to think carefully before implementing anything.

Bluetooth is often the first choice that comes to mind. It is popular and will allow your Arduino project to be controlled with the aid of your phone, tablet or computer. You can create a custom app to give your project a real professional look, equivalent to anything you can buy commercially.

But Bluetooth can also be an overkill if you just want to send a bit of data from a sensor or keypad. It also requires you to build an app which may be more than you want to take upon yourself.  You’ll also need to pair it with your device, although that isn’t particularly difficult.

WiFi is another good choice, using WiFi will allow your project to interact with all of the devices on your existing network. For an IoT (Internet of Things) device it is the perfect choice.

But WiFi can be an overkill if you only have basic requirements, it can cost a bit of money and also needs to be authenticated onto your network properly or it can become a security risk.  And of course it will only work if you actually have an existing WiFi network.

The nRF24L01 modules are popular choices, they don’t cost a lot and can provide reliable 2-way communications between two Arduinos.  In many ways they are the ideal solution to many wireless design problems.  And they can communicate over a considerable distance with the right antennas.

But the nRF24L01 can be a bit tricky to implement and if you don’t need 2-way communications they are a bit excessive. They can also cause interference with routers and cordless phones if you aren’t careful. Still they are an excellent choice and we will indeed visit this option – but that’s for another article.

The solution we will discuss here involves the use of super inexpensive (i.e cheap) wireless modules that can provide one-way communications capabilities over a reasonable distance. They are easy to use and won’t break the budget.

433 MHz Modules

These modules are available on eBay, Amazon and a myriad of other places. They can often be obtained for less than two dollars for the pair, making them one of the most inexpensive data communication options that you can get.

One of the reason for their low cost is that these modules are used in many electronic toys, games and also in key fobs for automobiles. They are manufactured by the millions and this keeps their cost to an absolute minimum.

The modules are extremely easy to use, each module has only three connections (the receiver has 4 pins but two are internally tied together) and two of those connections are for power.  The remaining connection is for data in on the transmitter and data out on the receiver.

The modules are also very tiny, allowing you to incorporate a wireless interface into virtually any project.

The modules both have a connection for an external antenna. We’ll discuss antennas in a moment but before we do it’s vital that we talk about the legalities of using these (and other ) radio modules in our projects.

Staying Legal

Because we are experimenting with devices that transmit radio waves we need to be aware of the regulations regarding unlicensed radio transmitters. These regulations will differ depending upon what area of the world you live in.

It is imperative that you are aware of the laws concerning using these modules in your country!  Failing to abide by these rules can land you in a lot of trouble.

Every country has a regulatory body responsible for radio communications.

The Federal Communications Commision or FCC is the governing body in the United States and its possessions.

The CRTC or Canadian Radio and Television Commision sets the laws in Canada.

In the UK the Office of Communications or OFCOM takes care of the allocation of radio bandwidth.

You can check out this Wikipedia list to find the regulatory body in your country.

In most countries these modules are legal for use providing the following conditions are met:

  • They are operated at low power.
  • They don’t transmit continuously (digital data is intermittent so it satisfies this requirement).
  • They do not transmit voice (digitized voice or sound is OK).

Again you should check with your local authority if there is any doubt BEFORE embarking upon these experiments.

ASK – Amplitude Shift Keying

There are many methods of sending digital data over radio:

  • Frequency Shift Keying or FSK. In this method the digital signal modifies the frequency of the carrier wave. This is similar to Frequency Modulation or FM radio.
  • Phase Shift Keying or PSK.  This works by modifying the phase of the carrier in response to the input signal. Many modems work this way.
  • Amplitude Shift Keying or ASK. This is a simpler method, similar to Amplitude Modulation or AM radio.

Because these modules are very simple we will use ASK.

In Amplitude Shift Modulation the amplitude (i.e. the level) of the carrier wave is changed in response to the incoming data signal.  This is sometimes called Binary Amplitude Shift Modulation as there really are only two levels to be concerned with:

  • Digital 1 – This drives the carrier at full strength.
  • Digital 0 – This cuts the carrier off completely.

This is shown in the following illustration:

Amplitude Shift keying has the advantage of being very simple so the resulting circuitry is simple and inexpensive.

It does have its disadvantages however. ASK is susceptible to interference from other radio devices and background noise.  But as long as you keep your data transmission to a relatively slow speed it can work reliably in most environments.

It also helps to have a good antenna.

Antenna Design

The antenna that you use for both the transmitter and receiver can really affect the range you’ll be able to obtain with these RF modules. In fact without an antenna you’d be lucky to communicate over a distance of more than a meter.

Some users have reported being able to communicate over a distance of 50 meters with the proper antenna design. Of course that is outdoors in an open space. Your range indoors, especially through walls, will be significantly diminished.

The antenna need not be anything fancy. A simple piece of 22 or 24 gauge solid wire can make an excellent antenna for both the transmitter and receiver.

The length of the wire does matter however, as it does for all radio devices. Rather than using a random length of wire you should use one that is an even fraction (i.e .one half or one quarter) of the wavelength of the signal you’re sending.

We are using a frequency of 433MHz in our modules. One wavelength at 433MHz is 69.24 cm. As this is a pretty long antenna (about 27.25 inches) it is more practical to use a half or quarter wave antenna.

Most experimenters use a quarter wave antenna which works out to about 17.3 cm or 6.8 inches.

If you are experimenting with other radio transmitters that use different frequencies you will need to calculate the required antenna length using their wavelength. This online wavelength calculator will assist you in determining how long to make your antenna.

Even a 17.3 cm antenna can seem unwieldy in your tiny Arduino project. It is common to coil the wire on one or both antennas to reduce the size, this sometimes can have the added bonus of increasing efficiency. You can experiment with antenna coils by wrapping the wire around a pencil or pen.

Demo 1 – Sending Data

Now that we have discussed our modules it is time to put them to use!

In our first experiment we will just send a canned message from the transmitter to the receiver. While this isn’t extremely useful it does serve to illustrate how to use the modules and can serve as the basis for more practical experiments and projects. It’s also a great way to see if our antenna design is sound.

As we will be sending data between two Arduinos we will (of course) need two Arduinos. I have shown these experiments using an Arduino Uno but any Arduino will work.

Hooking up the Transmitter

The hookup for the transmitter is very simple, as shown in the following illustration:

The module only has three connection, they are as follows:

  • VCC – This can be any positive DC voltage from 3 to 12 volts. In this experiment we will get 5 volts from our Arduino.
  • GND – The ground connection, connected to one of the Arduino ground terminals.
  • DATA IN – This is connected to pin 12 of the Arduino. You should try and use pin 12 as by default the library we’ll be using in our sketch uses this pin for data output.

You will also want to solder a 17.3 cm piece of solid hookup wire to the antenna terminal on the module.

Once you have the transmitter wired you can move on to the receiver.

Hooking up the Receiver

The receiver is just as easy to hookup as the transmitter was.

Once again there are only three connections to make. Although the receiver module has four pins the two center pins are tied together, so you can use either one for data out.

The connections are as follows:

  • VCC – Unlike the transmitter this needs to be 5 volts. We will use the 5 volt output from the Arduino.
  • GND – Again a ground that is connected to any Arduino ground pin.
  • DATA OUT – This needs to be connected to digital pin 11 on the Arduino.

The antenna connection on the receiver is often unmarked. It is the pad in the lower left of the module, right next to the small coil.

Now that both the transmitter and receiver are wired up we will need to write some code and send it to the respective Arduino boards.  Since you probably have only one computer we will start with the transmitter. Once the code has been loaded there we’ll move on to the receiver. The transmitter can then be powered using a power supply or battery.

But before we start coding there is a library we will need to install into our Arduino IDE that will make writing the code a lot simpler.

RadioHead Library

Radiohead are an English rock band that formed in 1985. This is required knowledge for every Arduino experimenter as they titled one of their most popular albums OK Computer and you have to love that.  This has nothing whatsoever to do with RF modules but I thought I would mention it!

The RadioHead that we are going to talk about is a code library that can be used to drive all sorts of radio communications devices, including our 433MHz modules. It was written by Mike McCauley for Airspayce and is in the public domain.

This is a very complex library, we will only be using the Amplitude Shift Keying code from it.

You will need to download the library from the Airspayce website.

Look for a link to the library at the top of the page and download the ZIP file to a location on your computer that you will remember – your downloads folder is probably as good a place as any.

Now open your Arduino IDE. Go to the Sketch pulldown menu and open the Include Library submenu. Choose Add ZIP library

A dialog box will open, allowing you to navigate to the location you put your RadioHead ZIP file.  Find the file and select it.

The library will be installed into your Arduino IDE. You may need to restart the IDE after doing this.

Now that RadioHead is part of your Arduino IDE you are ready to code.

Demo 1 Transmitter Code

Here is the sketch we will be using for our transmitter:

 

 

It’s a pretty short sketch but it’s all you need to get a signal transmitted.

We begin by loading the RadioHead ASK library. We also include the Arduino SPI Library as the ASK library is dependant upon it. If you think about it that makes some sense as we are working with serial data.

Next we create an ASK object to work with, I called mine “rf_driver”.

In the setup we need to initialize the ASK object.

Now the loop. We begin by encoding a message. This needs to be a char data type. This is stored in a variable named “msg”.

The message itself is a text string. You can use any string but keep it fairly short and be sure to count the number of characters in it – you will need that count for the receiver code. In my case my message has 24 characters.

We then send our message and wait for it to be sent. After that we apply a delay to give our receiver time to digest everything – I used one second but in retrospect I wish I had made it a bit longer due to my message length. You can experiment to get the optimum value.

After that the loop repeats and our message is sent over and over.

Now disconnect your computer from the Arduino, find another power supply for the Arduino and power it back up. It will transmit continuously while we code our receiver.

Demo 1 Receiver Code

Hook up the computer to the receiver Arduino and load the following code (remember, all of the code is in a handy ZIP file at the end of the article).

 

The receive code is also very simple. It starts out exactly the same as the transmit code, loading both the RadioHead and SPI libraries and creating an ASK object.

In the setup routine we initialize the ASK object and we also set up the serial monitor as this is how we will view our received message.

In the loop we set a buffer to match the size of the transmitted message. As my message (“Welcome to the Workshop”) is 24 characters I used a value of 24. You will need to adjust this to match your message length. Be sure to include any spaces and punctuation as they all count as characters.

We then check to see if we received a valid packet. If we do we print it to the serial monitor. Then we go back to the start of the loop and do it all over again.

After loading the code open your serial monitor. If all is working you should see your message.

Although this demo is not particularly useful it can be used to adjust your antenna length and the orientation of the transmitting and receiving antennas.  If you use a battery for the transmitter you can try moving it to different locations to see what sort of range you can obtain.

Demo 2 – Sending Sensor Data

Our first demonstration showed how we can send and receive data using our small modules. Now let’s do something a bit more practical.

In our second demonstration we will use a temperature and humidity sensor with our transmitter. We’ll take readings from the sensor and transmit these to our receiver where we will display them on the serial monitor.

There are a couple of great things about this demonstration:

  • It is a practical application. You can use it to measure the temperature in a remote location like your basement or attic. With the right enclosure you could even use it outdoors.
  • It shows you one method of sending more than one piece of information over the radio link. In this demo we send both temperature and humidity values.

In order to use our temperature and humidity sensor we will need to install some more libraries in our Arduino IDE.

Installing Adafruit Libraries

Our temperature sensor requires a couple of libraries from Adafruit.

If you followed the experiments in the Using the HC-SR04 Ultrasonic Distance Sensor with Arduino article you already have installed these libraries as we used the same temperature and humidity sensor in those experiments.

If you haven’t already installed these libraries you can install them using the Arduino Library Manager.  Just open the Library Manager and search for each library. You need both as the AM2315 library is dependent upon the Unified Sensor library.

Once you have the libraries installed you can wire up your transmitter.

Transmitter Wiring

Wiring the transmitter is very easy as most of it is exactly the same as the first demonstration. The only addition is a DHT22 temperature and humidity sensor. Here is the wiring diagram:

The DHT22 has four pins, one which is unused. It is hooked up as follows:

  • VCC – This is a 5 volt DC input which is taken from the same 5 volt Arduino output as the transmitter power supply.
  • GND – A ground, connected to any Arduino ground pin.
  • DATA OUT – This is the output pin which can be run to any unused Arduino digital I/O pin. I used pin 7.

Once you have wired in your DHT22 you are done with wiring. There are no changes to the receiver wiring, it remains exactly the same as it was in the first demonstration.

Demo 2 Transmitter Code

As we will be sending two data values (temperature and humidity) we need to figure out a way of placing all of that data into one character string. There are many ways of accomplishing this task.

I chose to put both data values in a comma delimited string. This is a common way of sending a line of data. Although this example only uses two data values you could actually add more using the same technique. Keep in mind that you’ll eventually run out of space in the data packets we are sending.

Here is the sketch I came up with to accomplish this:

 

The sketch begins in the same way as the first demonstration, including both the RadioHead library and the Arduino SPI library.  We also include the DHT library for the DHT22 sensor.

After that we define some constants for the DHT sensor, specifically the pin we have it connected to and the sensor type (the Adafruit library supports several sensors, including the less accurate DHT11).

Next we define some variables. A couple of floats are defined for the temperature and humidity data. As well we define some strings, we’ll need to convert the temperature and humidity floats to strings and assemble them into a comma delimited string so we can send it.

As with the other sketches an ASK object is defined. We also initialize the DHT22 sensor.

In the setup routine we initialize the ASK object and start the DHT sensor. We then move on to the loop.

We start the loop with a delay, this gives the DHT22 sensor some time to stabilize.  After it has stabilized we read the temperature and humidity values from the sensor and assign them to their respective floats.

We then convert both of those floats to strings, which we then use to construct our comma delimited string.

The string is converted into a char named “msg”, the same as we did in the earlier transmitter sketch.  The rest of the sketch is identical to the first transmitter sketch, we send the char and wait until it has been transmitted. Then we start at the top of the loop again.

Once again we will load the sketch into our transmitter Arduino and then disconnect it from the computer. We will power it with a battery or power supply and connect our computer to the receiver Arduino to work on that.

Demo 2 Receiver Code

If you still have the receiver Arduino loaded with the code from the first demonstration you can run it and observe the output on the serial monitor. You should see the temperature and humidity data displayed in a comma delimited string, along with a bit of “junk” after it. That “junk” is actually a null character.

Our receiver code for this demonstration is actually very similar to that of the first demo, all we need to do is change the size of the expected data packet and extract the values from the comma delimited string.

Here is the sketch we  will use to accomplish this:

 

The sketch starts in what is now a pretty familiar fashion, loading the RadioHead ASK and Arduino SPI libraries.  We then define the same strings we used in the transmitter sketch, one each for temperature and humidity and one for the comma delimited string that we will be receiving.

Again we create an ASK object named “rf_driver”.

In the setup we do exactly what we did in the original receiver sketch, initialize the ASK object and setup the serial monitor parameters.

The loop also starts off the same as the last receiver sketch, the only difference being that our packet size is 11 characters.

If a valid packet is received we convert the received data into a string. This will be our comma delimited text.

The Arduino has no command to extract elements from a delimited string like other higher level programming languages do. So we run a small routine to do that for us. It measures the string length and the position of the comma then uses that information to divide the string into two substrings. We assign each of these substrings to the string variables we created to hold humidity and temperature.

Finally we format the output text and display it on the serial monitor. Then we end the loop and start it all over again.

Load the sketch into the Arduino and then start your serial monitor. If all is working you will see the temperature and humidity displayed on the serial monitor.

Experiment by moving the transmitter to various locations and see how the temperature and humidity differs around your home.

Conclusion

As you can see adding a wireless link to your Arduino projects does not need to be complex or expensive. If all you need to do is send a small bit of data one way these small RF modules are ideal for the job, and the price is easy on the wallet.

You can use the technique for transmitting multiple chunks of data for other applications and sensors. Keep in mind that you could also use this technique to transmit the value of the analog inputs as well, so if you want to build a wireless joystick it shouldn’t be hard to modify the sketch to do exactly that.

So what will you build with your wireless link? Have you discovered any methods of (legally) increasing the range, perhaps a “super antenna”? Let us know in the comments.

Thanks for tuning in!

 

Resources

Code for this Article – All of the sketches used in this article in one ZIP file.

US Frequency Allocation Chart – The allocation of the radio spectrum in the United States

Canadian Frequency Allocation List – A list of the radio frequencies allocated by the CRTC

UK Frequency Allocation Chart – Allocation of radio frequencies in the United Kingdom.

RadioHead Library – The RadioHead Arduino Library for RF modules.

Adafruit Unified Sensor Library – The latest versions of the Adafruit Unified Sensor Library.

Adafruit AM2315 Library – The Adafruit library for temperature and humidity sensors.

 

Summary
Using Inexpensive 433MHz Transmit and Receive Modules with Arduino
Article Name
Using Inexpensive 433MHz Transmit and Receive Modules with Arduino
Description
Learn to use 433 MHz radio modules with the Arduino for inexpensive one-way data communication.
Author
Publisher Name
DroneBot Workshop
Publisher Logo
Using Inexpensive 433MHz Transmit and Receive Modules with Arduino
Tagged on:     

3
Leave a Reply

newest oldest most voted
Aksh

Can we check the amount of power the receiver is receiving using arduino? If yes, then how?

Paco

Hi, thanks for your good tutorial. It’s great! I would like to send three variables, temperature, humedity and light sensor. Could you help me about this sketch? Thank you very much

Tony B

Thanks for the thorough, informative video and web page. They’re consistently high quality, useful, and interesting.