Arduino Weather Station With RF433 MHz Modules

70,046

579

19

Introduction: Arduino Weather Station With RF433 MHz Modules

In this project I will show you how make two Arduinos talk to each other using RF frequency (wireless)

In the past I published four instructables that lead to this one :

The first two are about connecting a serial LCD with I2C to an Arduino UNO and a NANO

https://www.instructables.com/id/How-to-connect-a-s...

https://www.instructables.com/id/How-to-connect-a-s...

Another one showing how to use an LM35 temperature sensor with Arduino and an LCD

https://www.instructables.com/id/Display-temperatur...

And the last one is about using an LM35 temperature sensor without an LCD

https://www.instructables.com/id/How-to-display-tem...

Now I will use the knowledge in all these project and improve on them by making one Arduino send data to another Arduino wirelessly using an RF433 module and displaying it on I2C serial LCD.

Step 1: What Is Needed for This Project

Here is what you'll need for this project:

  1. 2 Arduinos, I am using an UNO and a NANO
  2. 2 Solderless breadboards
  3. A pair of RF433 Wireless TX-RX
  4. An LM35 temperature sensor
  5. An I2C serial LCD
  6. And a bunch of jumper wires

The RF433 Wireless TX+RX Pair are ideal for this project because they have a good range about 14 meters or 47 feet without antenna and 31 meters or 102 feet if you attach a 17.4cm antenna on both modules. Those numbers are in theory, real life result may vary according to voltage, temperature, walls etc.... but the idea is that they are great for a 1$ piece of electronics.

Step 2: Connect the Uno, LM35 and the Transmitter

I selected the UNO for this part because it can be powered by an external source.

First connect the GND and the VCC from the Arduino to the bread board

Insert the LM35 on the breadboard and connect the GND and the VCC (see picture for the location of the VCC and the GND pin on the LM35) The middle prong connects to PIN A0 on the Arduino.

If you reverse the GND and the VCC on the LM35, it will heat up and produce readings in the range of 300 to 500 degrees C. (if this happens avoid touching it with your hands)

Insert the RF433-TX module, place it facing you and Pins should be DATA, VCC, GND from left to right (see picture)

Connect the VCC and the GND to the +/- rails on the breadboard and the Data pin connects on digital pin 12 on the Arduino.

This is it for this part, next I will discuss the transmitter sketch.

Step 3: Transmitter Sketch

Start by loading the VirtualWire library which is responsible for communication between the RF433 TX and RX modules

#include <VirtualWire.h>

Next I will define few variables

float temp;        This will be the variable I will use to store the temperature reading<br>int sensor = 0;    This is the A0 where the LM35 data pin is connected                   char msg[6];    This is a Char array called msg that I will use to transmit the data with

Next is the void setup

Here I will define the TX pin is on digital pin 12 on the Arduino and set the transfer rate to 2000 bps

vw_set_tx_pin(12);          // Sets pin D12 as the TX pin<br>vw_setup(2000);         // Bits per sec

In the void loop I read the temperature from the sensor and store it in the variable temp then convert it to Celsius by multiplying the result with 0.48828125

temp = analogRead(sensor);
temp = temp * 0.48828125;

Then I change the type of the variable temp from float to char and store the values in an array called msg to transmit it to the RF433-RX

dtostrf(temp, 6,2,msg);

The I transmit the data over to the RX

vw_send((uint8_t *)msg, strlen(msg)); <br>vw_wait_tx();                                                                            delay(200);

The transmitter code and the virtual Wire library are attached in this step.Rece

Step 4: Connect the NANO, the Receiver and the I2C LCD

In this section I will connect the NANO with the LCD and the RF433-RX module

Plug in the NANO on the breadboard

Then insert the RF433-RX module

Connect the VCC and the GND from the RF433-RX to the NANO GND and VCC and connect the Data PIN (left most pin) to the digital pin 12 on the NANO

Connect the GND and the VCC from the I2C serial LCD to the GND and the VCC pins on the NANO, then connect the SDA to analog pin 4 on the NANO and the SCL to analog pin 5 on the NANO.

Step 5: Receiver Sketch

There is more action in this sketch:

First load the libraries:

#include <VirtualWire.h>
#include<Wire.h> 
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

Then define the variables: and initialize the LCD

#define I2C_ADDR          0x27        //Define I2C Address where the PCF8574A is<br>#define BACKLIGHT_PIN      3
#define En_pin             2
#define Rw_pin             1
#define Rs_pin             0
#define D4_pin             4
#define D5_pin             5
#define D6_pin             6
#define D7_pin             7
int I;
//Initialise the LCD
LiquidCrystal_I2C      lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

In the void setup I define the LCD, turn on the backlight, set the RX pin on digital 12 on the NANO, set the transfer rate to 2000bps and tell the receiver to listen for incoming transmission.

//Define the LCD as 16 column by 2 rows <br>    lcd.begin (16,2);
    
//Switch on the backlight
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    lcd.setBacklight(HIGH);
    
//Define the receiver pin and rate
    vw_set_rx_pin(12);       //Sets pin D12 as the RX Pin
    vw_setup(2000);          // Bits per sec
    vw_rx_start();           // Start the receiver PLL running

In the void loop, the NANO checks for transmission, and if it receives one, it prints "The temp is:" on the first line on the LCD and then prints the value with degrees Celsius on the second line

