Go Down

Topic: Wireless Communication with more than one sensor signal (Read 386 times) previous topic - next topic



Currently I have managed to use the VirtualWire library to set up communication between to UNO's on 433 MHz modules reading data from an SD card. The next stage is to transmit data from five different sensors. What would be the best way to do this ? Is there a way to merge them into a single string  or would I need to have five different channels ?



What would be the best way to do this ?
Do you need to send the data for each sensor every time? Or, do you want to send the data only when it changes?

Is there a way to merge them into a single string
Of course. sprintf() is one way. There are others.


Hi Paul S,

Thanks for your reply, I need to send the data from the sensor continuously.


I need to send the data from the sensor continuously.
That is not going to happen. Sending serial data, wired or wireless, is, of necessity, a series of discrete events.

Why is it necessary to send the same data over and over?

The switch is pressed.
The switch is pressed.
The switch is pressed.
The switch is pressed.
The switch is pressed.
The switch is pressed.
The switch is pressed.
The switch is pressed.

It makes more sense, to me, to only send data when the state of a pin changes. Or the temperature or the humidity or whatever data it is that you want to send.


Please explain more about you architecture. Is there a sending and receiving UNO, or are they bidirectional?
Do you want to collect data from 5 sensors on one uno and then pass the data to the other? Where does the SD card fit in? What type of sensors and what is the data to be passed? How often do you want to send data?

Collecting the data from all 5 sensors, putting it into a struct (or array if the same type) and transmitting the bytes is probably the most efficient method.  You can certainly send data one sensor at a time, and it can be sent as text strings using as ascii chars or alternatively, as numerical data broken into bytes.


Hi again,

Cattledog, at the moment the SD card is only holding a .txt file with some random data on it and I was using that to transmit from an UNO to another UNO and then using a diff checker to evaluate the accuracy of the transmission by compare the transmitted to a known message. The transmission is one way only. This was only to test type of aerials and environment in which I would be transmitting.

I now plan to transmitt 5 signals from 5 different strain gauges. I have set up amplifiers etc to output between 0 and 5 V so it can be read by the analogue inputs. The process being monitored lasts for about 2 seconds so I would like to take a sample every 0.01 s. (Arduino has a sample rate of 125 kHz ?).

Ideally I would like to monitor all five signals at each point.


I now plan to transmitt 5 signals from 5 different strain gauges.
I'm sure that you mean 5 different VALUES from the 5 different analog pins.


Sorry, yes that's what I meant. Five different voltages will be input to the different Analogue pins which will be converted to 8 bit number using the ADC


What would be the best way to do this ? Is there a way to merge them into a single string  or would I need to have five different channels ?
You could send the data either way depending on your setup. Below is servo control code that is made for transmitting where transmitting bandwith may be limited. In the code for each analog input the analog value is determined, converted to a servo value, a servo identifier is added, and a comma is added as an end of packet marker.  Bottom is serial servo control code made to receive what is being sent and control the servos.

Tx code

Code: [Select]

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor

#include <Servo.h>
Servo myservo1;  //declare servos
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int potpin1 = 0;  //analog input pin A0
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;

int newval1, oldval1;  //pot input values
int newval2, oldval2;
int newval3, oldval3;
int newval4, oldval4;
int newval5, oldval5;

void setup()
  Serial.println("testing multi pot servo"); 

void loop()
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179);
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band
    myservo1.write(newval1); //position the servo
    Serial.print(newval1); //print the new value for testing
    oldval1=newval1; //set the current old value

  newval2 = analogRead(potpin2);
  newval2 = map(newval2, 0, 1023, 0, 179);
  if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){ 

  newval3 = analogRead(potpin3);           
  newval3 = map(newval3, 0, 1023, 0, 179);
  if (newval1 < (oldval1-2) || newval3 > (oldval3+2)){ 

  newval4 = analogRead(potpin4);           
  newval4 = map(newval4, 0, 1023, 0, 179);
  if (newval1 < (oldval1-2) || newval4 > (oldval4+2)){ 

  newval5 = analogRead(potpin5);           
  newval5 = map(newval5, 0, 1023, 0, 179);
  if (newval1 < (oldval5-2) || newval5 > (oldval5+2)){ 
  delay(50);  //to slow loop for testing, adjust as needed

Rx code

Code: [Select]

//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo

void setup() {

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
          Serial.print("writing Microseconds: ");
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
          Serial.print("writing Angle: ");
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
         readString=""; //clears variable for new input
    else {     
      readString += c; //makes the string readString

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


This is much simpler with the EasyTransfer library. As a bonus it sends its packets with a CRC -- you really need some kind of verification that the data isn't getting mangled after it has been received.



Go Up