Wireless Communication using Arduino UNO

Hello!
We are working on ARDUINO UNO. Our current goal is to establish a Wireless Communication Module for Trans-reception of Analog signal for a frequency range of 1Hz - 1000Hz.

We are using a RF transmitter and Receiver, 433Mhz Operating frequency.

Two Arduino UNO. One for the transmitter and One for Receiver.

The Transmitter Code:

#include <PCF8591.h>
#include <Wire.h>
#include <VirtualWire.h>
byte numSamples;
int i;
const int tx=12;
char cad[100];

void setup()
{
 Serial.begin(115200);
 vw_set_tx_pin(tx);
 vw_setup(2000);
 ADCSRA = 0;             // clear ADCSRA register
 ADCSRB = 0;             // clear ADCSRB register
 ADMUX |= (0 & 0x07);    // set A0 analog input pin
 ADMUX |= (1 << REFS0);  // set reference voltage
 ADMUX |= (1 << ADLAR);  // left align ADC value to 8 bits from ADCH register

// sampling rate is [ADC clock] / [prescaler] / [conversion clock cycles]
// for Arduino Uno ADC clock is 16 MHz and a conversion takes 13 clock cycles
ADCSRA |= (1 << ADPS2) | (1 << ADPS0);    // 32 prescaler for 38.5 KHz
//ADCSRA |= (1 << ADPS2);                     // 16 prescaler for 76.9 KHz
//ADCSRA |= (1 << ADPS1) | (1 << ADPS0);    // 8 prescaler for 153.8 KHz

//ADCSRA |= ( 1 << ADPS1 );

//ADCSRA |=  (1 << ADPS0);

 ADCSRA |= (1 << ADATE); // enable auto trigger
 ADCSRA |= (1 << ADIE);  // enable interrupts when measurement complete
 ADCSRA |= (1 << ADEN);  // enable ADC
 ADCSRA |= (1 << ADSC);  // start ADC measurements

 
}


ISR(ADC_vect)
{

}
 
void loop()
{
byte x = ADCH;  // read 8 bit value from ADC
numSamples=x;
cad[i]=numSamples;
Serial.println(cad[i]);
vw_send((byte*)cad,strlen(cad));
vw_wait_tx();

}

“AnalogRead” had few issues, we tried reading the input value directly from the ADC and tried to set a prescaler to increase the current sampling rate.

RECEIVER CODE:

#include <Wire.h>
#include <VirtualWire.h>
char cad[100];
const int rp = 11;
int i,j;


#define PCF8591 (0x90 >> 1) // I2C bus address
void setup()
{
Wire.begin();
 vw_set_tx_pin(rp);
 vw_setup(2000);
 vw_rx_start();
 Serial.begin(9600);
 Serial.println("CLEARDATA");
 Serial.println("LABEL,Timestamp,voltage,..");
 Serial.println("RESETTIMER");
}
void loop()
{

byte buf[VW_MAX_MESSAGE_LEN];
 
 byte buflen = VW_MAX_MESSAGE_LEN;
 

 if (vw_get_message(buf, &buflen))
   for (i = 0; i < buflen; i++)
   {
     dacoutput(buf[i]); 

    Serial.print("DATA,TIME,");
    Serial.println(buf[i]);
       
    }
}

int dacoutput(int i)
{
   Wire.beginTransmission(PCF8591); // wake up PCF8591
   Wire.write(0x40); // control byte - turn on DAC (binary 1000000)
   Wire.write(i); // value to send to DAC
   Wire.endTransmission(); // end tranmission
return;
}

The output of Arduino is Digital (PWM OUTPUT). We have interfaced a DAC PCF8591 to get the original signal back. And store the data received in excel document for easy representation and for timestamp using PLX DAQ.

PROBLEM:
We aren’t able to receive all the frequencies. Eg: 20, 40, 60, 80Hz, 187,210,230,250,270Hz, 500Hz are properly getting transmitted and reconstructed by the DAC. But the demodulated frequency is not greater than 5Hz. Other frequencies are distorted to a very large extent.

Can someone Help us with This? This is a very important part of the Project. Do suggest improvements. That would help us a lot.

Regards.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

I am not personally familiar with 433MHz wireless modules.

…R

You have the transmitter configured for 2000 bits per second. (vw_setup(2000) ; ) Thus the fastest you could hope to transfer data is 2000 bps / 8 bits per sample = 250 samples/second. In reality there is significant overhead imposed by VirtualWire (much of it necessary) so I'd expect something like a tenth of that. 2000 bps is close to the limit of the cheap 433 MHz transmitter/receiver products so they really don't address your system requirements.

You need a higher performance data link.

The 433 MHz transmitter may be busy only for 10% of the time by law in my country. That is another factor 10 reduction.

I have never tried this: https://github.com/nRF24/RF24Audio, but it seems like a lot of fun.

Robin2:
To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

I am not personally familiar with 433MHz wireless modules.

…R

Thank you Sir! I have modified the post accordingly.

MrMark:
You have the transmitter configured for 2000 bits per second. (vw_setup(2000) ; ) Thus the fastest you could hope to transfer data is 2000 bps / 8 bits per sample = 250 samples/second. In reality there is significant overhead imposed by VirtualWire (much of it necessary) so I'd expect something like a tenth of that. 2000 bps is close to the limit of the cheap 433 MHz transmitter/receiver products so they really don't address your system requirements.

You need a higher performance data link.

Yes Sir. That was one of the issues. We tried increasing the bits per second to 4000. Didn't give any positive difference. I will check for better performing Trans-Reception modules. Is ZigBee a good option?

I have not used I2C so I won't comment on that part.

However your transmitter code has an empty ISR so goodness knows what values are being sent.

...R

Koepel:
The 433 MHz transmitter may be busy only for 10% of the time by law in my country. That is another factor 10 reduction.

I have never tried this: https://github.com/nRF24/RF24Audio, but it seems like a lot of fun.

Thank you Sir. I will go through the Github Link. I will let you know once I get some improvement over this. The 433Mhz Transmitter and Receiver has a very low kbps speed. May be one of the issue. I will let you know shortly.

Thank You.

Robin2:
I have not used I2C so I won't comment on that part.

However your transmitter code has an empty ISR so goodness knows what values are being sent.

...R

This entire complexity in the code was to avoid AnalogRead function. I will upload another code where we tried to Read the values by directly addressing the control register of ADC.

Once I remove the ISR, the values aren't read.

Duplicate posts, same terrible mistakes in the code.

My recommendation in that post was to start over with the working examples provided by VirtualWire.

Keep in mind that VirtualWire can send only about 200 bytes/second, which limits the audio frequency response of your project to at best 100 Hz.

Hema_19:
This entire complexity in the code was to avoid AnalogRead function. I will upload another code where we tried to Read the values by directly addressing the control register of ADC.

Once I remove the ISR, the values aren't read.

I was not suggesting that you eliminate the ISR. Just put some useful code into it.

The ADC register should read in the ISR and saved to a variable that can be accessed from your other code. Also set a flag variable so your other code knows that a new value has been produced.

...R