Is there any way through code to estimate signal quality by sending a certain amount of bytes of data and showing percentage received? That would be pretty nice.
--
You received this message because you are subscribed to the Google Groups "virtualwire" group.
To unsubscribe from this group and stop receiving emails from it, send an email to virtualwire...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You might try experimenting with antenna length and input voltage. Higher input voltage will generally result in higher transmit power for these transmitters. Antenna design is more complicated, but I've successfully used my TX/RX pair with 5V in and no antenna at about 20cm distance, more than that becomes unreliable (but I do get some data in that configuration out to about a meter).
73,
~James
Do you know if I can low the strength of the rf 434 MHz signal of the transmitter in order to be received only if the receiver is in a 1 or 2 meters radius ?
If you have the cheap model, decrease the supply voltage. 12 volts gives maximum transmit power. Outside of that you really need to get into some antenna theory. That can get quite complicated. For testing I would suggest using a three inch 50 ohm omni directional antenna over a three inch ground plane. Then only supply the transmitter with three volts. Test the distance and increase or decrease the voltage to achieve the desired operating range.
I am asking about the strength of the signal because I want to install an arduino with a receiver in my car and tag my keys or my wallet with small rf transmitters that they will act as a beacon. So when I enter the car arduino will inform if all the tagged object are inside the car, that's why I want the transmitters to have a small transmitting radius 1 or 2 meters in order not to be reachable from the receiver if they are out of the car. I have searched for RFID but besides they are expensive they also have a small radius , some cm only.
void loop() {count++;delay(1);if (count == 2000) {vw_send(count); //Send all the data in "count"vw_wait_tx(); // Wait until the whole message is gone}
I was thinking more along the lines of:
unsigned int count;
void setup() {
count = 0;
// vw setup
// any other setup
}
void loop() {
count++;
mySend(count);
delay(10);
}
void mySend(unsigned int sendValue) {
uint8_t buffer[2];
buffer[0] = highByte(sendValue);
buffer[1] = lowByte(sendValue);
vw_send(buffer, 2);
vw_wait_tx();
}
73,
~James
When you call vw_send, you need to give it an array of characters and a length. An int, like count, is not a character array. Although functions like Serial.print() know how to handle things that aren't characters, vw_send() doesn't. You need to convert the int to a sequence of characters (as in my other email). The second argument, the length, is the number of characters to send. For a numeric value, like the count you're sending here, that length is allays the same: the number of characters you used when you converted the number to a character array. To hold numbers from 0 to 65,536 (the range that can be represented by an unsigned int), you need two characters (= 16 bits = 2 bytes = 2*uint8_t).
Does this make more sense?
Cheers,
~James
Please review my comments and tell me if I understand correctly.
unsigned int count;
void setup() {
count = 0; // Value to store count
// vw setup
// any other setup
}
void loop() {
count++; // Increment the value of count by 1
mySend(count);
delay(10);
}
void mySend(unsigned int sendValue) {
uint8_t buffer[2]; // States that the buffer is storing 2 bytes?
buffer[0] = highByte(sendValue); //Byte # 1 ?
buffer[1] = lowByte(sendValue); //Byte # 2 ?
vw_send(buffer, 2); //Send the 2 bytes in the buffer?
vw_wait_tx();
}
int vw_rx_good = 0;
// RF Transmission container
char vw_rx_goodMsg[4];
// Trying to use 5 instead to fit trailing null char
// go back to 4 if this does not work.
//char Sensor1CharMsg[5];
void setup() {
Serial.begin(9600);
Serial.print("RX Start");
// Bits per sec.
vw_setup(2000);
// Start the receiver PLL running
vw_rx_start();
} // END void setup
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Non-blocking
if (vw_get_message(buf, &buflen))
{
int i;
// // Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
// // Fill vw_rx_goodMsg Char array with corresponding
// // chars from buffer.
vw_rx_goodMsg[i] = char(buf[i]);
}
//
// // Null terminate the char array
// // This needs to be done otherwise problems will occur
// // when the incoming messages has less digits than the
// // one before.
vw_rx_goodMsg[buflen] = '\0';
//
// // Store value received to vw_rx_good
vw_rx_good = atoi(vw_rx_goodMsg);
//
// DEBUG
Serial.println(vw_rx_good);
}
#include <OneWire.h> //This temperature sensor requires a 4.7k Ohm resistor across its pins 2 and three!!!!
#include <DallasTemperature.h>
#include <Wire.h>
#include <VirtualWire.h>
int ledPin = 13;//Set up the TX indicator pin 13 as LedPin
int vw_rx_good;
int Sensor1Data;//initialize the use of the variable Sensor1Data
//int sensorValue = 0; // variable to store the value coming from the sensor If using analog sensor
float currentTemp = 0;//to store decimal value coming from the temp sensor
// RF Transmission container
//char Sensor1CharMsg[4];
// Trying to use 5 instead to fit trailing null char
// go back to 4 if this does not work.
char Sensor1CharMsg[5];
//This temperature sensor requires a 4.7k Ohm resistor across its pins 2 and three!!!! Thats the middle pin and the GND pin
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = { 0x28, 0xFA, 0xA5, 0x6B, 0x04, 0x00, 0x00, 0xD8 };
// DeviceAddress outsideThermometer = { 0x28, 0x20, 0x04, 0xA8, 0x02, 0x00, 0x00, 0x4D };
void setup()
{
pinMode(ledPin, OUTPUT);//Set the ledPin as an output
Serial.begin(9600);//initialize serial communication
Serial.print("TX Start");//Print TX Start in the serial terminal
// VirtualWire
// Initialise the IO and ISR
// Required for DR3100
//vw_set_ptt_inverted(true);
// Bits per sec
vw_setup(2000); //Set VirtualWire communication speed
// Start up the library
sensors.begin();
// set the resolution to 9 bit (good enough?)
sensors.setResolution(insideThermometer, 9);
// sensors.setResolution(outsideThermometer, 9);
}
void loop(void)
{
sensors.requestTemperatures(); //Get temperature from the temp Sensor
float tempC = sensors.getTempC(insideThermometer);
if (tempC == -127.00) {
Serial.write("Error");//Print Error if we read -127
} else {
// lcd.print(tempC);
// lcd.print("/");
Sensor1Data = (DallasTemperature::toFahrenheit(tempC));//Set Sensor1Data as the Celcius to Fahrenheit Conversion
Serial.write(Sensor1Data); //Print the converted temp in the serial terminal
// Integer to ASCII
itoa(Sensor1Data,Sensor1CharMsg,10);
digitalWrite(13, true); // Turn on a light to show transmitting
vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));//Send the data collected
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false); // Turn off a light after transmission
// delay(200);//Wait 200 Milliseconds and then go back to program start
}
}
// include the library code:
#include <avr/sleep.h>
#include "Wire.h"
#include "LiquidCrystal.h"
#include <VirtualWire.h>
int Sensor1Data;
int vw_rx_good;
// RF Transmission container
char Sensor1CharMsg[4];
// Trying to use 5 instead to fit trailing null char
// go back to 4 if this does not work.
//char Sensor1CharMsg[5];
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
// VirtualWire
// Initialise the IO and ISR
// Required for DR3100
//vw_set_ptt_inverted(true);
// Bits per sec
vw_setup(2000);
// Start the receiver PLL running
vw_rx_start();
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setBacklight(HIGH);
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Non-blocking
if (vw_get_message(buf, &buflen))
{
int i;
// Turn on a light to show received good message
digitalWrite(13, true);
// lcd.print("Remote Temp: ");
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
// Fill Sensor1CharMsg Char array with corresponding
// chars from buffer.
Sensor1CharMsg[i] = char(buf[i]);
}
// Null terminate the char array
// This needs to be done otherwise problems will occur
// when the incoming messages has less digits than the
// one before.
Sensor1CharMsg[buflen] = '\0';
// Convert Sensor1CharMsg Char array to integer
// Sensor1Data = atoi(Sensor1CharMsg);
Sensor1Data = atoi(Sensor1CharMsg);
// DEBUG
lcd.setCursor(0, 0);
lcd.print(vw_rx_good);
delay(10);
}
}