Wireless connection via 433 MHz with the Arduino

FunduinoPublished on

Daten drahtlos zwischen zwei Arduinos übertragen

Die Sender und Empfänger für das 433-MHz-Funksignal sind relativ kleine und günstige Bauteile. Sie eignen sich für kleine Datenverbindungen über einen Abstand von wenigen Metern. Die beiden Module kannst du jedoch mit kleinen Antennen ausstatten und so die Reichweite erhöhen. Die Antennen lötest du jeweils an der dafür vorgesehenen Stelle an die Module.

Auf der 433-MHz-Frequenz werden die gesendeten Daten unverschlüsselt übermittelt. Du solltest dir also darüber im Klaren sein, dass andere Personen die Daten abfangen könnten. Den Sender kannst du mit ca. 3,5 V bis 12 V betreiben – je höher die Spannung, desto höher ist die Reichweite.

Für diese Anleitung brauchst du die RCSwitch-Library (github.com/sui77/rc-switch). Du musst sie installieren, bevor du die Sketche verwendest.

Aufgabenstellung: Mit dem Sender sendest du ein 433-MHz-Signal. Ein zweiter Arduino-Mikrocontroller empfängt die Daten und zeigt sie im Serial Monitor an.

433 MHz radio transmitter and receiver for data transmission between two Arduinos
Transmit data between two microcontrollers via 433 MHz
Solder points for the antennas on the 433 MHz radio transmitter and receiver
Antennas for the 433 MHz radio transmitter and receiver
1 / 2

You need this

433 MHz Radio Module Set - Transmitter and Receiver, 3.3-5 V 433 MHz Radio Module Set - Transmitter and Receiver, 3.3-5 V 2,90 € *Item no. F23108773About the product — 433 MHz Radio Module Set - Transmitter and Receiver, 3.3-5 V
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino 830-point Breadboard - solderless breadboard for Arduino 2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
Breadboard cables male-female - 40 pieces, 20 cm Breadboard cables male-female - 40 pieces, 20 cm 1,74 € *Item no. FUN-1010554About the product — Breadboard cables male-female - 40 pieces, 20 cm
LED 5 mm - 100 Pieces, 5 Colors, 2 V LED 5 mm - 100 Pieces, 5 Colors, 2 V 1,97 € *Item no. F23107316About the product — LED 5 mm - 100 Pieces, 5 Colors, 2 V
Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W 1,72 € *Item no. F23107216About the product — Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W

All 7 parts together 24,09 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

The 433 MHz radio transmitter module

These modules support various transmission methods and protocols, such as sending binary code, decimal numbers, or Tri-State. In this guide, we’ll focus on sending decimal numbers, as they’re the easiest to process.

The transmitter has three connections. To wire it up, connect the data pin to pin 10 on the Arduino, VCC to 5V, and GND to GND.

Transmitter connections viewed from the front: GND on the left, VCC in the middle, DATA on the right.

433 MHz radio transmitter module, connections: left GND, center VCC, right DATA
The 433 MHz radio transmitter module
Wiring the 433 MHz radio transmitter to the Arduino: DATA to pin 10, VCC to 5V, GND to GND
433 MHz radio transmitter module on the Funduino UNO R3 (old version)
1 / 2
Program code - 433 MHz radio transmitter
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
  mySwitch.enableTransmit(10);  // The transmitter is connected to pin 10
}
void loop() {
  mySwitch.send(1234, 24); // The 433 MHz transmitter sends the decimal number "1234"
  delay(1000);  // One-second pause, then the sketch starts over
}

The 433 MHz radio receiver module

The receiver constantly checks for incoming signals on the 433 MHz frequency. As soon as it detects a signal, the Arduino microcontroller interrupts the program (loop). You can then display and process the received data in the Serial Monitor.

The receiver runs on 5 V. A higher voltage will not increase its range. An antenna is also useful for the receiver.

The receiver has four connections. To use it, connect any Data pin to pin 2 on the Arduino. In the sketch, this is described as pin 0 because it is interrupt pin 0.

Receiver connections when viewed from the back: GND on the left, DATA in the middle (2x), VCC on the right.

433 MHz radio receiver module, pins: left GND, center 2x DATA, right VCC
The 433 MHz radio receiver module
Wiring the 433 MHz radio receiver to the Arduino: DATA to pin 2, VCC to 5V, GND to GND
433 MHz radio receiver module for the Funduino UNO R3 (old version)
1 / 2
Program Code – 433 MHz Radio Receiver
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup()
{
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver is connected to interrupt pin "0" - on the UNO, that is pin 2
}
void loop() {
  if (mySwitch.available()) // If a code is received...
  {
    int value = mySwitch.getReceivedValue(); // The received data is stored in the variable "value".
    if (value == 0) // If the received data is "0", "Unknown code" is displayed.
    {
      Serial.println("Unknown code");
    }
    else // If the received code is usable, it is sent to the Serial Monitor here.
    {
      Serial.print("Received: ");
      Serial.println( value );
    }
    mySwitch.resetAvailable(); // The receiver is "reset" here
  }
}

Expansion: Transmit signals between two microcontrollers

When you press a button on the first Arduino, an LED on the second Arduino should light up. To do this, connect an additional LED to pin 12 of the receiver Arduino.

