This is the code for the first test of this Tiny receiver PCB. Connect the battery at the input. Then add 2 DC motors at the outputs AR and AL. Then go below and downlaod or cipy+paste the example receiver code. You will need the radio controller we've made in this tutorial so use the transmitter code from that tutorial. If you don't have the radio controller, just use the transmitter code from that tutorial and make your any kind of radio controller with potentiometers or cheap joysticks. Remember to downlaod and install the NRF24 library to your IDE.
/* Test code for the Radio control receiver
* Install the NRF24 library to your IDE
* Upload this code to the Tiny receiver PCB
* Connect a NRF24 module to it:
* Tutorial: https://electronoobs.com/eng_arduino_tut105.php
* Scheamtic: https://electronoobs.com/images/Arduino/tut_105/sch_2.jpg
* Code: https://electronoobs.com/eng_arduino_tut105_code1.php
* Transmitter tutorial: https://electronoobs.com/eng_arduino_tut86.php
Module // Arduino UNO
GND -> GND
Vcc -> 3.3V
CE -> D7
CSN -> D8
CLK -> D13
MOSI -> D11
MISO -> D12
Please, like share and subscribe : https://www.youtube.com/c/ELECTRONOOBS
*/
#include <SPI.h>
#include <nRF24L01.h> //Download it here: https://electronoobs.com/eng_arduino_NRF24_lib.php
#include <RF24.h>
#include <Servo.h> //To create PWM signals we need this lybrary
const uint64_t pipeIn = 0xE8E8F0F0E1LL; //Remember that this code is the same as in the transmitter
RF24 radio(7, 8);
//We could use up to 32 channels
struct MyData {
byte throttle; //We define each byte of data input, in this case just 6 channels
byte yaw;
byte pitch;
byte roll;
byte AUX1;
byte AUX2;
};
MyData data;
void resetData()
{
//We define the inicial value of each data input
//3 potenciometers will be in the middle position so 127 is the middle from 254
data.throttle = 0;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;
data.AUX1 = 0;
data.AUX2 = 0;
}
//Define the pins for the H bridge of the Tiny receiver PCB
int AL1 = 5;
int AL2 = 6;
int AR1 = 2;
int AR2 = 4;
/**************************************************/
void setup()
{
pinMode(AL1,OUTPUT);
pinMode(AL2,OUTPUT);
pinMode(AR1,OUTPUT);
pinMode(AR2,OUTPUT);
Serial.begin(9600); //Set the speed to 9600 bauds if you want.
//You should always have the same speed selected in the serial monitor
resetData();
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,pipeIn);
//we start the radio comunication
radio.startListening();
}
/**************************************************/
unsigned long lastRecvTime = 0;
void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(MyData));
lastRecvTime = millis(); //here we receive the data
}
}
/**************************************************/
void loop()
{
recvData();
unsigned long now = millis();
//Here we check if we've lost signal, if we did we reset the values
if ( now - lastRecvTime > 1000 ) {
// Signal lost?
resetData();
}
if(data.throttle < 125 && data.yaw > 125 && data.yaw < 130)
{
digitalWrite(AL1,HIGH);
digitalWrite(AL2,LOW);
digitalWrite(AR1,HIGH);
digitalWrite(AR2,LOW);
}
if(data.throttle > 130 && data.yaw > 125 && data.yaw < 130)
{
digitalWrite(AL1,LOW);
digitalWrite(AL2,HIGH);
digitalWrite(AR1,LOW);
digitalWrite(AR2,HIGH);
}
if(data.throttle > 125 && data.throttle < 130 && data.yaw > 125 && data.yaw < 130)
{
digitalWrite(AL1,LOW);
digitalWrite(AL2,LOW);
digitalWrite(AR1,LOW);
digitalWrite(AR2,LOW);
}
if(data.yaw < 125 && data.throttle > 125 && data.throttle < 130)
{
digitalWrite(AL1,LOW);
digitalWrite(AL2,HIGH);
digitalWrite(AR1,HIGH);
digitalWrite(AR2,LOW);
}
if(data.yaw > 130 && data.throttle > 125 && data.throttle < 130)
{
digitalWrite(AL1,HIGH);
digitalWrite(AL2,LOW);
digitalWrite(AR1,LOW);
digitalWrite(AR2,HIGH);
}
if(data.yaw > 125 && data.yaw < 130 && data.throttle > 125 && data.throttle < 130)
{
digitalWrite(AL1,LOW);
digitalWrite(AL2,LOW);
digitalWrite(AR1,LOW);
digitalWrite(AR2,LOW);
}
//Uncomment below for debug
/*
Serial.print("Throttle: "); Serial.print(data.throttle); Serial.print(" ");
Serial.print("Yaw: "); Serial.print(data.yaw); Serial.print(" ");
Serial.print("Pitch: "); Serial.print(data.pitch); Serial.print(" ");
Serial.print("Roll: "); Serial.print(data.roll); Serial.print("\n");
*/
}//end void loop
/**************************************************/