Trying to transmit flex sensor via rf module , but unable to receive , the rx pin in the Uno is not glowing whereas tx led in mega is glowing , so can any one please help with the code .
here's the tx code
int ledPin = 13;
int flexSensorPin = 0;
int val1 = 0;
int rx =0;
int tx =1;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(rx, INPUT);
pinMode(tx, OUTPUT);
Serial.begin(4800);
}
void loop()
{
val1 = analogRead(flexSensorPin);
val1 = map(val1, 150,400,100,0);
delay(250);
Serial.println(val1);
}
successfully seeing the values in serial monitor with tx led on .
here's the rx code
#include <SoftwareSerial.h>
SoftwareSerial RFSerial(2, 3); //'virtual' rx pin, 'virtual' tx pin
void setup()
{
Serial.begin(4800);
RFSerial.begin(4800);
}
void loop() // run over and over again
{
if (RFSerial.available()) {
Serial.print((char)RFSerial.read());
}
}
have even tried with various codes at receiver side such as
/*
SimpleReceive
This sketch displays text strings received using VirtualWire
Connect the Receiver data pin to Arduino pin 11
*/
#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
void setup()
{
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}
}
the above code is for the tx code
/*
SimpleSend
This sketch transmits a short text message using the VirtualWire library
connect the Transmitter data pin to Arduino pin 12
*/
#include <VirtualWire.h>
int flexSensorPin = A0;
char flex[8];
void setup()
{
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
Serial.begin(9600);
}
void loop()
{
int flexSensorReading = analogRead(flexSensorPin);
Serial.println(flexSensorReading);
//In my tests I was getting a reading on the arduino between 512, and 614.
//Using map(), you can convert that to a larger range like 0-100.
int flex0to100 = map(flexSensorReading, 150,400,100,0);
Serial.println(flex0to100);
itoa(flex0to100,flex,20);
delay(250); //just here to slow down the output for easier reading
}
void send (int flex0to100)
{
vw_send((uint8_t *)flex, strlen(flex));
vw_wait_tx(); // Wait until the whole message is gone
}