Go Down

Topic: XY-MK-5V 433Mhz RF Receiver AND FS1000A/XY-FST RF 433Mhz Transmitter (Read 14949 times) previous topic - next topic

gc9n

I just bought this kit (4 pairs) from ebay ,

and i am trying to make them work with the VirtualWire Library...

But I cannot make it work with it...

the TX is on a UNO
and RX is on a MEGA..

i made a simple sketch that send data from humidity sensor ... but the RX doesnt get it ....

TX
Code: [Select]

// transmitter.pde
//
// Simple example of how to use VirtualWire to transmit messages.
// Implements a simplex (one-way) transmitter.
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
// TX data to Digital I/O pin 12.
// Sends DHT11 data.

#define DEBUG

#include <VirtualWire.h>
// Init VWMsgBuf.
char VWMsgBuf[VW_MAX_MESSAGE_LEN];
// Init VWMsgStr.
String VWMsgStr;

#include <dht11.h>
// Init DHT11.
dht11 DHT11;
// DHT11 OUT to digital I/O pin.
#define DHT11_PIN 2

// Init hello world count.
unsigned int cnt = 0;

// setup() runs once after reset.
void setup() {
  #ifdef DEBUG
    // Init serial for debugging.
    Serial.begin(9600);
  #endif
  // Init BPS.
  vw_setup(3000);
  vw_set_tx_pin(7);
  // Send setup() message.
  VWMsgStr = "REMOTE1: setup()!";
  VWTX(VWMsgStr);
  #ifdef DEBUG
    Serial.println(VWMsgStr);
  #endif
}

// loop() runs continuously after setup().
void loop() {
  // Send hello world message.
  VWMsgStr = "REMOTE1: Hello World!  Count=" + String(cnt++);
  VWTX(VWMsgStr);
  #ifdef DEBUG
    Serial.println(VWMsgStr);
  #endif

  // Send DHT11 message.
  int rc = DHT11.read(DHT11_PIN);
  switch (rc) {
    case DHTLIB_OK:
      VWMsgStr = "REMOTE1: OK. Humi%: " + String(DHT11.humidity);
      VWMsgStr += "  TempC: " + String(DHT11.temperature);
      VWMsgStr += "  TempF: " + String(fahrenheit(DHT11.temperature));
      break;
    case DHTLIB_ERROR_CHECKSUM:
      VWMsgStr = "REMOTE1: Checksum!";
      break;
    case DHTLIB_ERROR_TIMEOUT:
      VWMsgStr = "REMOTE1: Time Out!";
      break;
    default:
      VWMsgStr = "REMOTE1: Unknown!";
      break;
  }
  VWTX(VWMsgStr);
  #ifdef DEBUG
    Serial.println(VWMsgStr);
  #endif
}

// Virtual Wire Transmit msgStr
void VWTX(String VWMsgStr) {
  VWMsgStr.toCharArray(VWMsgBuf, VW_MAX_MESSAGE_LEN);
  uint8_t VWMsgBufLen = strlen(VWMsgBuf);
  digitalWrite(13, true); // Flash a light to show transmitting
  vw_send((uint8_t *)VWMsgBuf, strlen(VWMsgBuf));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13, false);
  delay(1000);
}

/*
// Returns double fahrenheit from double celsius.
double fahrenheit(double celsius) {
  return 1.8 * celsius + 32;
}
*/

// Returns int fahrenheit from int celsius.
int fahrenheit(int celsius) {
  return (celsius * 18 + 5) / 10 + 32;
}

/*
// Returns double kelvin from double celsius.
double kelvin(double celsius) {
  return celsius + 273.15;
}

// dewPoint function NOAA
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/geography/weather_station/Geog_site/about.htm
double dewPoint(double celsius, double humidity) {
  // (1) Saturation Vapor Pressure = ESGG(T)
  double RATIO = 373.15 / (273.15 + celsius);
  double RHS = -7.90298 * (RATIO - 1);
  RHS += 5.02808 * log10(RATIO);
  RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
  RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
  RHS += log10(1013.246);
  // factor -3 is to adjust units - Vapor Pressure SVP * humidity
  double VP = pow(10, RHS - 3) * humidity;
  // (2) DEWPOINT = F(Vapor Pressure)
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity) {
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}
*/





RX
Code: [Select]

// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
// RX data to Digital I/O pin 11.
// Receive TX data.
// Get local DHT11 data.

#define DEBUG

#include <VirtualWire.h>
// Init VWMsgBuf.
uint8_t VWMsgBuf[VW_MAX_MESSAGE_LEN];
// Init VWMsgStr.
String VWMsgStr;

