im trying to make a remote control using 3 button that is controling servo and LED.i have this problem for quite a while now where the nrf24l01 just not working it just dont transmit and recieve anything. i use uno both for transmitter and reciever
transmitter
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipe = 0xE8E8F0F0E1LL;
int right = 2;
int left = 3;
int go = 4;
int State = 0;
RF24 radio(7,8); // CE, CSN pins
void setup() {
Serial.begin(9600);
pinMode(right,INPUT);
pinMode(left,INPUT);
pinMode(go,INPUT);
digitalWrite(10,HIGH);
radio.begin();
radio.setChannel(108);
radio.openWritingPipe(pipe);
radio.stopListening();
}
void loop() {
State = 0;
if(digitalRead(right) == HIGH)
{
State = 10;
}
if(digitalRead(left) == HIGH)
{
State = 20;
}
if(digitalRead(go) == HIGH)
{
State = 30;
}
radio.write(&State, sizeof(State));
Serial.println(State);
}
reciever
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Servo.h>
const uint64_t pipe = 0xE8E8F0F0E1LL;
bool yes_or_no = false;
int pos = 90;
int State = 0;
int CE = 7;
int CSN = 8;
RF24 radio(CE,CSN); // CE, CSN pins
Servo servo;
void setup()
{
pinMode(3,OUTPUT);
pinMode(2,INPUT);
Serial.begin(9600);
digitalWrite(10,HIGH);
radio.begin();
radio.setChannel(108);
radio.openReadingPipe(1,pipe);
radio.startListening();
servo.attach(6);
servo.write(pos);
}
void loop()
{
if(radio.available())
{
radio.read(&State, sizeof(State));
}
if(State == 10)
{
for(pos = 90; pos < 181; pos++)
{
servo.write(pos);
}
if(pos == 180)
{
pos = 90;
}
}
if(State == 20)
{
for(pos = 90; pos > 0; pos--)
{
servo.write(pos);
}
if(pos == 0)
{
pos = 90;
}
}
if(State == 30 && digitalRead(2) == LOW)
{
if(yes_or_no == true)
{
digitalWrite(3,HIGH);
yes_or_no = false;
}
else
{
digitalWrite(3,LOW);
yes_or_no = true;
}
}
Serial.println(State);
}