I am struggling to write code to send the value of the potentiometer on the transmitter, over to the receiver. I don't know whether it matters when I map the value. The code works with a potentiometer and drone motor with no wireless transmission.
#include<Servo.h>
Servo esc;
void setup()
{
esc.attach(12);
}
void loop()
{
int val;
int mappedval;
val=analogRead(A0);
mappedval = map(val, 560, 950, 1300, 2000);
esc.write(mappedval);
}
Here is my code for the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int val;
RF24 radio(9, 10); // CE, CSN
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup() {
radio.begin();
radio.openWritingPipe(pipe);
radio.stopListening();
}
void loop() {
val = map(analogRead(A0), 560, 950, 1300, 2000);
radio.write(val, sizeof(val));
}
And receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
Servo esc;
int val;
RF24 radio(9, 10); // CE, CSN
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();
esc.attach(5);
}
void loop() {
if (radio.available()) {
radio.read(val, sizeof(val));
Serial.println(val);
esc.write(val);
}
}
For the nRF24L01's work, I used Robins guide and ensured they worked there first. When running the code I get nothing in the serial monitor for the receiver and the motor does nothing.
Thanks for the help.