#include <dht11.h>
// Init DHT11.
dht11 DHT11;
// DHT11 OUT to digital I/O pin.
#define DHT11_PIN 2
// DHT11 Sample Time
const unsigned long DHT11SampMillisMax = 1000;
unsigned long DHT11SampMillis = millis() + DHT11SampMillisMax;

// setup() runs once after reset.
void setup() {
  #ifdef DEBUG
    // Init serial for debugging.
    Serial.begin(9600);
  #endif
  // Init BPS.
  vw_setup(3000);
  // vw_set_ptt_inverted(true);
  // Start the receiver.
  vw_set_rx_pin(2);
  vw_rx_start();      
  // Send setup() message.
  VWMsgStr = "LOCAL: setup()!";
  #ifdef DEBUG
    Serial.println(VWMsgStr);
  #endif
}

// loop() runs continuously after setup().
void loop() {
  // Init Buffer Length
  uint8_t VWBufLen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(VWMsgBuf, &VWBufLen)) {
    // Flash a light to show received good message.
    digitalWrite(13, true);
    // Message with a good checksum received, dump it.
    VWMsgStr = "";
    for (int i = 0; i < VWBufLen; i++) {
      VWMsgStr += char(VWMsgBuf[i]);
    }
    #ifdef DEBUG
      Serial.println(VWMsgStr);
    #endif
    digitalWrite(13, false);
  }

//  // Get Local DHT11 message?
//  if (millis() >= DHT11SampMillis) {
//    //Yes, update DHT11SampMillis
//    DHT11SampMillis = millis() + DHT11SampMillisMax;
//    int rc = DHT11.read(DHT11_PIN);
//    switch (rc) {
//      case DHTLIB_OK:
//        VWMsgStr = "LOCAL: OK. Humi%: " + String(DHT11.humidity);
//        VWMsgStr += "  TempC: " + String(DHT11.temperature);
//        VWMsgStr += "  TempF: " + String(fahrenheit(DHT11.temperature));
//        break;
//      case DHTLIB_ERROR_CHECKSUM:
//        VWMsgStr = "LOCAL: Checksum!";
//        break;
//      case DHTLIB_ERROR_TIMEOUT:
//        VWMsgStr = "LOCAL: Time Out!";
//        break;
//      default:
//        VWMsgStr = "LOCAL: Unknown!";
//        break;
//    }
//    #ifdef DEBUG
//      Serial.println(VWMsgStr);
//    #endif
//  }
}

// Returns int fahrenheit from int celsius.
int fahrenheit(int celsius) {
  return (celsius * 18 + 5) / 10 + 32;
}

/*
// Returns double fahrenheit from double celsius.
double fahrenheit(double celsius) {
  return 1.8 * celsius + 32;
}

// Returns double kelvin from double celsius.
double kelvin(double celsius) {
  return celsius + 273.15;
}

// dewPoint function NOAA
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/geography/weather_station/Geog_site/about.htm
double dewPoint(double celsius, double humidity) {
  // (1) Saturation Vapor Pressure = ESGG(T)
  double RATIO = 373.15 / (273.15 + celsius);
  double RHS = -7.90298 * (RATIO - 1);
  RHS += 5.02808 * log10(RATIO);
  RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
  RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
  RHS += log10(1013.246);
  // factor -3 is to adjust units - Vapor Pressure SVP * humidity
  double VP = pow(10, RHS - 3) * humidity;
  // (2) DEWPOINT = F(Vapor Pressure)
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity) {
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}
*/


gc9n




THe only code that works is this .. and thats whithout the VirtualWire Library,,,
any help will be appreciated!


RX
Code: [Select]

/*
  RF Blink - Receiver sketch
     Written by ScottC 17 Jun 2014
     Arduino IDE version 1.0.5
     Website: http://arduinobasics.blogspot.com
     Receiver: XY-MK-5V
     Description: A simple sketch used to test RF transmission/receiver.          
 ------------------------------------------------------------- */

 #define rfReceivePin A0  //RF Receiver pin = Analog pin 0
 #define ledPin 13        //Onboard LED = digital pin 13

 unsigned int data = 0;   // variable used to store received data
 const unsigned int upperThreshold = 70;  //upper threshold value
 const unsigned int lowerThreshold = 50;  //lower threshold value

 void setup(){
   pinMode(ledPin, OUTPUT);
   Serial.begin(9600);
 }

 void loop(){
   data=analogRead(rfReceivePin);    //listen for data on Analog pin 0
  
    if(data>upperThreshold){
     digitalWrite(ledPin, LOW);   //If a LOW signal is received, turn LED OFF
     Serial.println(data);
   }
  
   if(data<lowerThreshold){
     digitalWrite(ledPin, HIGH);   //If a HIGH signal is received, turn LED ON
     Serial.println(data);
   }
 }




