I have been working on a project. where i have to measure change in resistance with the help of another reference (should this reference resistor value be small??) which is basically a voltage divider. The voltage drop(Vout) is given to inverting input of an opamp(ADA4522-1ARZ, which is renamed). The opamp is used as a buffer(voltage follower). There is another voltage divider(R1, R2). which is used to give reduced voltage to the teensy(3.2). The analog pin reads the value through the second voltage divider.(connections in detail are given in the schematic). I want to read the unknown resistance value in the serial monitor and transmit at the same time and receive with help of nRF24L01 modules. I'm not getting the desired output at transmitter end(wrong values) and also at the receiver end. The receiver end is just blank not receiving anything. Any suggestions and help would be appreciated.
//the transmitter code//
Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
float Rg = 0;
const float Vin = 24.0;
float Vout = 0.0;
const float Rref = 16000;
RF24 radio(7, 8); // CE, CSN
const byte rxAddr[6] = "00001";
#define NUM_CHANNELS 1
typedef struct {
long int td; //4 bytes
int data[ NUM_CHANNELS ]; //2 x 6 = 12 bytes
} SRF24_Data;
SRF24_Data RData;
SRF24_Data* pSRData = &RData;
//int receiveNodeData = {1,1};
//#define Vout
//#define Rg
//#define Rref //470Kohm
//#define Vin
void setup()
{
Serial.begin(9600);
Serial.println("[*][*][*] Beginning nRF24L01 transmit program[*][*][*]");
radio.begin();
radio.setRetries(15, 15);
radio.enableAckPayload();
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(rxAddr);
radio.setChannel(0x76);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop()
{
Serial.print("Hello World\n");
const char text[32] = "Hello World";
radio.write(&text, sizeof(text));
//currentTime = millis();
pSRData->td = millis();
int ADCREAD = 0;
// analogReadResolution(1);
ADCREAD = analogRead(A0);
//int SensorValue = analogRead(A0);
//float Voltage = SensorValue * (5.0/1023);
float Vout = (Vin * ADCREAD) / 1024;//(ADCREAD; //* 5)/4096;
float Rg = (Rref * (Vin / Vout)- Rref);
pSRData->data[0] = ADCREAD;
//radio.write(pSRData, sizeof(SRF24_Data));
long int t = millis();
radio.write(pSRData, sizeof(SRF24_Data));
Serial.print("R: ");
Serial.println(Rg);
Serial.println(Vout);
Serial.println(ADCREAD);
//Serial.println(Voltage);
delay(100);
Serial.println("Naidu");
// const char text[] = "This is NAIDU";
//radio.write(&text, sizeof(text));
//receiveNodeData();
delay(1000);
}
//***the output-Tx***//
Hello World
R: 31627.91
1.68
344
Naidu
//****The receiver code***//
Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//#define Vout
//#define Rg
//#define Vin
//#define R1
//#define R2
//#define Rref
const int SensorPin = A0;
int SensorValue = 0;
float Vin = 24;
float Vout = 0;
float Rref = 16000;
float Rg = 0;
RF24 radio(7, 8);
const byte rxAddr[6] = "00001";
#define NUM_CHANNELS 1
typedef struct{
long int td;
int data[NUM_CHANNELS];
}
SRF24_Data;
SRF24_Data RData;
SRF24_Data* pSRData = &RData;
void setup()
{
while (!Serial);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, rxAddr);
radio.enableAckPayload();
radio.setChannel(0x76);
radio.startListening();
}
long int lastTd;
void loop()
{
if (radio.available())
{
long int t;
SensorValue = analogRead(SensorPin);
float Vout = (Vin* SensorValue)/1023;
float Rg = (Rref * (Vin / Vout)- Rref);
//Rg = (((Vin*Rref)/Vout)-1);
//Rg = Rref * (1/((Vin/Vout)-1));
radio.read(pSRData, sizeof(SRF24_Data));
//float Vout = (pSRData->data[0]*3.27)/1023;
Serial.print("Hello World");
Serial.print(pSRData->td);
Serial.print("R:");
Serial.println(Rg);
Serial.println(Vout);
delay(1000);
//Serial.print(R);
//char text[] = {0};
//radio.read(&text, sizeof(text));
// Serial.println(text);
}
}