I am working on a project where I am sending data via the Arduino Mhz 433 transmitter and receiver. The data code is coming from a FSR. How ever the code for the data I am receiving is in a Long and the code for the MHZ 433 is in a char.
This is my code for the transmitter plus the FSR
`
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver;
int fsrPin = 0; // the FSR and 10k resistor are connected to A0
int fsrReading; // analog reading from the FSR resistor divider
int fsrVoltage; // analog reading converted to voltage
unsigned long fsrResistance; // voltage converted to resistance
unsigned long fsrConductance;
long fsrForce = 0; // resistance converted to force
void setup(void) {
#ifdef RH_HAVE_SERIAL
Serial.begin(9600);
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
}
void loop(void) {
fsrReading = analogRead(fsrPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);
// analog voltage reading ranges from about 0 to 1023 which maps to 0V to 5V (= 5000mV)
fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
Serial.print("Voltage reading in mV = ");
Serial.println(fsrVoltage);
if (fsrVoltage == 0) {
Serial.println("No pressure");
} else {
// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V
fsrResistance = 5000 - fsrVoltage; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance *= 10000; // 10k resistor
fsrResistance /= fsrVoltage;
Serial.print("FSR resistance in ohms = ");
Serial.println(fsrResistance);
fsrConductance = 1000000; // we measure in micromhos so
fsrConductance /= fsrResistance;
Serial.print("Conductance in microMhos: ");
Serial.println(fsrConductance);
// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000) {
fsrForce = fsrConductance / 80;
Serial.print("Force in Newtons: ");
Serial.println(fsrForce);
} else {
fsrForce = fsrConductance - 1000;
fsrForce /= 30;
Serial.print("Force in Newtons: ");
Serial.println(fsrForce);
}
}
Serial.println("--------------------");
delay(1000);
const char *msg = "Hello World!";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000);
}
This is the reciever code:
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
}
}
Running this code I do get "hello world" but have been having issues gettiing the data from the FSR to send over the Mhz433