Summary of 433MHz Radio Frequency (RF) transmitter and receiver using PIC12F1822
This project builds a 5-channel 433MHz RF remote control using two PIC12F1822 microcontrollers and cheap 433/315MHz RF transmitter/receiver modules. The transmitter reads five pushbuttons and sends NEC-protocol encoded 32-bit RF codes; the receiver decodes NEC timing with Timer1 and toggles five LEDs accordingly. CCS C source code for both transmitter and receiver is provided, using the PIC internal oscillator, internal pull-ups, and simple timing routines to generate and measure NEC pulses and spaces.Parts used in the 5-Channel 433MHz RF Remote Control:
- PIC12F1822 Microcontroller (transmitter)
- PIC12F1822 Microcontroller (receiver)
- 433MHz or 315MHz RF Transmitter module
- 433MHz or 315MHz RF Receiver module
- 5 Push Buttons
- 5 LEDs
- 5 x 470 Ohm Resistors
- 100 µF Capacitor
- +5V Power Source (for each circuit)
- Protoboard
- Jumper Wires
This project shows how to use low cost 433MHz RF transmitter/receiver modules to build a 5-channel wireless RF remote control system using 2 x PIC12F1822 microcontrollers.
The used RF modules in this project are cheap and easy to use with any microcontroller. These modules are shown below with pin configuration:
Communication protocol:
In this 433MHz RF project data is transmitted from the transmitter circuit to the receiver circuit using NEC protocol. The NEC protocol uses pulse distance encoding of the bits. Each pulse is a 562.5µs long.
Logic 0: 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1125µs (562.5 x 2).
Logic 1: a 562.5µs pulse burst followed by a 1687.5µs (562.5 x 3) space, with a total transmit time of 2250µs (562.5 x 4).
The following topic shows how to decode an IR remote control uses the NEC communication protocol:
Extended NEC Protocol Decoder Using PIC12F1822 Microcontroller
Components List:
RF Transmitter Circuit:
- PIC12F1822 Microcontroller
- 433MHz or 315MHz RF Transmitter
- 5 Push Buttons
- +5V Power Source
- Protoboard
- Jumper Wires
RF Receiver Circuit:
- PIC12F1822 Microcontroller
- 433MHz or 315MHz RF Receiver
- 100uf Capacitor
- 5 LEDs
- 5 x 470 Ohm Resistors
- +5V Power Source
- Protoboard
- Jumper Wires
5-Channel 433MHz RF remote control transmitter circuit:
The RF transmitter circuit schematic is shown below.
In the circuit there 5 push buttons and each button sends a different RF signal code. The RF transmitter is the element that sends the RF signals to the RF receiver circuit.
PIC12F1822 internal pull-ups are enabled by the software and the internal oscillator is used as usual.
5-Channel 433MHz RF remote control transmitter using PIC12F1822 CCS PIC C code:
In the circuit there are 5 push buttons connected to RA0, RA1, RA2, RA3 and RA4 which means that pins must be configured as inputs and the RA5 pin as output.
Internal pull-ups are enabled for the input pins with the following line:
port_a_pullups(0x1F);
The five buttons transmit the following signals respectively:
0x40BF00FF -- 0x40BF807F -- 0x40BF40BF -- 0x40BF20DF -- 0x40BFA05F
1s and 0s are transmitted as:
Transmit 1 : output_high(PIN_A5);
Transmit 0: output_low(PIN_A5);
For example the transmission of 9ms pulse and 4.5ms space:
// Send 9ms pulse
output_high(PIN_A5);
delay_ms(9);
// Send 4.5ms space
output_low(PIN_A5);
delay_us(4500);
CCS C code:
// NEC protocol 433MHz RF remote control transmitter using PIC12F1822 CCS PIC C code
// http://ccspicc.blogspot.com/
// [email protected]
// Use at your own risk
#include <12F1822.h>
#fuses NOMCLR INTRC_IO PLL_SW
#use delay(clock=32000000)
#use fast_io(A)
void send_signal(unsigned int32 number){
int8 i;
// Send 9ms pulse
output_high(PIN_A5);
delay_ms(9);
// Send 4.5ms space
output_low(PIN_A5);
delay_us(4500);
// Send data
for(i = 0; i < 32; i++){
// If bit is 1 send 560us pulse and 1680us space
if(bit_test(number, 31 - i)){
output_high(PIN_A5);
delay_us(560);
output_low(PIN_A5);
delay_us(1680);
}
// If bit is 0 send 560us pulse and 560us space
else{
output_high(PIN_A5);
delay_us(560);
output_low(PIN_A5);
delay_us(560);
}
}
// Send end bit
output_high(PIN_A5);
delay_us(560);
output_low(PIN_A5);
delay_us(560);
}
void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON); // Set internal oscillator to 32MHz (8MHz and PLL)
output_a(0);
set_tris_a(0x1F); // Configure RA5 pin as output and others as inputs
port_a_pullups(0x1F); // Enable internal pull-ups for pins RA0,RA1,RA2,RA3 & RA4
while(TRUE){
while(!input(PIN_A0)){
send_signal(0x40BF00FF);
delay_ms(500);
}
while(!input(PIN_A1)){
send_signal(0x40BF807F);
delay_ms(500);
}
while(!input(PIN_A2)){
send_signal(0x40BF40BF);
delay_ms(500);
}
while(!input(PIN_A3)){
send_signal(0x40BF20DF);
delay_ms(500);
}
while(!input(PIN_A4)){
send_signal(0x40BFA05F);
delay_ms(500);
}
}
}
5-Channel 433MHz RF remote control receiver circuit:
In the 433MHz RF receiver circuit there are 5 LEDs and an RF receiver. The RF receiver receives radio signals transmitted from the RF transmitter. Each LED is remotely controlled from one button in the transmitter circuit.
PIC12F1822 internal oscillator is used and MCLR pin is configured as a digital input pin.
5-Channel 433MHz RF remote control receiver using PIC12F1822 CCS PIC C code:
As in the RF transmitter the internal oscillator of the RF receiver microcontroller is used.
Timer1 is configured to increment every 1us and it is used to measure pulses and spaces duration (@ 32MHz mcu frequency).
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
For example to check the 9ms pulse the following lines are used:
// Check 9ms pulse (remote control sends logic high)
SET_TIMER1(0);
while(input(IR_Sensor) && (count < 9500))
count = GET_TIMER1();
if( (count > 9499) || (count < 8500))
return FALSE;
And checking the 4.5ms space as follows:
// Check 4.5ms space (remote control sends logic low)
SET_TIMER1(0);
count = 0;
while((!input(IR_Sensor)) && (count < 5000))
count = GET_TIMER1();
if( (count > 4999) || (count < 4000))
return FALSE;
Full Code:
// NEC protocol 433MHz RF remote control receiver using PIC12F1822 CCS PIC C code
// http://ccspicc.blogspot.com/
// [email protected]
// Use at your own risk
#include <12F1822.h>
#fuses NOMCLR INTRC_IO PLL_SW
#use delay(clock=32000000)
#use fast_io(A)
#define RF_Receiver PIN_A3
unsigned int32 rf_code;
short nec_remote_read(){
unsigned int16 count = 0;
unsigned int8 i;
// Check 9ms pulse (RF remote control sends logic high)
SET_TIMER1(0);
while(input(RF_Receiver) && (count < 9500))
count = GET_TIMER1();
if( (count > 9499) || (count < 8500))
return FALSE;
// Check 4.5ms space (RF remote control sends logic low)
SET_TIMER1(0);
count = 0;
while((!input(RF_Receiver)) && (count < 5000))
count = GET_TIMER1();
if( (count > 4999) || (count < 4000))
return FALSE;
// Read RF message (32 bits)
for(i = 0; i < 32; i++){
SET_TIMER1(0);
count = 0;
while(input(RF_Receiver) && (count < 650))
count = GET_TIMER1();
if( (count > 649) || (count < 500))
return FALSE;
count = 0;
SET_TIMER1(0);
while((!input(RF_Receiver)) && (count < 1800))
count = GET_TIMER1();
if( (count > 1799) || (count < 400))
return FALSE;
if( count > 1000) // If space width > 1ms
bit_set(rf_code, (31 - i)); // Write 1 to bit (31 - i)
else // If space width < 1ms
bit_clear(rf_code, (31 - i)); // Write 0 to bit (31 - i)
}
return TRUE;
}
void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON); // Set internal oscillator to 32MHz (8MHz and PLL)
output_a(0);
set_tris_a(8);
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
while(TRUE){
while(!input(RF_Receiver)); // Wait until RF_Receiver pin raises
if(nec_remote_read()){
if(rf_code == 0x40BF00FF)
output_toggle(PIN_A0);
if(rf_code == 0x40BF807F)
output_toggle(PIN_A1);
if(rf_code == 0x40BF40BF)
output_toggle(PIN_A2);
if(rf_code == 0x40BF20DF)
output_toggle(PIN_A4);
if(rf_code == 0x40BFA05F)
output_toggle(PIN_A5);
}
}
}
433MHz Radio Frequency (RF) transmitter and receiver using PIC12F1822:
Source : 433MHz Radio Frequency (RF) transmitter and receiver using PIC12F1822
Quick Solutions to Questions related to 5-Channel 433MHz RF Remote Control:
- What communication protocol is used by the RF remote control?
The NEC protocol is used, which encodes bits by pulse distance with a 562.5µs base pulse. - Which microcontroller is used in both transmitter and receiver?
The PIC12F1822 microcontroller is used for both transmitter and receiver. - How many channels does the remote control support?
It supports five channels, one per push button and one per LED on the receiver. - How are logic 0 and logic 1 encoded in NEC timing?
Logic 0 is a 562.5µs pulse plus 562.5µs space; logic 1 is a 562.5µs pulse plus 1687.5µs space. - Which pin is used to transmit RF signal on the transmitter PIC?
PIC pin RA5 (PIN_A5) is used as the RF output for transmission. - How does the receiver measure pulse and space durations?
The receiver uses Timer1 configured to increment every 1µs to time pulses and spaces for NEC decoding. - Are internal pull-ups and internal oscillator used?
Yes; internal pull-ups are enabled for input pins on the transmitter and the internal oscillator is used on both devices. - What are the 32-bit RF codes transmitted for the five buttons?
The codes are 0x40BF00FF, 0x40BF807F, 0x40BF40BF, 0x40BF20DF, and 0x40BFA05F respectively. - What happens on the receiver when a matching RF code is decoded?
The corresponding output pin toggles to control the associated LED.
Related projects
RFID Reader – Access Control System
This device is a simple access control system which uses RFID cards. It is designed with PIC12F1822 microcontroller running on internal oscillator...
Wireless & IoT · PIC12F1822Wireless Communication Using Cheap 433MHz RF Modules and Pic Microcontrollers. Part 2
On the first part of this instructable, I demonstrated how to program a PIC12F1822 using MPLAB IDE and XC8 compiler, to send...
Sensors & Temperature · PIC12F1822DHT11 Interfacing with PIC12F1822 microcontroller
In this blog there are some topics talking about the DHT11 relative humidity and temperature sensor and how to interface it with...
Audio, Sound & RadioAudio Spectrum Analyzer
We developed an audio spectrum analyzer as our final project for ECE 4760. This analyzer presented a histogram-style representation of audio signals....
Audio, Sound & Radio · PIC12F675Audio CRO using PIC12F675 Microcontroller
This project is a miniature Audio CRO. For those not familiar with the abbreviation "CRO," it means "Cathode Ray Oscilloscope" and this...
Audio, Sound & RadioBuild a musical EKG with the Freescale FRDM-KL05
Short Introduction: I have been following the Battle of the DreamBoards Championship with interest and I enjoyed the variation of functionality features...


