Reader small image

You're reading from  Mastering Arduino

Product typeBook
Published inSep 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781788830584
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Jon Hoffman
Jon Hoffman
author image
Jon Hoffman

Jon Hoffman has over 25 years of experience in the field of information technology. Over these years, Jon has worked in the areas of system administration, network administration, network security, application development, and architecture. Currently, Jon works as a senior software engineer for Syn-Tech Systems. Jon has developed extensively for the iOS platform since 2008. This includes several apps that he has published in the App Store, apps that he has written for third parties, and numerous enterprise applications. He has also developed mobile applications for the Android and Windows platforms. What really drives Jon the challenges that the field of information technology provides and there is nothing more exhilarating to him than overcoming a challenge. Some of Jon's other interests are spending time with his family, robotic projects, and 3D printing. Jon also really enjoys Tae Kwon Do, where he and his oldest daughter Kailey earned their black belts together early in 2014, Kim (his wife) earned her black belt in December 2014, and his youngest daughter Kara is currently working towards her black belt.
Read more about Jon Hoffman

Right arrow

Remotely Controlling the Arduino

When I was a kid, my parents used to use both myself and my sister as the remote control for the television sets because back then, television sets did not come with remote controls. Fortunately, Eugene Polley, an engineer at Zenith, came up with the idea to control television with remote controls, saving millions of kids from having to change the channels for their parents. The remote control greatly enhanced how we interacted with the television set and can do the same for your Arduino project.

In this chapter, you will learn:

  • How to connect a radio frequency remote control to an Arduino
  • How to determine what button is pressed on a radio frequency remote
  • How to connect an infrared remote control to an Arduino
  • How to determine what button is pressed on an infrared remote

Introduction

In this chapter, we will look at a couple of ways that we can control our Arduino project remotely. For the first project, we will use the Keyestudio IR (infrared) receiver, which uses the HX1838 infrared control module. The HX1838 infrared control module is used in numerous IR receivers that can be used by the Arduino. Therefore, you do not need to specifically get the Keyestudio one that we use here.

An infrared transmitter has an LED that emits infrared radiation, which is picked up by the infrared receiver. When a button is pressed on the remote control, the LED on the transmitter will blink very quickly for a fraction of a second and the receiver will read the pattern of blinks and interpret it.

The Keyestudio IR receiver that we will be using in this chapter looks like the following photograph:

The pin marked with the S is the signal pin and should be connected...

Components needed

For these projects, you will need the following items:

  • One Arduino Uno or compatible board
  • One infrared receiver
  • One or more infrared transmitter(s)
  • One RF transmitter and receiver pair
  • Jumper wires
  • Breadboard

Circuit diagrams

The following diagram shows how we connect the infrared receiver to the Arduino:

The 5V in and the ground pins on the IR receiver are connected to the appropriate rails on the breadboard. The signal pin is connected to the digital 2 pin on the Arduino. Now let's look at how we would connect the radio frequency receiver to the Arduino:

The 5V in and the ground pins on the RF receiver are connected to the appropriate rails on the breadboard. The four output pins on the receiver are connected to the 8, 9, 10 and 11 digital pins on the Arduino. When a button is pressed on the transmitter, the corresponding output pin on the receiver goes to HIGH.

Now let's look at the code for our projects.

Code

Before we can start writing the code that will read the input from the infrared receiver, we will need to load the IRremote library by shirriff. The following screenshot shows the library and version that we will use:

Once the library is loaded, we will need to start by importing the header file for the IRremote library and creating the global variables and directives. The following code shows how to do that:

#include <IRremote.h>

#define IR_PIN 2
IRrecv ir(IR_PIN);
decode_results irCode;

In the preceding code, we start off by including the IRremote.h header file into our project. We then define that the infrared receiver is connected to pin 2 on the Arduino. Next, we create an instance of the IRrecv type, which is used to read the input from the IR receiver. Finally, we create an instance of the decode_results type, which is used to store the values from the IR receiver...

Challenge

In this chapter, we saw two types of remote control devices. The first was the IR control, which needs a line of sight to the project and can have a lot of different buttons. The radio frequency remote is good when the remote needs to work over greater distances from the device or even in a different room.

There are numerous other ways to create remote controls using wireless signals, such as Zigbee radios or even Wi-Fi; however, for this challenge, we want you to think outside the box and to begin to expand your own horizons. The challenge for this chapter is to think of ways to remotely control your device without using a wireless signal.

You may be shaking your head right now wondering what we mean by remotely controlling a project without using a wireless signal. One example of this would be the clapper. The clapper is a sound-activated electrical switch...

Summary

In this chapter, we saw how to use an IR remote and an RF remote with an Arduino. You were also challenged to think outside of the box and think of other ways that you could remotely control your project without using a wireless signal. The reason this challenge was in this last project chapter was to get you to start thinking outside of the box when designing your projects because thinking outside of the box and creating new and improved ways to do something is what gets people excited about these types of projects. It can also make you a lot of money if you are able to monopolize your project.

In the next chapter, we will talk about how you can use the knowledge you gained from previous project chapters to create a simple robot. We will not be writing the code or designing the circuits for you. Instead we will show you how to put the pieces you have learned in the book...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Arduino
Published in: Sep 2018Publisher: PacktISBN-13: 9781788830584
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jon Hoffman

Jon Hoffman has over 25 years of experience in the field of information technology. Over these years, Jon has worked in the areas of system administration, network administration, network security, application development, and architecture. Currently, Jon works as a senior software engineer for Syn-Tech Systems. Jon has developed extensively for the iOS platform since 2008. This includes several apps that he has published in the App Store, apps that he has written for third parties, and numerous enterprise applications. He has also developed mobile applications for the Android and Windows platforms. What really drives Jon the challenges that the field of information technology provides and there is nothing more exhilarating to him than overcoming a challenge. Some of Jon's other interests are spending time with his family, robotic projects, and 3D printing. Jon also really enjoys Tae Kwon Do, where he and his oldest daughter Kailey earned their black belts together early in 2014, Kim (his wife) earned her black belt in December 2014, and his youngest daughter Kara is currently working towards her black belt.
Read more about Jon Hoffman