uint8_t buf[VW_MAX_MESSAGE_LEN];<br>   uint8_t buflen = VW_MAX_MESSAGE_LEN;
   
   if( vw_get_message(buf, &buflen) )
      {
        lcd.setCursor(0, 0);
        lcd.print("Temp inside is:");    
        lcd.setCursor(3,1);  
        
       for (i = 0; i < buflen; i++)
         { 
           lcd.write(buf[i]); 
                    
         }
        
           lcd.print((char)223);
           lcd.print("C");

The code is attached in this step

Have fun building it

Be the First to Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • Make It Bridge

      Make It Bridge
    • For the Home Contest

      For the Home Contest

    19 Comments

    0
    AqeelaD
    AqeelaD

    4 years ago

    you can send to me the code of the Receiver cuz I have an error

    0
    dillon868
    dillon868

    Question 4 years ago

    Hi, I'm using two 433MHz
    RF (UART) transceiver modules, one for TX and the other RX - Cytron : http://www.cytron.com.my/p-rf-uart-433-1km?search=433&description=1. I've tried using the VirtualWire library but transfer of information fails to work. Can you provide Part No of 433 modules you used in this project, I suspect the modules I'm using are not compatible with vw. Thanks

    0
    TrafikV
    TrafikV

    5 years ago

    With simple "10K thermistor" use this code to get correct temperature:

    #include <VirtualWire.h> //Load the library

    float temp; //Define the temp float variable

    int sensor = 0; // sensor middle pin on analog pin 0

    char msg[6];

    float R1 = 10000;

    float logR2, R2, T, Tc, Tf;

    float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

    int Vo;

    void setup()

    {

    Serial.begin(9600);

    vw_set_tx_pin(2); // Sets pin D2 as the TX pin

    vw_setup(2000); // Bits per sec

    }

    void loop()

    {

    Vo = analogRead (sensor);

    Serial.print ("Temperature: ");

    Serial.print (" C");

    Serial.println (Tc);

    R2 = R1 * (1023.0 / (float)Vo - 1.0);

    logR2 = log(R2);

    T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));

    Tc = T - 273.15;

    dtostrf(Tc, 6,2,msg); //converts the float into a char

    vw_send((uint8_t *)msg, strlen(msg)); //transmits the data

    vw_wait_tx(); // Wait until the whole message is gone

    delay(200);

    }

    0
    MamunEdt
    MamunEdt

    6 years ago

    I need 1 more Sensor Valu Voltage ...Wt To do ...

    i Mean Mufti sensor ...

    0
    licheong
    licheong

    6 years ago

    Is it possible to do it on one Arduino only? I knew that IR modules on the same Arduino can communicate with each other. Is it possible to transmit and receive at the same time?

    0
    Fliperone
    Fliperone

    7 years ago

    Hi! First of all, great tutorial!

    Now
    I have a question. Instead of "writing" the buf[i] I'm trying to save the result to a new int or string, whatever the received msg is. So how can I do that? If I save it to a new variable, I only get a string of ASCII values. I did search and I think, I need to use sscanf to transform the message back to normal, but couldn't figure out the syntax.

    Any help appreciated!

    Regards;
    Filip

    0
    g4ipz
    g4ipz

    7 years ago

    Hi There.

    I notice that the transmitter.ino and receiver.ino files attached in the instrucible are not the ones for this project but simply send a count sequence from the transmitter to the receiver for display on the serial monitor on the Arduino. Was that intended?

    0
    eliesalame
    eliesalame

    Reply 7 years ago

    Hi g4izp, you are correct, it took over 19000 views before someone realized that I uploaded the wrong code. I apologize for this mistake, it is already corrected.

    Thank you

    0
    g4ipz
    g4ipz

    Reply 7 years ago

    It works very nicely too. Nice piece of compact coding. Great stuff.

    0
    g4ipz
    g4ipz

    Reply 7 years ago

    Thanks for the update . I've noticed before how many people tend to comment on instructibles without apparently ever having read the coding thats provided.

    Thanks again though

    0
    Raphango
    Raphango

    7 years ago

    Great! =D

    0
    HenkO3
    HenkO3

    7 years ago

    I'm using codebender for my projects. When compiling the receiver file, I get error message:

    Looks like your project uses header files or libraries that do not exist in our system, in your personal libraries or in your sketch. More info Receiver for LM35.ino:2:10: fatal error: 'LCD.h' file not found
    #include
    ^
    1 error generated.

    Q: Where do I get the header file LCD.h and where do I put it (if I've gotten it)


    0
    shadow_k909
    shadow_k909

    7 years ago

    At what distance this weather station may work?

    0
    eliesalame
    eliesalame

    Reply 7 years ago

    In theory it should work at 47 feet without an antenna and 102 feet with a 17cm antenna. However, since we are dealing with RF signal it could be shorter depends on what you have in between the walls.

    0
    diy_bloke
    diy_bloke

    Reply 7 years ago

    my experience with the cheap 433MHz transmitter Receiver pair is that without antenna the reach is very limited and with the 17 cm straight wire is a couple of meters.
    I have very good results however with this simple antenna. Really, made a heck of a difference:

    https://arduinodiy.wordpress.com/2015/07/25/coil-l...

    0
    Doodle Snackers
    Doodle Snackers

    Reply 7 years ago

    If you connect the output of the TX433 MHz up to a 5KW linear amplifier and use a piece of damp string as an antenna then you should be able reach the moon on a still night.

    0
    electrowiz89
    electrowiz89

    7 years ago

    This will be very useful for me

    thanks for sharing

    I like how your projects have evolved and have come together to create this project. Very innovative and good work.

    0
    eliesalame
    eliesalame

    Reply 7 years ago

    Thank you very much :)