You cannot use the onboard LED on pin 13 in this case.

Circuit diagram of the radio transmitter with a push button on pin 7 and a transmitter module on pin 10
Circuit diagram – wireless transmitter with button
Schematic of the radio receiver with an LED on pin 12 and a receiver module on pin 2
Circuit diagram - radio receiver with LED
1 / 2
Program code – radio transmitter with push button
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int taster = 7; // The word "taster" now stands for the value 7.
int tasterstatus = 0; // This variable stores whether the button is pressed or not.
void setup() // The setup starts here.
{
  mySwitch.enableTransmit(10);  // The transmitter is connected to pin 10
  pinMode(taster, INPUT); // The pin with the button (pin 7) is now an input.
}
void loop()
{ // This brace opens the loop section.
  tasterstatus = digitalRead(taster); // Pin 7 is read here (command: digitalRead).
  if (tasterstatus == HIGH) // Processing: If the button is pressed (the voltage signal is high)...
  { // Open the program section of the IF statement.
    mySwitch.send(5678, 24); // The 433 MHz transmitter sends the decimal number "5678"
    delay(50); // 50 millisecond pause
  } // Close the program section of the IF statement.
  else // ...otherwise...
  { // Open the program section of the else statement.
    mySwitch.send(1234, 24); // The 433 MHz transmitter sends the decimal number "1234"
  } // Close the program section of the else statement.
} // This final brace closes the loop section.
Program code - radio receiver with LED
#include <RCSwitch.h>
int LED = 12;
RCSwitch mySwitch = RCSwitch();
void setup()
{
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver is connected to interrupt pin "0" - on the UNO, that's pin 2
  pinMode(LED, OUTPUT); // The pin with the LED (pin 12) is now an output.
}
void loop() {
  if (mySwitch.available()) // If a code is received...
  {
    int value = mySwitch.getReceivedValue(); // The received data is stored in the variable "value".
    if (value == 0) // If the received data is "0", "Unknown code" is displayed.
    {
      Serial.println("Unknown code");
    }
    else // If the received code is usable, it is sent to the Serial Monitor here.
    {
      Serial.print("Received: ");
      Serial.println( value );
      if (value == 5678)   // Processing: If the Arduino receives the number "5678", then...
      {   // Open the program section of the IF statement.
        digitalWrite(LED, HIGH); // ...the LED should light up
        delay(500);   // for 0.5 seconds (500 milliseconds).
        digitalWrite(LED, LOW); // Then the LED should be off.
      }   // Close the program section of the IF statement.
    }
    mySwitch.resetAvailable(); // The receiver is "reset" here
  }
}

Extension: Transmit measurement data wirelessly

A temperature sensor is also connected to the Arduino with the transmitter module. Temperature sensor You send the sensor reading via 433 MHz to a second Arduino and display it there in the Serial Monitor. A warning LED on the receiver Arduino should also light up when the temperature is 25 °C or higher.

Connect the temperature sensor’s data line to pin A0.

The transmitter sends the temperature as a decimal number. Temperatures below zero cannot be transmitted correctly this way, so the sketch is suitable for temperatures of 0 °C and above.

Circuit diagram of the radio transmitter with temperature sensor on A0 and transmitter module on pin 10
Circuit diagram - radio transmitter with temperature sensor
Circuit diagram of the radio receiver with warning LED on pin 12 and receiver module on pin 2
Circuit diagram – radio receiver with warning LED
1 / 2
Program code – radio transmitter with temperature sensor
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int TMP36 = A0; // The sensor is connected to analog pin A0. From now on, we’ll call the pin "TMP36".
int sensorwert; // Create a variable for the sensor reading.
int temperatur = 0; // The temperature value will later be stored in the variable "temperatur".
void setup() // This is where setup begins.
{
  mySwitch.enableTransmit(10);  // The transmitter is connected to pin 10
}
void loop()
{ // This brace opens the loop section.
  sensorwert = analogRead(TMP36); // Read the sensor value.
  temperatur = map(sensorwert, 0, 410, -50, 150); // Convert the sensor value using the "map" command.
  mySwitch.send(temperatur, 24); // The 433-MHz transmitter sends the temperature as a decimal number.
  delay(1000); // Pause for one second.
} // This final brace closes the loop section.
Program code - radio receiver with warning LED
#include <RCSwitch.h>
int LED = 12;
RCSwitch mySwitch = RCSwitch();
void setup()
{
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver is connected to interrupt pin "0" - on the UNO, this is pin 2
  pinMode(LED, OUTPUT); // The pin with the LED (pin 12) is now an output.
}
void loop() {
  if (mySwitch.available()) // If a code is received...
  {
    int value = mySwitch.getReceivedValue(); // Received data is stored in the variable "value".
    Serial.print("Temperature: ");
    Serial.println( value );
    if (value >= 25) // Processing: If the temperature is 25 °C or higher...
    { // Open the program section of the IF statement.
      digitalWrite(LED, HIGH); // ...the LED should light up
    } // Close the program section of the IF statement.
    else // ...otherwise...
    { // Open the program section of the else statement.
      digitalWrite(LED, LOW); // ...the LED should be off.
    } // Close the program section of the else statement.
    mySwitch.resetAvailable(); // The receiver is "reset" here
  }
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.