Getting Started with Arduino – Chapter Eleven

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino universe. The first chapter is here, the index is here.

Welcome back

In this instalment we will start to investigate radio data transmission; then introduce rotary encoders.

As technology has marched along and generally improved on the past, things have been getting small and relatively cheaper. What was once jaw-droppingly amazing is now just meh. But as you are reading this, you know differently. We can now take control of this technology for our own devices. What has been in the past quite unapproachable is now relatively – the concept of wireless data transmission. But no just sending a signal, like a remote-control garage door opener – but sending actual,  useful data – numbers and characters and so on.

How is it so? With this pair of tiny devices:

txrxmodule

Quite small indeed – the pins are spaced 2.54mm apart, and the graph paper is 5mm square. The transmitter is on the right. This pair operates at 315 kHz, over up to a theoretical 150 metres. The data transmission speed is 2400 bps (bits per second). These units are serial passthrough, that is they can replace a link of wire between the serial TX (pin 1) from one Arduino, and the RX of another Arduino (pin 0). They don’t need aerials for very short distances, but the use of one will extend the range towards the maximum. And finally, the transmitter needs between 2 and 10 volts; the receiver 5. Here is the data sheet for these modules: 315MHz.pdf. Normally they are sold individually, for example the transmitter and receiver. You can also find faster (data speed) modules, however we will use these ones today.

In preparation to use these modules, another library needs to be installed – the VirtualWire library. Download the latest revision from the following location: http://www.open.com.au/mikem/arduino/.

There is also a guide to using the library in .pdf format as well. Please note the library author’s instructions with regards to licensing on the last page of the guide. For a refresher on how to install a library, please head back to chapter two. This library will save us a lot of time, it takes care of checking for errors, and only allows complete, correct data (i.e. what is received matches what is sent) to be used in the receiver’s sketch.

However, as wireless is not 100% reliable, you need to take into account that transmissions may not be received, or erroneous ones will be ignored by the receiver’s sketch. You can reduce the data speed to improve reliability and range. Furthermore, you cannot use PWM on D9 and D10 if you are using VirtualWire.

Therefore if you are using this for some important communications, have the transmitter repeatedly sent the message. Later on in this series we will investigate more powerful solutions. Anyhow, moving along …

First of all, we will demonstrate the use of these modules with a basic sketch. It sends some text from one Arduino to another. The receiving Arduino sends the data to the serial monitor box. Of course you could always use an LCD module instead. In my own inimitable style the sketches are very simple, yet allow you to use their contents in your own work. Here is the sketch for the transmitter – tx.pdf and the receiver – rx.pdf.

When working with two sketches at the same time, you can have two Arduinos connected to your PC simultaneously,  just remember to select the correct USB port for the correct Arduino. Do this with the tools > serial port menu option in the IDE. Otherwise you will become very frustrated if you upload the rx sketch to the tx Arduino.

Furthermore, you will need to remove the wire from digital 0 to the data pin on the receiving units before uploading the sketch. And finally, remember to set the serial monitor window at 9600 baud.

Here are my two boards in action:

example11p1small

Although having both boards connected to the one computer is only useful for demonstration purposes, in real life this is obviously useless. Remember that once you upload your sketch the Arduino doesn’t need a computer, only a power supply. You can feed yours between 7 and 12 volts DC through the socket. A nice switchmode power pack will do nicely, or if you are a cheapskate like me, a PP3 battery and clip soldered to a DC plug:

pp3small

You may find that when you use a battery powered Arduino that it basically does not work. Arduino genius Jon Oxer (co-author of Practical Arduino) has found a solution for this issue – place a 10k resistor between GND and digital 0 (RX), or between digital pins 0 and 1. The next thing to consider it improving the reception range. This can be done using two methods – the first by connecting an external antenna, either a length of wire, or perhaps a purpose-built aerial. The second method is to increase the supply voltage of the transmitter up to 12 volts.

Now it is your time to do some work:

Exercise 11.1

