LOGIN
Narendran Ashok
Engineer (Project Leader)
 · ChennaiIndia
Edit
Delete
Share
Report
SHOW & TELL

I made a small assembly with two Arduino1 and Arduino2. Arduino1 has a Bluetooh module and a TX module to it.

Arduino2 has a rx module to it and serially displays the data transmitted from Arduino1.

Code for Arduino 1

~span~class~_1bcRJhiNTH8jh88VODldlE~#include~span~ <VirtualWire.h>

const int led_pin = 13;
const int transmit_pin = 12;
void setup() {
   vw_set_tx_pin(transmit_pin);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);   // Bits per sec
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
if((Serial.available()>0))
{
  int a=Serial.read();
  
  Serial.println(a);
   digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  
  vw_send((uint8_t *)a, 2);
  vw_wait_tx(); // Wait until the whole message is gone
  
  digitalWrite(led_pin, LOW);
  delay(1000);
}
}


code for Arduino2

~span~class~_1bcRJhiNTH8jh88VODldlE~#include~span~ <VirtualWire.h>

const int led_pin = 13;
const int receive_pin = 11;

void setup()
{
    delay(1000);
    Serial.begin(9600);  // Debugging only
    Serial.println("setup");
    pinMode(led_pin,OUTPUT);
    vw_set_rx_pin(receive_pin);
    vw_setup(2000);  // Bits per sec
    vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      int i;
      digitalWrite(led_pin, HIGH); // Flash a light to show received good message
       Serial.print("receiving : ");
       int a=buf[i];
         Serial.println(a);
       //Serial.println();
       }
        digitalWrite(led_pin, LOW);
    }

output

when i send 0 from my android mobile to Arduino1 i receive 0 in serial monitor of Arduino2.
rest which ever character i send i receive only 0 as output

1 like 
Like
Share
Load 15 previous comments
Anas Dalintakam
Electronics engineer,DIY thinkerer,arduino/raspberry pi/particle enthusiast,IoT researcher
 · KozhikodeIndia
Edit
Delete
Share
Report

if array is working perfect use array format commands

1 like 
Narendran Ashok
Engineer (Project Leader)
 · ChennaiIndia
Edit
Delete
Share
Report

yes brother. But i am trying to break my head why array works and why not a normal variable?

0 like 
Anas Dalintakam
Electronics engineer,DIY thinkerer,arduino/raspberry pi/particle enthusiast,IoT researcher
 · KozhikodeIndia
Edit
Delete
Share
Report

Then you have to check each data format and try sending each format from arduino 1 to arduino 2 you can try sending all formats in single code

1 like 
Narendran Ashok
Engineer (Project Leader)
 · ChennaiIndia
Edit
Delete
Share
Report

Yes brother lemme try …!! 😄

0 like 
Abhi Verma
Electronics Engineer
 · GhaziabadIndia
Edit
Delete
Share
Report

there is a issue with your data format. let me explain that…
when you send anything from your mobile, it’s encoded to ASCII. i.e. 0 will be 48 (ASCII representation to 0). so you will receive 48 on your arduino1. then you transmit the same data to arduino2 , you have got 48 there also. now when you are using the command Serial.println(a). your a holds 48 in it. while print function only prints characters, you are sending the integer, print command will only take a single char, here you have passed two (4 & 8). the result will be garbage. instead of print, use Serial.write(a). this command will send 48 to terminal and your terminal will automatically convert that to ASCII i.e. 0.
Try it and tell me if that works.

1 like 
Narendran Ashok
Engineer (Project Leader)
 · ChennaiIndia
Edit
Delete
Share
Report

Actually i have tried that too brother… No problem… today after myself making the workout lets split up the discussion and move the project ahead.

0 like 
Leave a reply...
DISCOVER
CHAT
ALERTS
-2
DISCUSSIONS
-1
FEED