I have built a wireless robot hand for school project using flex sensor, nRF24l01 module and servo but it is not working.
I have reassembled it many times and assembled it again but still it is not working. Please help me.
And please also check the circuit diagram.
Here is the code :
Reciever code :
#include <Servo.h> //the library which helps us to control the servo motor
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
//define the servo name
Servo myServo1;
Servo myServo3;
Servo myServo4;
Servo myServo2;
Servo myServo5;
RF24 radio(5,10); /This object represents a modem connected to the Arduino.
Arguments 5 and 10 are a digital pin numbers to which signals
CE and CSN are connected./
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.
int msg[1];
int data; //data variable
int pos; //position variable
void setup(){
//define the servo input pins
myServo1.attach(15); //A1
myServo3.attach(16); //A2
myServo4.attach(17); //A3
myServo2.attach(18); //A4
myServo5.attach(19); //A5
radio.begin(); //it activates the modem.
radio.openReadingPipe(1, pipe); //determines the address of our modem which receive data.
radio.startListening(); //enable receiving data via modem
}
//You don't need to make changes in this section
void loop(){
if(radio.available()){
radio.read(msg, 1);
if(msg[0] <11 && msg[0] >-1){
data = msg[0], pos=map(data, 0, 10, 175, 0);
myServo1.write(pos);
}
if(msg[0] <21 && msg[0]>10){
data = msg[0], pos=map(data, 11, 20, 175, 0);
myServo3.write(pos);
}
if(msg[0] <31 && msg[0]>20){
data = msg[0], pos=map(data, 21, 30, 175, 0);
myServo4.write(pos);
}
if(msg[0] <41 && msg[0]>30){
data = msg[0], pos=map(data, 31, 40, 175, 0);
myServo2.write(pos);
}
if(msg[0] <51 && msg[0]>40){
data = msg[0], pos=map(data, 41, 50, 175, 0);
myServo5.write(pos);
}
}
}
And Transmitter code :
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
int msg[1];
//define the flex sensor input pins
int flex_5 = A5;
int flex_4 = A4;
int flex_3 = A3;
int flex_2 = A2;
int flex_1 = A1;
//define variables for flex sensor values
int flex_5_val;
int flex_4_val;
int flex_3_val;
int flex_2_val;
int flex_1_val;
RF24 radio(5,10); //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.
void setup(void){
Serial.begin(9600);
radio.begin(); //it activates the modem.
radio.openWritingPipe(pipe); //sets the address of the receiver to which the program will send data.
}
void loop(){
flex_5_val = analogRead(flex_5);
//175 - 0
flex_5_val = map(flex_5_val, 1023, 0, 0, 10);
msg[0] = flex_5_val;
radio.write(msg, 1);
flex_4_val = analogRead(flex_4);
//175 - 0
flex_4_val = map(flex_4_val, 1023, 0, 11, 20);
msg[0] = flex_4_val;
radio.write(msg, 1);
flex_3_val = analogRead(flex_3);
//175 - 0
flex_3_val = map(flex_3_val, 1023, 0, 21, 30);
msg[0] = flex_3_val;
radio.write(msg, 1);
flex_2_val = analogRead(flex_2);
//175 - 0
flex_2_val = map(flex_2_val, 1023, 0, 31, 40);
msg[0] = flex_2_val;
radio.write(msg, 1);
flex_1_val = analogRead(flex_1);
//175 - 0
flex_1_val = map(flex_1_val, 1023, 0, 41, 50);
msg[0] = flex_1_val;
radio.write(msg, 1);
}