You now are able to send characters using the radio link from one Arduino to another. Now it is time to control things remotely. For the purpose of the exercise, we will just control three LEDs, turning them on and off. You already know how to control other things with digital output pins, so we just need to focus on getting the switching on and off. Hint – you can send characters via the wireless link, so create your own codes.

You will need:

  • Two standard Arduino setups (computer, cable, Uno or compatible)
  • two breadboards and some connecting wire
  • One transmitter and one receiver unit
  • three LEDs
  • 3 x 560 ohm 0.25 W resistors. They are to reduce the current to protect the LEDs

Here is the schematic of my interpretation:

exerc11p1sch

… the transmitter:

exer11p1txsmall

… the receiver:

exer11p1rxsmall

and the video:

So how did you go? Hopefully this exercise was easier than you had first expected. If not, here are the example sketches: exercise 11.1 tx and exercise 11.1 rx. A basic transmit/receive system like this would also be handy for testing the range that wireless modules can operate over, or testing a particular site to see if you could implement such wireless modules. It’s always better to test before agreeing to make something for someone.

That concludes our work with radio wireless links – for now.

LEDborder

Next on the agenda is the rotary encoder. Recall how we used a potentiometer in the previous chapters as a dial, to select menu options using the readdial() function. It was simple, cheap and it worked, but some may say it was a kludge. There must be a better way! And there is, with the rotary encoder. A rotary encoder looks like a potentiometer, but it is a knob that can be rotated in either direction infinitely. Furthermore, the knob is also a normally-open button. The encoder we will be using in this chapter is a 12-step encoder, in that you can feel it physically resist rotation slightly twelve times over the 360 degrees of rotation.

Here is our example:

encoder11

On one side there are three pins, and two on the opposing side. On the perpendicular sides are legs for strength, that is they are meant to be soldered into a PCB to lock it in nicely. The problem for us is that those legs interfere when trying to use the encoder in a breadboard, so I have bent them up and cut them off:

encoder2

The pins are easy to understand. The two pins on one side are the button contacts, just like any simple button. The other side with the three pins – the centre goes to ground, and the outside pins are the forwards and backwards output pins. The data sheet for our encoder is here. After fooling about with this all afternoon, the quickest way to get a feel for how it works is with a simple demonstration. So first we will test it out, then see how we can use it in our user-interfaces.

This example is very easy to assemble. You only need an encoder, and the usual Arduino setup. Here is the sketch, and the schematic:

example11p2schem

and in real life:

example11p2boardsmall

and finally a snapshot of the output. Don’t forget to set the speed in your serial monitor box to 115200 baud:

example11p2screen

So as you can see, this is a much better solution that then potentiometer that we used in the past. Plus having the button integrated in the encoder is very convenient, you can really create a user interface with only one control. In the next instalment of this series we will implement the encoder in an existing design. So on to Chapter Twelve.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

