need help for wireless interface

hi everyone…well i have trained my voice recognition module v3 for 3 purpose on and arduino uno.
But now i want to connect my v3 with a nano and transmit the instruction wirelessly using NRF24 to an uno to which is connected my relay. can anyone tell me how to proceed with the transmission of the instruction part?

this is my current code between v3 and uno

#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"

/**        
   2   ------->     TX
   3   ------->     RX
*/
VR myVR(2,3);    // 2:RX 3:TX

uint8_t records[7]; // save record
uint8_t buf[64];

int led = 13;
int CH0 = 8;
int CH1 = 9;
#define onRecord    (0)
#define offRecord   (1)
#define leftRecord (2)
#define rightRecord (3) 
#define upRecord (4)
#define downRecord (5)

void setup()
{
  myVR.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(CH0, OUTPUT);
  pinMode(CH1, OUTPUT);
      
}

void loop()
{
  int ret;
  ret = myVR.recognize(buf, 50);
  if(ret>0){
    switch(buf[2]){
      case onRecord:
        digitalWrite(led, HIGH);
        break;
      case offRecord:
         digitalWrite(led, LOW);
        break;
      case leftRecord:
        digitalWrite(CH0, HIGH);
        break;
      case rightRecord:
         digitalWrite(CH0, LOW);
        break;
        case upRecord:
        digitalWrite(CH1, HIGH);
        break;
      case downRecord:
         digitalWrite(CH1, LOW);
        break;
    }
  }
}

Have a look at this Simple nRF24L01+ Tutorial. The first example should be suitable.

I think you just need to send the value that is in your buf[2]

It would probably make the code less confusing if you create a byte variable called dataToSend and then using

dataToSend = buf[2];

and then you can send it with

