How to send sensor values wirelessly

i know how to send messages to another arduino but im not sure how to send sensor values here is code to transmit the word hello 

If you could show me an example code it would be great.

// transmitter.pde

//

// Simple example of how to use VirtualWire to transmit messages

// Implements a simplex (one-way) transmitter with an TX-C1 module

//

// See VirtualWire.h for detailed API docs

// Author: Mike McCauley ([email protected])

// Copyright (C) 2008 Mike McCauley

// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

 

#include <VirtualWire.h>

 

const int led_pin = 11;

const int transmit_pin =  3;

const int receive_pin = 49;

const int transmit_en_pin = 3;

int sensorPin = A0;

int sensorValue = 0;

void setup()

{

  // Initialise the IO and ISR

  vw_set_tx_pin(transmit_pin);

  vw_set_rx_pin(receive_pin);

  vw_set_ptt_pin(transmit_en_pin);

  vw_set_ptt_inverted(true); // Required for DR3100

  vw_setup(2000); // Bits per sec

}

 

byte count = 1;

 

void loop()

   sensorValue = analogRead(sensorPin);   

  char msg[7] = {'h','e','l','l','o',' ','#'};

  msg[6] = count;

  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting

  vw_send((uint8_t *)msg,7);

  vw_wait_tx(); // Wait until the whole message is gone

  digitalWrite(led_pin, LOW);

  delay(1000);

  count = count + 1;

}

and here is the recieve code for it

// receiver.pde

//

// Simple example of how to use VirtualWire to receive messages

// Implements a simplex (one-way) receiver with an Rx-B1 module

//

// See VirtualWire.h for detailed API docs

// Author: Mike McCauley ([email protected])

// Copyright (C) 2008 Mike McCauley

// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

 

#include <VirtualWire.h>

 

const int led_pin = 6;

const int transmit_pin = 12;

const int receive_pin = 49;

const int transmit_en_pin = 3;

 

void setup()

{

    delay(1000);

    Serial.begin(9600); // Debugging only

    Serial.println("setup");

 

    // Initialise the IO and ISR

    vw_set_tx_pin(transmit_pin);

    vw_set_rx_pin(receive_pin);

    vw_set_ptt_pin(transmit_en_pin);

    vw_set_ptt_inverted(true); // Required for DR3100

    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

// Message with a good checksum received, print it.

Serial.print("Got: ");

for (i = 0; i < buflen; i++)

{

   Serial.print(buf[i], BYTE);

   Serial.print(' ');

}

Serial.println();

        digitalWrite(led_pin, LOW);

    }

}

I have questions about your code.

In the transmit example, your transmit_pin = 3. In your receive example, your transmit_pin = 12. Why do you you have two different pins?

In your receive code, you have a pair of variables that seem to get assigned to “constants”, the variable names are all caps. Where do those variables come from?

    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

**I just copied the code **

I just copied the code so i dont kno much about it and I must of forgot to change that pin. I dont really know what those variables do.

If you could explain what the code is doing it would be great because the comments arnt very good.

Yup

Tx:

 

void setup()

{

  Serial.begin(9600);

}

 

void loop()

{

  Serial.print(“A”);

  delay(1000);

}

 

 

Rx:

 

char rxData;

 

void setup()

{

  Serial.begin(9600);

}

 

void loop()

{

  if (Serial.available()>0)

  {

    rxData=Serial.read();

    if(rxData==‘A’)

    {

      //do something

    }

    Serial.flush();

  }

}

 

i think those variables are from the library birdmun

i think those variables are from the library birdmun.  that code doesnt seem to help much do you have any other ideas chris

**Use the built-in functions itoa and atoi **

Sending a integer is just a tiny bit different than sending a character. When sending you must transform the integer to a character first. When receiving transform the character back to an integer.

Use the built-in functions itoa and atoi .

Look here for further information.

Specifically…

Okey dokey,

I have posted links to 4 or more tutorials, as well as the code I posted here. The code I posted here I wrote specifically to be the most simple example of serial data transfer that could be written. 

So far, all the responses have been “that tutorial didn’t help” or now, “this code does not help”. Could you tell us specifically what you don’t understand, or what is not working.

Take for instance, the super-simple code above:  Did it not compile? Did it not work? It worked but did not do what you want it to do? It worked but you were not able to expand it to what you needed? It worked/didn’t work but you don’t understand the commands used? 

Do you need help learning about constants and variables?

Do you need help dealing with chars and ints etc?

etc  etc etc  etc

 

 

All these questions are relevant

All these questions are relevant, Nathanielm.

The more precise your problem description is the better our answers.
The less precise the more options you get on different levels of abstraction… and that can leave you more confused in the end as you were in the beginning when you asked for help.

Can you work with all our responses?

**I understand now **

Thanks that has been really helpful thanks everyone for your help I really apreciate it

Ok great!

I think I can sum this up a bit here…

If indeed you have it now, great! If you need more help or clarification in the future, great. However, I must admit, I get the feeling like you were/are looking for “off-the-shelf, ready-to-run and configured-to-your-set-up code” that you can just copy/paste and zap into your robot and you are not very interested in learning A) how it works or B) how to modify any of the many examples I gave you into what you are doing. 

–Just to save you some time here (and possibly a third post asking the same questions again), you are not going to find this code anywhere and no one is going to write if for you. There is no way around this, you are going to have to read the reference pages, forums, tutorials and wiki’s and just figure this out. And, as nils said, you gotta be much more specific in your questions. The more specific you can be (in terms of describing exactly confuses you) will allow us to explain things much better.

Dig into those turorials I sent you, my friend. Write test code, keep it simple. Experiment. You will figure it out, I’m sure.

Good luck

 

hey i just found this post

hey i just found this post here ! well interesting one !!

i guess it’s the same as potentiometer because in this one he is using a light sensor

so i was reading the codes and this is what confuses me :

 

void loop()

   sensorValue = analogRead(sensorPin);   

  char msg[7] = {‘h’,‘e’,‘l’,‘l’,‘o’,’ ‘,’#’};

  msg[6] = count;

  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting

  vw_send((uint8_t *)msg,7);

  vw_wait_tx(); // Wait until the whole message is gone

  digitalWrite(led_pin, LOW);

  delay(1000);

  count = count + 1;

}

 

how did he send the variable of the sensor and why did he made a count variable ? the potentiometer values will go from 0 to 255 so how it is converted and send ?!! by which line of codes ?

In the code snippet you posted

nothing is done with the variable sensorValue. That data is not being sent anywhere, based on the code you offered us. The only value that is being sent is the count variable. I hope it was declared as a byte variable at the beginning. Otherwise the program will probably puke at some point.

not it’s not my code !! it’s

not it’s not my code !! it’s the code of nathanielm the guy who created this post !! i was trying to figure out if we want to send data from potentiometer how do we do it ? :frowning: i am trying to figure it out, by reading posts and searching on google on forums but still didn’t get any answer !!

DOH!

It’s great when I don’t pay attention. However, to answer your question, I believe that mapping the sensorValue to a number between 0 and 255 then placing it at msg[6] would manage to send a sensor value.

exactly how to place numbers

exactly how to place numbers from 0 to 255 in an array ?!!

Firashelou

Please go back to your original post, I have given you a lengthy response to the questions about your project.