23 Responses to “Getting Started with Arduino – Chapter Eleven”

  1. Rich says:

    Hi John – my vote is for a long article format.

  2. Marcel says:

    Dear John,

    Thanks for your sterling effort. You are explaining things very well.

    In terms of article length. I don’t mind. It all depends on the subject. Evidently, rotary encoders aren’t as complex to handle as I might have imagined, so a short article has done the job nicely. Thanks.

    Keep up the great work.

    Marcel

    • John Boxall says:

      Hello Marcel
      Thank you very much for your feedback. You’re right, some things can be shorter than others… however I’m not finished with the encoder. Integrating them into menu systems is proving a little difficult, however I promise to have it done for the next installment. Have a great week!
      Cheers
      John

  3. David says:

    Love your work. My vote is “don’t stop!!”. Fortnightly gives me a chance to try stuff :)

    • John Boxall says:

      Hello David
      Thank you for your comment :) I’m not stopping anytime soon.. Yes, fortnightly is better for me too, sometimes I fall behind schedule when they’re weekly.
      Have fun
      john

  4. Carlin says:

    Once again Great work! The internet is a very very large place, and I must say yours is on top of all others in my view. :)

    Definitely prefer fortnightly so we can order parts and receive them. (Although I am still playing catch up :P)

    With the transmitters/recievers, comparing with something like the XBee Module’s, is there any other differences than data speed?

    • John Boxall says:

      Hello Carlin
      Thanks again for your comments. :) Yes, fortnightly (or even every three weeks) is looking like the future. Writing those tutorials really takes time, planning, building, debugging, testing, waiting for parts, etc. To be honest, I haven’t had a chance to check out the XBees yet, maybe next month. I just had a quick look through the manual (http://www.sparkfun.com/datasheets/Wireless/Zigbee/XBee-Manual.pdf), the main things that took my interest were: the higher data speed, some Xbees can have a much longer range, they are transceivers (data in and out), and look great. They have given me an idea for a “welcome home” automation project… Sorry I couldn’t be much more help at this stage. :(
      Cheers
      John

  5. John says:

    Hi John

    I have been 5 weeks plodding through all sorts of arduino searches, and now I have found your neat and tidy website – well done, very informative !

    I have built three projects so far, ( a 2 axis cnc machine, a keypad to 4 serial 7seg displays, and a wireless selectable audio announcer using a SD card, and am busy with another 2 projects simultaneously !

    I think I must go back and start the tutorials again when these are done …….. ( I think I must have had a lot of luck on the first 3 :-)

    Cheers

    John Smith ( boffin 1 on arduino )
    Cape Town

  6. Jean-Sébastien says:

    Hello,

    I’ve found something similar on http://www.lextronic.fr (http://www.lextronic.fr/75-radiofrequence.html)

    Receiver :
    http://www.telecontrolli.com/products-catalogue/rf-receivers/am-super-regenerative_en.html?page=shop.product_details&flypage=flypage.tpl&product_id=17&category_id=11

    transmitter :
    http://www.telecontrolli.com/products-catalogue/rf-transmitters/am-saw-resonator-tx_en.html?page=shop.product_details&flypage=garden_flypage.tpl&product_id=43&category_id=16

    I’m think to buil a home-made electric heating control system (and more).
    Those transmeter an receiver could help me to get external temperature or to control indoor or outdoor devices.

    It also exists FM version but AM are cheaper.
    I’ve also have no idea about operating distance.
    can you advise me please ?

    Thanks for your help and your interesting getting started.
    Regards,
    Jean-Sébastien

    • John Boxall says:

      Hello
      Those units would have a short range, around fifty metres at the most. If you need a longer range, I would recommend a Starman Databridge (www.starmanelectric) or perhaps a digital solution using XBees.
      john

  7. Hi John!

    I have a Wiring v 1.0, how many of these rotary encoders could I connect simultaneously to my board?

    Thanks for your article, it is by far my favourite on the subject! :-)

    Cheers,

    Rafael Marfil

  8. hemu says:

    how to connect rx/tx module with image????

  9. kumud gautam says:

    hi john:
    thank you for the wonderful blog. :).
    i am trying to connect an arduino and a PC. the main objective is to send the data to the PC, obtained from the transformer of 120 V, using arduino i.e. aslo wireless. i have RX 315 module.
    can i get some help!!!!!

    • John Boxall says:

      For safety reasons I will not advise people on how to work with mains voltages. Please contact a licensed electrician, electrical engineer, etc.

      • kumud gautam says:

        thank you for the reply, john . Actually, we have our supervisor for main voltage but he also don’t have much idea about the wireless communication. we only need help for the communication part. other things are arranged!

      • John Boxall says:

        OK. You should ask your questions in our group -http://groups.google.com/group/tronixstuff

  10. Hoyt says:

    Hi John,
    as in schematic exercise11.1, i use a pair of wires to connect from tx side to rx side as to substitute RF part, but it doesn’t work. Can you suggest a solution or the reason why?

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

Arduino Tutorials

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: