# Radio Does not Name a type error

**URL:** <https://forum.arduino.cc/t/radio-does-not-name-a-type-error/689912>\
**Category:** General Guidance\
**Created:** [January 5, 2021, 1:42am UTC](https://forum.arduino.cc/t/radio-does-not-name-a-type-error/689912 "2021-01-05T01:42:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cameronshep](https://avatars.discourse-cdn.com/v4/letter/c/53a042/32.png) [@cameronshep](https://forum.arduino.cc/u/cameronshep)\
**Post date:** [January 5, 2021, 1:42am UTC](https://forum.arduino.cc/t/radio-does-not-name-a-type-error/689912/1 "2021-01-05T01:42:35Z")

</div>

Hello! Im currently trying to program a homemade RC car with a brushless motor and a servo. This is the code causing the error of

Transmitter\_Base\_Code:61:3: error: 'radio' does not name a type

radio.write(&data, sizeof(Data\_Package));

^ ~~~~

Multiple libraries were found for "nRF24L01.h"

\Documents\Arduino\libraries\RF24

Not used: \Documents\Arduino\libraries\RF24-master

exit status 1

'radio' does not name a type

And here is the full code

#include \<SPI.h\>  
#include \<RF24.h\>

RF24 radio(9, 10); // nRF24L01 (CE, CSN)  
const byte address[6] = "00001"; // Address  
// Max size of this struct is 32 bytes - NRF24L01 buffer limit  
struct Data\_Package {  
byte j1PotX;  
byte j1PotY;  
byte j2PotX;  
byte j2PotY;  
};  
Data\_Package data; //Create a variable with the above structure  
void setup() {  
Serial.begin(9600);  
pinMode(27,OUTPUT);  
// Define the radio communication  
radio.begin();  
radio.openWritingPipe(address);  
radio.setAutoAck(false);  
radio.setDataRate(RF24\_250KBPS);  
radio.setPALevel(RF24\_PA\_LOW);

// Set initial default values  
data.j1PotX = 127; // Values from 0 to 255. When Joystick is in resting position, the value is in the middle, or 127. We actually map the pot value from 0 to 1023 to 0 to 255 because that's one BYTE value  
data.j1PotY = 127;  
data.j2PotX = 127;  
data.j2PotY = 127;  
}  
void loop() {  
// Read all analog inputs and map them to one Byte value  
data.j1PotX = map(analogRead(A1), 0, 1023, 0, 255); // Convert the analog read value from 0 to 1023 into a BYTE value from 0 to 255  
data.j1PotY = map(analogRead(A0), 0, 1023, 0, 255);  
data.j2PotX = map(analogRead(A2), 0, 1023, 0, 255);  
data.j2PotY = map(analogRead(A3), 0, 1023, 0, 255);  
}  
// Send the whole data from the structure to the receiver  
radio.write(&data, sizeof(Data\_Package));  
}

This isn't all my code and I'm no Arduino code master, i barely know python, so some help would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [January 5, 2021, 3:28am UTC](https://forum.arduino.cc/t/radio-does-not-name-a-type-error/689912/2 "2021-01-05T03:28:04Z")

</div>

You have a curly bracket closing the loop() function early. That puts the radio.write statement outside of a function. That is an error.

If you had bothered to read the forum guidelines you would have known to format the code with the IDE autoformat tool (ctrl-t or Tools, Auto Format) before posting code in code tags. Here is your code fixed so that it compiles, formatted and posted properly. The comment marked with \*\*\* show the source of the error.

```cpp
#include <SPI.h>
#include <RF24.h>

RF24 radio(9, 10);  // nRF24L01 (CE, CSN)
const byte address[6] = "00001"; // Address
// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package
{
  byte j1PotX;
  byte j1PotY;
  byte j2PotX;
  byte j2PotY;
};
Data_Package data; //Create a variable with the above structure

void setup()
{
  Serial.begin(9600);
  pinMode(27, OUTPUT);
  // Define the radio communication
  radio.begin();
  radio.openWritingPipe(address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);

  // Set initial default values
  data.j1PotX = 127; // Values from 0 to 255. When Joystick is in resting position, the value is in the middle, or 127. We actually map the pot value from 0 to 1023 to 0 to 255 because that's one BYTE value
  data.j1PotY = 127;
  data.j2PotX = 127;
  data.j2PotY = 127;
}
void loop()
{
  // Read all analog inputs and map them to one Byte value
  data.j1PotX = map(analogRead(A1), 0, 1023, 0, 255); // Convert the analog read value from 0 to 1023 into a BYTE value from 0 to 255
  data.j1PotY = map(analogRead(A0), 0, 1023, 0, 255);
  data.j2PotX = map(analogRead(A2), 0, 1023, 0, 255);
  data.j2PotY = map(analogRead(A3), 0, 1023, 0, 255);
   
  // } ************* this misplaced } closed the loop function leaving the next statement      hanging
   
  // Send the whole data from the structure to the receiver
  radio.write(&data, sizeof(Data_Package));
}

```

The multiple libraries part is a warning, not an error, but you can fix it by deleting the \Documents\Arduino\libraries\RF24-master library.

---

<div class="post-metadata">

**Author:** ![SteveMann](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@SteveMann](https://forum.arduino.cc/u/SteveMann)\
**Post date:** [January 5, 2021, 3:34am UTC](https://forum.arduino.cc/t/radio-does-not-name-a-type-error/689912/3 "2021-01-05T03:34:12Z")

</div>

If you format your code in the IDE (CTRL-T) and post it here using code tags as directed in the "How to use this forum" sticky, more people will look at it.

Your problem is misapplied braces. Which becomes obvious when looking at formatted code.  
Your call to radio.write is outside of the loop.

---

<div class="post-metadata">

**Author:** ![cameronshep](https://avatars.discourse-cdn.com/v4/letter/c/53a042/32.png) [@cameronshep](https://forum.arduino.cc/u/cameronshep)\
**Post date:** [January 5, 2021, 5:52pm UTC](https://forum.arduino.cc/t/radio-does-not-name-a-type-error/689912/4 "2021-01-05T17:52:29Z")

</div>

Ah okay, thank you both!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 7:24pm UTC](https://forum.arduino.cc/t/radio-does-not-name-a-type-error/689912/5 "2021-05-05T19:24:11Z")

</div>

Closed on May 5, 2021, 7:24pm UTC

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
