RF433 problem with arduino

Hi guys, i have been playing with the rf433 module , i have tried to sent a simple message from my transmitter to the receiver, however i found out that the message can only be sent when the distance between both transmitter is near(about 15cm). Is there anything wrong with my code?


// 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 $

#include <VirtualWire.h>

const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;
char msg = ‘188’;
//char msg[7] = {‘D’,‘a’,‘n’,‘g’,‘e’,‘r’,’#’};
unsigned int correctCount=0;

void setup()
{
delay(1000);
Serial.begin(9600); // Debugging only
//Serial.println(“setup”);

// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec

vw_rx_start(); // Start the receiver PLL running

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)) // Non-blocking
{
int i;

digitalWrite(led_pin, HIGH); // Flash a light to show received good message
// Message with a good checksum received, dump it.
//Serial.print("Got: ");

//for (i = 0; i < buflen; i++)
//{
// Serial.print((char)buf*);*

  • //Serial.print(’ ');*
  • //}*
  • for(i=0; i<buflen; i++){*
    if((char)buf_==msg){//){
    * correctCount++;
    }
    }
    if(correctCount>=3){
    Serial.write(220);
    while(1){_
    digitalWrite(led_pin,!digitalRead(led_pin));
    _ delay(250);
    }
    }
    correctCount=0;
    //Serial.println();_
    //digitalWrite(led_pin, LOW);
    _ }_
    }*</em></em> <em>_*```*_</em> <em><em>**</em></em> <em>_*```*_</em> <em>_*#include <VirtualWire.h>*_</em> <em><em>*const int led_pin = 13;*</em></em> <em><em>*const int transmit_pin = 12;*</em></em> <em><em>*const int receive_pin = 2;*</em></em> <em><em>*const int transmit_en_pin = 3;*</em></em> <em>_*const int danger = 8;*_</em> <em>_*const int buzzer = 10;*_</em> <em>_*boolean dangerFlag=false, injuredFlag=false;*_</em> <em>_*int counter=0;*_</em> <em>_*void setup(){*_</em> <em>_* // Initialise the IO and ISR*_</em> <em><em>* vw_set_tx_pin(transmit_pin);*</em></em> <em><em>* vw_set_rx_pin(receive_pin);*</em></em> <em><em>* vw_set_ptt_pin(transmit_en_pin);*</em></em> <em><em>* vw_set_ptt_inverted(true); // Required for DR3100*</em></em> <em><em>* vw_setup(2000); // Bits per sec*</em></em> <em><em>* pinMode(led_pin, OUTPUT);*</em></em> <em>_* pinMode(buzzer, OUTPUT);*_</em> <em>_* Serial.begin(9600);*_</em> <em>_*}*_</em> <em>_*byte count = 1;*_</em> <em>_*//char msg[7] = {'D','a','n','g','e','r','#'};*_</em> <em>_*char msg[3]={'188','188','188'};//,'188','188','188','188'};*_</em> <em>_*void loop(){*_</em> <em>_* if(digitalRead(danger)==HIGH && dangerFlag==false ){//&& firstRound==true)*_</em> <em><em>* digitalWrite(led_pin, HIGH);*</em></em> <em>_* dangerFlag=true;*_</em> <em>_* }*_</em> <em>_* if(digitalRead(danger)==HIGH && dangerFlag==true && counter<32){*_</em> <em>_* counter++;*_</em> <em>_* delay(250);*_</em> <em><em>* digitalWrite(led_pin, !digitalRead(led_pin));*</em></em> <em>_* }*_</em> <em>_* if(digitalRead(danger)==LOW && dangerFlag==true && counter<32){*_</em> <em>_* dangerFlag=false;*_</em> <em><em>* digitalWrite(led_pin, LOW);*</em></em> <em>_* counter=0;*_</em> <em>_* }*_</em> <em>_* if(counter>=32){*_</em> <em>_* injuredFlag=true;*_</em> <em>_* }*_</em> <em>_* if(injuredFlag==true){*_</em> <em>_* while(1){*_</em> <em><em>* digitalWrite(led_pin, !digitalRead(led_pin));*</em></em> <em>_* digitalWrite(buzzer, !digitalRead(buzzer));*_</em> <em><em><em> vw_send((uint8_t *)msg, 3);</em></em></em> <em><em>* vw_wait_tx(); // Wait until the whole message is gone*</em></em> <em>_* delay(250);*_</em> <em>_* }*_</em> <em>_* }*_</em> <em><em>*}*

I recall someone else posting similar issue with rang being very short. You could try searching the forum, I think it was Project Advice.

Also, you have posted to the wrong section this is not a micro controller question.

I will ask the moderate to move it to a more suitable location

Did you solder the right length of wire to the receiver, as an antenna?

You don't actually need to attach an antenna to get them to work... You do to get any range.

Have a look at this: if ( (char) buf == msg ) the 'buf' is the name of an array, and 'buf' is therefor a pointer. Test the first character like this: if ( buf [ 0 ] == msg )

There are a number of things that could go wrong with the cheap 433MHz RF modules. The receiver is tuned with a coil. I don't use those anymore. My main receiver is a HopeRF 433MHz receiver of -108dB sensitivity. I have not done a range check yet, but so far everything is received. I bought a transmitter from Ebay that had a missing component. I compared it with other transmitters, but they had the component, so I quickly tossed it away. You need an antenna, preferrably 17cm, but any piece of wire will do.