I have a project where one arduino transmits simple data to another arduino using cheap 433MHz RF modules. This works fine but now I bought another type of 433MHZ Rx module so that another arduino can also get the data and this is where the problem starts.
Both receiving arduinos print different values. The first one that used the cheap receiver is printing the correct value and the new one is printing a value much lower than the first one.
The new receiver I'm using is of superheterodyne type, could that be the problem?
both modules uses the same library and code but the first arduino is a nano whereas the new one is an uno. Both modules are powered from the arduino 5v pin.
Here is the code that both arduino runs.
#include <VirtualWire.h>
const int led_pin = 13;
const int receive_pin = 2;
void setup()
{
delay(1000);
Serial.begin(9600);
Serial.println("setup");
vw_set_rx_pin(receive_pin);
vw_setup(2000);
vw_rx_start();
pinMode(led_pin, OUTPUT);
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
digitalWrite(led_pin, HIGH);
Serial.print("Got: ");
Serial.print(buf[0]);
Serial.println();
digitalWrite(led_pin, LOW);
}
}
currently my first arduino prints a value "51" and my new one prints "36".
Update:
adding Tx sketch
#include <NewPing.h> // Ultrasonic module library
#include <VirtualWire.h> // RF module library
const byte TRIGGER_PIN = 11; // Trigger pin on D11
const byte ECHO_PIN = 12; // Echo pin on D12
const int MAX_DISTANCE = 200;// Max distance set at 200cm
const int led_pin = 13; // LED Indicator pin
const int transmit_pin = 10; // TX data pin
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // Set Ultrasonic
void setup()
{
Serial.begin(9600); // Serial communication at 9600 bauds
vw_set_tx_pin(transmit_pin); // Set TX pin
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Transmitter Bits per sec
pinMode(led_pin, OUTPUT); // LED Indicator
}
void loop()
{
delay(1000); // Wait (milliseconds) between each ping
int a = sonar.ping_median(5); // Digital filter by taking median of (x) number of pings
a = sonar.convert_cm(a); // Convert median to average in cm
byte g = (int) a; // Convert the integer 'z' into byte 'g'
digitalWrite(led_pin, HIGH); // Flash LED to show transmitting
vw_send(&g, 1 ); // Transmit the Byte 'g'
vw_wait_tx(); // Wait until the whole message is gone
Serial.print(g); // Print the Byte 'g' on Serial Monitor
Serial.println(); // Set Print on next line
digitalWrite(led_pin, LOW); // Turn off LED
}