TX
Code: [Select]

/*
  RF Blink - Transmit sketch
     Written by ScottC 17 Jun 2014
     Arduino IDE version 1.0.5
     Website: http://arduinobasics.blogspot.com
     Transmitter: FS1000A/XY-FST
     Description: A simple sketch used to test RF transmission.          
 ------------------------------------------------------------- */

 #define rfTransmitPin 4  //RF Transmitter pin = digital pin 4
 #define ledPin 13        //Onboard LED = digital pin 13

 void setup(){
   pinMode(rfTransmitPin, OUTPUT);    
   pinMode(ledPin, OUTPUT);    
 }

 void loop(){
   for(int i=4000; i>5; i=i-(i/3)){
     digitalWrite(rfTransmitPin, HIGH);     //Transmit a HIGH signal
     digitalWrite(ledPin, HIGH);            //Turn the LED on
     delay(2000);                           //Wait for 1 second
    
     digitalWrite(rfTransmitPin,LOW);      //Transmit a LOW signal
     digitalWrite(ledPin, LOW);            //Turn the LED off
     delay(i);                            //Variable delay
   }
 }


cattledog

Take a step back and run the basic TX and RX sketches that are the VW library examples. One change you will have to make to the Receiver sketch is to set the Serial baud rate to Serial.begin(115200). You could also increase the delay(200) in the transmitter sketch, but without these changes the receiver will not display on the monitor.

If they don't work, try it with a direct connection between crossed TX/RX pins with jumper wires. Connect eh ground in this case, or power both arduinos from usb on the same computer.

You may need antennas If the software works but the radios do not. You must get the basics working before your sketch.

rossodisera


cattledog

I do not know if these modules are compatible with the Due. First, there is the issue of the 3.3v and second, whether or not the key libraries(VirtualWire or RadioHead) work with the Due.

I would ask your question in the forum section dedicated to the Due.

http://forum.arduino.cc/index.php/board,87.0.html


jpl-pfungst

hello,

I am using your code an see that the receptor receiving a lot of data. What shoud I expect when the transmitter is on?

raulm21

THe only code that works is this .. and thats whithout the VirtualWire Library,,,
any help will be appreciated!


RX
Code: [Select]

/*
  RF Blink - Receiver sketch
     Written by ScottC 17 Jun 2014
     Arduino IDE version 1.0.5
     Website: http://arduinobasics.blogspot.com
     Receiver: XY-MK-5V
     Description: A simple sketch used to test RF transmission/receiver.         
 ------------------------------------------------------------- */

 #define rfReceivePin A0  //RF Receiver pin = Analog pin 0
 #define ledPin 13        //Onboard LED = digital pin 13

 unsigned int data = 0;   // variable used to store received data
 const unsigned int upperThreshold = 70;  //upper threshold value
 const unsigned int lowerThreshold = 50;  //lower threshold value

 void setup(){
   pinMode(ledPin, OUTPUT);
   Serial.begin(9600);
 }

 void loop(){
   data=analogRead(rfReceivePin);    //listen for data on Analog pin 0
   
    if(data>upperThreshold){
     digitalWrite(ledPin, LOW);   //If a LOW signal is received, turn LED OFF
     Serial.println(data);
   }
   
   if(data<lowerThreshold){
     digitalWrite(ledPin, HIGH);   //If a HIGH signal is received, turn LED ON
     Serial.println(data);
   }
 }




TX
Code: [Select]

/*
  RF Blink - Transmit sketch
     Written by ScottC 17 Jun 2014
     Arduino IDE version 1.0.5
     Website: http://arduinobasics.blogspot.com
     Transmitter: FS1000A/XY-FST
     Description: A simple sketch used to test RF transmission.         
 ------------------------------------------------------------- */

 #define rfTransmitPin 4  //RF Transmitter pin = digital pin 4
 #define ledPin 13        //Onboard LED = digital pin 13

 void setup(){
   pinMode(rfTransmitPin, OUTPUT);     
   pinMode(ledPin, OUTPUT);   
 }

 void loop(){
   for(int i=4000; i>5; i=i-(i/3)){
     digitalWrite(rfTransmitPin, HIGH);     //Transmit a HIGH signal
     digitalWrite(ledPin, HIGH);            //Turn the LED on
     delay(2000);                           //Wait for 1 second
     
     digitalWrite(rfTransmitPin,LOW);      //Transmit a LOW signal
     digitalWrite(ledPin, LOW);            //Turn the LED off
     delay(i);                            //Variable delay
   }
 }



Hello!
I'm having the same problem. Did you solved it?

My Tx: FS1000A
My Rx: RF-5V

Looks like yours

Thank you in advance.

Go Up