radio.write(&dataToSend, sizeof(dataToSend);

Your receiver code also needs a byte variable into which to put the received value.

...R

Robin2:
Have a look at this Simple nRF24L01+ Tutorial. The first example should be suitable.

I think you just need to send the value that is in your buf[2]

It would probably make the code less confusing if you create a byte variable called dataToSend and then using

dataToSend = buf[2];

and then you can send it with

radio.write(&dataToSend, sizeof(dataToSend);

Your receiver code also needs a byte variable into which to put the received value.

...R

so the "switch case" must be written on both uno and nano?

keshav_singh:
so the "switch case" must be written on both uno and nano?

No. I assumed you would only have it in the receiver.

...R

im totallly confused with coding part...u seem to be familiar with the nrf24 dude, can you help me out with the code the loop part?

Did you read his tutorial?

i have been trying but its not working.

this is the voice module code

#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"

/**        
   2   ------->     TX
   3   ------->     RX
*/
VR myVR(2,3);    // 2:RX 3:TX

uint8_t records[7]; // save record
uint8_t buf[64];

int led = 13;
int relay0 = 8;
int relay1 = 9;
#define onRecord    (0)
#define offRecord   (1)
#define leftRecord (2)
#define rightRecord (3) 
#define upRecord (4)
#define downRecord (5)

void setup()
{
  myVR.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(relay0, OUTPUT);
  pinMode(relay1, OUTPUT);
      
}

void loop()
{
  int ret;
  ret = myVR.recognize(buf, 50);
  if(ret>0){
    switch(buf[2]){
      case onRecord:
        digitalWrite(led, HIGH);
        break;
      case offRecord:
         digitalWrite(led, LOW);
        break;
      case leftRecord:
        digitalWrite(relay0, HIGH);
        break;
      case rightRecord:
         digitalWrite(relay0, LOW);
        break;
        case upRecord:
        digitalWrite(relay1, HIGH);
        break;
      case downRecord:
         digitalWrite(relay1, LOW);
        break;
    }
  }
}

this is the transmitter code (im using a nano)

//transmit

#include <VoiceRecognitionV3.h>
#include <SoftwareSerial.h>
VR myVR(2,3);    // 2:TX 3:RX
uint8_t records[7]; // save record
uint8_t buf[64];
#define onRecord    (0)
#define offRecord   (1)

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#define CE_PIN   7
#define CSN_PIN 8
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
const byte slaveAddress[5] = {'R','x','A','A','A'};

int dataSend = buf[2];
int data;
void setup ()
{
  myVR.begin(9600);
  Serial.begin ( 9600 );
  radio.begin ();
  radio.setDataRate( RF24_250KBPS );
  radio.openWritingPipe (slaveAddress);
}

void loop ()
{ {int ret;
  ret = myVR.recognize(buf, 50);}
  
  while (radio.available())
    { 
      radio.write (&dataSend, sizeof (dataSend));
    if (Serial.available ()> 0 )
    
  // Send 0 via radio 
  if (buf [ 2 ] == '0' )
  {
    Serial.println ( "light on" );
    data = 0 ;
    radio.write (data, 0 );
 
  }
  
  // Send 1 via radio 
  if (buf [ 2 ] == '1' )
  {
    Serial.println ( "light off" );
    data = 1 ;
    radio.write (data, 1 );
  
  }
  
  }
}

this is receiver an uno

//receiver

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#define CE_PIN   7
#define CSN_PIN 8
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

int dataReceived [1];
int data;

int LED1 = 13 ;

void setup ()
{
  pinMode (LED1, OUTPUT);
  Serial.begin ( 9600 );
  radio.begin ();
  radio.setDataRate( RF24_250KBPS );
  radio.openReadingPipe ( 1 , thisSlaveAddress);
  radio.startListening ();
  
}

void loop ()
{
 
  while (radio.available())
    { 
      radio.read (&dataReceived, sizeof (dataReceived));

      radio.write (data, 2);
 
       // If received 3, light on 
      if (dataReceived [ 0 ] == 0 )
      {
        delay ( 10 );
        digitalWrite (LED1, HIGH);
      }

      // If received 1, light off 
      if (dataReceived [ 0 ] == 1 )
      {
        delay ( 10 );
        digitalWrite (LED1, HIGH);
      }
    
    }
  }

Are you using the same spi pins on the unit and the nano? I have seen some nano pinouts that have MOSI and MISO around the wrong way.

I would load the getting started example that is included in the library and make sure you have communication before trying your code.

keshav_singh:
i have been trying but its not working.

Start by getting one or more of my examples working without any changes or additions.

When that works (but not before) then you can add on other pieces testing as often as possible.

Wireless problems are very difficult to debug.

...R

SamIAm93:
Are you using the same spi pins on the unit and the nano? I have seen some nano pinouts that have MOSI and MISO around the wrong way.

I would load the getting started example that is included in the library and make sure you have communication before trying your code.

yes i have connected the mosi and miso pins on the iscp pins on both nano and uno

Robin2:
Start by getting one or more of my examples working without any changes or additions.

When that works (but not before) then you can add on other pieces testing as often as possible.

Wireless problems are very difficult to debug.

…R

Robin2:
Start by getting one or more of my examples working without any changes or additions.

When that works (but not before) then you can add on other pieces testing as often as possible.

Wireless problems are very difficult to debug.

…R

indeed its a code which i found and tested…i have modified in my concept. see original code below…

transmitter

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#define CE_PIN   7
#define CSN_PIN 8
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
const byte slaveAddress[5] = {'R','x','A','A','A'};


// Store the character typed serial 
char value [ 1 ];

// Store the data sent 
int data [ 1 ];

int dataSend[1];
void setup ()
{
  // Initialize the serial 
  Serial.begin ( 9600 );
  Serial.println ( "Type 1, 2 or L and press SEND ..." );
  
  // Initialize communication of NRF24L01
  radio.begin ();
  radio.setDataRate( RF24_250KBPS );
  // Enters transmission mode
  radio.openWritingPipe (slaveAddress);
}

void loop ()
{
  // Check radio signal 
  while (radio.available())
    { 
      radio.read (&dataSend, sizeof (dataSend));
  // Le character typed in serial 
  if (Serial.available ()> 0 )
  {
    value [ 0 ] = Serial.read ();
  }
  
  // Send via 1 radio if you enter the value 1 
  if (value [ 0 ] == '1' )
  {
    Serial.println ( "Sent: 1 - Gira servant to the left" );
    data [ 0 ] = 1 ;
    radio.write (data, 2 );
    delay ( 100 );
    value [ 0 ] = 0 ;
  }
  
  // Send 2 via radio if you enter the value 2 
  if (value [ 0 ] == '2' )
  {
    Serial.println ( "Sent: 2 - Turns servant to the right" );
    data [ 0 ] = 2 ;
    radio.write (data, 2 );
    delay ( 100 );
    value [ 0 ] = 0 ;
  }
  
  // Send 3 via radio if typed the L character 
  if (value [ 0 ] == 'L' )
  {
    Serial.println ( "Sent: L - Turns the LED" );
    data [ 0 ] = 3 ;
    radio.write (data, 2);
    delay ( 100 );
    value [ 0 ] = 0 ;
  }
}
}

receiver

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#define CE_PIN   7
#define CSN_PIN 8
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};



#include <Servo.h>

// Store the data received 
int dataReceived [1];
int data;

// Initializes the NRF24L01 pins 9 (EC) and 53 (CS) Arduino Mega 


Servo myservo;

// Set the address for communication between the modules 

// Set the LED pin 
int LED1 = 5 ;

void setup ()
{
  // Servo connected to pin 4 
  myservo.attach ( 4 );
  // Set the LED pin as output
  pinMode (LED1, OUTPUT);
  // Initialize the serial 
  Serial.begin ( 9600 );
  // Initialize communication of NRF24L01
  radio.begin ();
  radio.setDataRate( RF24_250KBPS );
  // Goes into reception mode 
  radio.openReadingPipe ( 1 , thisSlaveAddress);
  radio.startListening ();
  // Initial message 
  Serial.println ( "Waiting for data ..." );
}

void loop ()
{
  // Check radio signal 
  while (radio.available())
    { 
      radio.read (&dataReceived, sizeof (dataReceived));

      radio.write (data, 2);
   
      Serial.print ( "Received:" );    
      Serial.print (dataReceived [ 0 ]);
      
      // If you received one, move the servo to the left 
      if (dataReceived [ 0 ] == 1 )
      {
        delay ( 10 );
        Serial.println ( "-> Turning motor to the left" );
        myservo.write ( 1 );
      }
      
      // If received 2 moves the servo to the right 
      if (dataReceived [ 0 ] == 2 )
      {
        delay ( 10 );
        Serial.println ( "-> Turning motor to the right" );
        myservo.write ( 160 );
      }

      // If received 3, the LED lights 
      if (dataReceived [ 0 ] == 3 )
      {
        delay ( 10 );
        Serial.println ( "-> Lights LED" );
        digitalWrite (LED1, HIGH);
      }
      else
      {
        digitalWrite (LED1, LOW);
      }
      delay ( 100 );
    }
  }

keshav_singh:
Indeed its a code which i found and tested…

Am I correct to think that my code worked for you?

Tested could mean that it did not work.

I have bookmarked this for follow-up tonight or tomorrow when I have more time.

…R

sorry uploaded wrong reference code… i have tried it works but it has some delays when sending the data. i tried to modify this code for the voice module.
transmitter

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define CE_PIN   7
#define CSN_PIN 8

const byte slaveAddress[5] = {'R','x','A','A','A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

// Store the character typed serial 
char value [ 1 ];

// Store the data sent 
int data [ 1 ];

void setup ()
{
  // Initialize the serial 
  Serial.begin ( 57600 );
  Serial.println ( "Type 1, 2 or L and press SEND ..." );
  
  radio.begin ();
  radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
 
}

void loop ()
{
  // Le character typed in serial 
  if (Serial.available ()> 0 )
  {
    value [ 0 ] = Serial.read ();
  }
  
  // Send via 1 radio if you enter the value 1 
  if (value [ 0 ] == '1' )
  {
    Serial.println ( "Sent: 1 - Gira servant to the left" );
    data [ 0 ] = 1 ;
    radio.write (data, 1 );
    delay ( 100 );
    value [ 0 ] = 0 ;
  }
  
  // Send 2 via radio if you enter the value 2 
  if (value [ 0 ] == '2' )
  {
    Serial.println ( "Sent: 2 - Turns servant to the right" );
    data [ 0 ] = 2 ;
    radio.write (data, 1 );
    delay ( 100 );
    value [ 0 ] = 0 ;
  }
  
  // Send 3 via radio if typed the L character 
  if (value [ 0 ] == 'L' )
  {
    Serial.println ( "Sent: L - Turns the LED" );
    data [ 0 ] = 3 ;
   radio.write (data, 1 ); 
    delay ( 100 );
    value [ 0 ] = 0 ;
  }
}

receiver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   7
#define CSN_PIN 8

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);
 
#include <Servo.h>

// Store the data received 
int received [ 1 ];
 
Servo myservo;

// Set the LED pin 
int LED1 = 5 ;

void setup ()
{
  // Servo connected to pin 4 
  myservo.attach ( 4 );
  // Set the LED pin as output
  pinMode (LED1, OUTPUT);
  // Initialize the serial 
  Serial.begin ( 57600 );
  // Initialize communication of NRF24L01
  radio.begin ();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening ();
  // Initial message 
  Serial.println ( "Waiting for data ..." );
}

void loop ()
{
  // Check radio signal 
  if (radio.available ())
  {
 
   radio.read (received, 1); 
      Serial.print ( "Received:" );    
      Serial.print (received [ 0 ]);
      
      // If you received one, move the servo to the left 
      if (received [ 0 ] == 1 )
      {
        delay ( 10 );
        Serial.println ( "-> Turning motor to the left" );
        myservo.write ( 1 );
      }
      
      // If received 2 moves the servo to the right 
      if (received [ 0 ] == 2 )
      {
        delay ( 10 );
        Serial.println ( "-> Turning motor to the right" );
        myservo.write ( 160 );
      }

      // If received 3, the LED lights 
      if (received [ 0 ] == 3 )
      {
        delay ( 10 );
        Serial.println ( "-> Lights LED" );
        digitalWrite (LED1, HIGH);
      }
      else
      {
        digitalWrite (LED1, LOW);
      }
      delay ( 100 );
    }
  }

keshav_singh:
sorry uploaded wrong reference code... i have tried it works but it has some delays when sending the data.

Sorry, but you are still confusing me. And as i said wireless problems are very difficult to debug so it is essential to progress at a snail's pace or else get hopelessly lost.

Do you mean that when you tried my code with NO CHANGES there were some unexpected delays in it? If so we need to sort that out first. Please describe in detail what you mean by "some delays"

...R