Free Shipping on all Vilros kits & Accessories. Everyday!

SHIPPING DELAY!

Please Note:

Due to the Succot Holiday, our customer service department and warehouse will be closed on the following days: Monday & Tuesday October 14th -15th, Friday - Wednesday October 18th - 23th.

Please expect shipping delays and plan accordingly!

Can You Hear Me Now? Making a Wireless Communication Device with Arduino UNO

Can You Hear Me Now? Making a Wireless Communication Device with Arduino UNO

How would you like to create your own wireless device?
In this project, inspired by MisterBotBreak we will use Arduino Uno to transmit variables that will allow us to control a servo motor.


Here are the parts and apps you’ll need:

• Arduino Uno + Genuino UNO https://vilros.com/products/arduino-uno-micro-controller?variant=21355380113508
• Jumper Wires https://vilros.com/products/jumper-wires?variant=21355395448932
• NRF24l01 radio transmitter
• A Rotary Potentiometer - 10k Ohm
• A DC Motor in Micro Servo Body
• Arduino IDE


Note about the Radio Transmitter

The NRF24l01 radio transmitter used in this project can transmit data on the frequency range of 2, 4GHz. There are two types of antennae, ceramic and antenna trace.
Also, even though some radio transmitters have a voltage regulator that supports 5V, this project is based on using a transmitter that only supports 3.3V.

Library

For the code for this project, we use a library that’s called Mirf
3 Mirf/Mirf.cpp
@@ -2,6 +2,8 @@
* Mirf
*
* Additional bug fixes and improvements
* 11/03/2011:
* Switched spi library.
* 07/13/2010:
* Added example to read a register
* 11/12/2009:
@@ -87,6 +89,7 @@ void Nrf24l::init()
csnHi();

// Initialize spi module
Serial.println("Calling begin");
spi->begin();

}
6 Mirf/MirfHardwareSpiDriver.cpp
@@ -1,15 +1,11 @@
#include "MirfHardwareSpiDriver.h"
#include <HardwareSerial.h>

uint8_t MirfHardwareSpiDriver::transfer(uint8_t data){
return SPI.transfer(data);
}

void MirfHardwareSpiDriver::begin(){
Serial.println("Begining SPI");
SPI.begin();
SPI.setBitOrder(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_2XCLOCK_MASK);
}

6 Mirf/MirfSpiDriver.h
@@ -8,10 +8,10 @@ extern "C" {

class MirfSpiDriver {
public:
uint8_t transfer(uint8_t data);
virtual uint8_t transfer(uint8_t data);

void begin();
void end();
virtual void begin();
virtual void end();
};

#endif
4 Mirf/examples/ping_client/ping_client.pde
@@ -16,9 +16,10 @@
* 'ping_server_interupt' on the server.
*/

#include <Spi.h>
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup(){
Serial.begin(9600);
@@ -35,6 +36,7 @@ void setup(){
Mirf.cePin = 7;
Mirf.csnPin = 8;
*/
Mirf.spi = &MirfHardwareSpi;
Mirf.init();

/*
9 Mirf/examples/ping_server/ping_server.pde
@@ -13,13 +13,20 @@
*
*/

#include <Spi.h>
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup(){
Serial.begin(9600);

/*
* Set the SPI Driver.
*/

Mirf.spi = &MirfHardwareSpi;

/*
* Setup pins / SPI.
*/
9 Mirf/examples/ping_server_interupt/ping_server_interupt.pde
@@ -16,9 +16,10 @@
* CSN -> 7
*/

#include <Spi.h>
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <avr/sleep.h>

void wakeupFunction(){
@@ -32,6 +33,12 @@ void toSleep(){

void setup(){
Serial.begin(9600);

/*
* Set the SPI Driver.
*/

Mirf.spi = &MirfHardwareSpi;

/*
* Setup pins / SPI.
6 Mirf/examples/reg_read/reg_read.pde
@@ -10,15 +10,17 @@
* CSN -> 7
*/

#include <Spi.h>
#include <mirf.h>
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup() {
Serial.begin(9600);
Serial.println( "Starting wireless..." );

// Setup
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"clie1");
Mirf.payload = sizeof(unsigned long);
4 README
@@ -2,10 +2,6 @@ An Arduino port of the tinkerer.eu library. It works with the Sparkfun nRF24L01+

For more details, check out: https://github.com/aaronds/arduino-nrf24l01


Wiring

In order to wire together all the component parts, you’ll want to follow the diagrams available here.

Code

Here is the code you will need:

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup() {
Serial.begin(9600);
Serial.println("Library initialization; EC/CSN pin and channel definition and module transmission and reception address definition");
delay(2000);
Mirf.cePin = 9;
Mirf.csnPin = 10;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.channel = 1;
Mirf.payload = sizeof(float);
Mirf.config();
Mirf.setTADDR((byte *) "nrf02");
Mirf.setRADDR((byte *) "nrf01");
}

void loop() {
float value = analogRead(A0);
Serial.println(value);

Mirf.send((byte *) &value);
while(Mirf.isSending());
}

If you’ve enjoyed this project, be sure to check back here on our Vilros Projects blog for more ideas you can try using Arduino and Raspberry Pi.



Leave a comment

Comments will be approved before showing up.

GET IN TOUCH

MAKE:INSPIRE TEAM

x