How to use a 315MHz remote with an Arduino

Got Questions? Click here and post them in the Brainy-Bits Forum to get help!

OVERVIEW

We already did a tutorial on how to use an IR remote control, today we will learn how to use an RF remote.

Since the RF signals can go through walls, this kind of remote can be useful when your project is in another room. 

The remote has 4 buttons which corresponds to 4 pins on the receiver.  The RF module uses the SC2272-M4, which is the momentary version, so the pin will stay HIGH as long as we hold down the button.

We will use a 4bits 7 segment LED display to show which button was pressed instead of the serial monitor.



SCHEMATIC

 

Using a 315mhz remote with an arduino

Both the Display and the RF receiver need 5V and Ground.

 

We are connecting the 5V – GND of the Arduino to the breadboard power rails so we can connect both modules.

 

The RF receiver has 4 pins for each buttons, and one DT (trigger) pin that will activate if any buttons is pressed.

 

The Display uses the I2C bus, so it only needs 2 pins.



THE CODE

We are using the TM1637 library to drive the 7 segment display. 

Instead of IF statements to detect which button is pressed, we will use WHILE loops in our code instead.

This way our code will pause and wait for us to press a button, instead of looping and having to refresh the 7 segment display over and over again.

The first WHILE loop will check all the receiver pins, if ALL of them are LOW, the code will stay in the loop, if any button is pressed, then that pin will become HIGH making the condition false and the code will exit the loop.

The other WHILE loops check which pin is HIGH and execute the code inside.

 

As always, you can have a look at the tutorial video for more information.

#include "TM1637Display.h"  //  Library for 7 segment Display

//{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//0~9,A,b,C,d,E,F  // Available for display
 

#define CLK 3  // Pins for display     
#define DIO 4
TM1637Display tm1637(CLK,DIO);
 

void setup(){
  tm1637.init();  // Reset Display 
  tm1637.set(BRIGHT_TYPICAL); 
  //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  delay(1500);  // Delay to let system boot 
}

 
void loop(){
 

  while (digitalRead(9) == LOW && digitalRead(10) == LOW && digitalRead(11) == LOW && digitalRead(12) == LOW) {
    tm1637.display(3,0);  // Loops until button is pressed
  }  
  
  tm1637.clearDisplay();  // Clear display
  
  while (digitalRead(9) == HIGH) {  // Button 1 pressed
    tm1637.display(0,1);
  }
  
  while (digitalRead(10) == HIGH) {  // Button 2 pressed
    tm1637.display(1,2);
  }  
  
  while (digitalRead(11) == HIGH) {  // Button 3 pressed
    tm1637.display(2,3);
  }
  
  while (digitalRead(12) == HIGH) {  // Button 4 pressed
    tm1637.display(3,4);
  }
    tm1637.clearDisplay();

}



TUTORIAL VIDEO



DOWNLOAD

Copy and paste the above code in the Arduino IDE to program your Arduino.

 

Used Libraries:

Download the TM1637 created by avishorp here:  https://github.com/avishorp/TM1637

 

Once downloaded, just extract the content of the zip files inside your “arduino/libraries” folder.

Got Questions? Click here and post them in the Brainy-Bits Forum to get help!

Leave a comment

Comments have to be approved before showing up