OngoingDIY Receiver 3 Channel
STDDIY Receiver 3 Channel
792
0
0
0
Mode:Full
License
:Creation time:2022-01-07 10:08:38Update time:2022-01-21 17:36:01
Description
Receiver Code:
// 3 Channel Receiver
// PWM output on pins D3, D5, D6
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
int ch_width_1 = 0;
int ch_width_2 = 0;
int ch_width_3 = 0;
Servo ch1;
Servo ch2;
Servo ch3;
struct Signal {
byte throttle;
byte steering;
byte aux1;
};
Signal data;
const uint64_t pipeIn = 0xE9E8F0F0E1LL;
RF24 radio(10, 9);
void ResetData()
{
// Define the inicial value of each data input
// The middle position for Potenciometers
data.steering = 127; // Center
data.throttle = 127; // Motor Stop
data.aux1 = 0; // Center
}
void setup()
{
//Set the pins for each PWM signal
ch1.attach(3);
ch2.attach(5);
ch3.attach(6);
//Configure the NRF24 module
ResetData();
radio.begin();
radio.openReadingPipe(1,pipeIn);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_MAX);
radio.startListening(); //start the radio comunication for receiver
}
unsigned long lastRecvTime = 0;
void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(Signal));
lastRecvTime = millis(); // receive the data
}
}
void loop()
{
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
ResetData(); // Signal lost.. Reset data
}
ch_width_1 = map(data.steering, 0, 255, 1000, 2000); // pin D3 (PWM signal)
ch_width_2 = map(data.throttle, 0, 255, 800, 2200); // pin D5 (PWM signal)
ch_width_3 = map(data.aux1, 0, 1, 1000, 2000); // pin D6 (PWM signal)
// Write the PWM signal
ch1.writeMicroseconds(ch_width_1);
ch2.writeMicroseconds(ch_width_2);
ch3.writeMicroseconds(ch_width_3);
}Design Drawing
The preview image was not generated, please save it again in the editor.BOM
Bom empty
CloneAdd to Album
0
0
Share
Report
Project Members
Followers0|Likes0
Related projects
Empty


Comment