ratack0
Published © GPL3+

Transceiver Communication for road trips!

This is a project designed to make communicating on road trips easier!

AdvancedShowcase (no instructions)467
Transceiver Communication for road trips!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
I used an Arduino Uno and an Arduino Leonardo
×2
Jumper wires (generic)
Jumper wires (generic)
Lots
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
Analog joystick (Generic)
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
One per Arduino
×2
SparkFun Transceiver Breakout - nRF24L01+ (RP-SMA)
SparkFun Transceiver Breakout - nRF24L01+ (RP-SMA)
One per Arduino
×2
Buzzer
Buzzer
Optional (one per Arduino)
×2

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Connections

Code

Road Trip Communication

C#
Upload this code to both Arduinos
#include <LiquidCrystal_I2C.h> // I2C LCD library
LiquidCrystal_I2C lcd(0x27, 16, 2); // define the LCD
#include <SPI.h> // SPI library for the transceiver
#include <nRF24L01.h> // include both of the libraries needed for the transceiver
#include <RF24.h>
const String messages[26] = { // messages 
  "Hello",
  "How are you?",
  "Good",
  "Tired",
  "Hungry",
  "Bathroom break?",
  "Yes",
  "No",
  "Food Break?",
  "Where are you?",
  "Behind you",
  "In front of you",
  "Beside you",
  "Ha!",
  "BRB",
  "Disconnecting...",
  "No!",
  "Turn left",
  "Turn right",
  "Too fast",
  "Too slow",
  "Food soon?",
  "Break soon?",
  "Ok"
};
int messageNumber = 0; // which message the LCD is showing

const int VRX = 0; // joystick pin (analog)
const int VRY = 1; // joystick pin (analog)
const int SW = 8;  // joystick button pin (digital)

#define CE_PIN   9 // CE of radio
#define CSN_PIN 10 // CSN of radio

const byte sendAddress[5] = {'R','x','A','A','A'}; // address to send data
const byte receiveAddress[5] = {'T','x','A','A','A'}; // address to receive data

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int dataReceived;
int dataToSend;

void setup() {
  pinMode(SW, INPUT); // set the button pin as input
  digitalWrite(SW, HIGH);
  Serial.begin(9600); // begin Serial monitor (debugging)
  Serial.println("Starting lcd");
  lcd.backlight(); // turn on LCD backlight
  lcd.init(); // start the LCD
  lcd.clear(); // clear the LCD

    Serial.println("Starting Radio");

    radio.begin(); // start radio
    radio.setDataRate( RF24_250KBPS ); // set data rate
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(sendAddress); // open a pipe for data sending
    radio.openReadingPipe(1, receiveAddress); // open a pipe for receiving data
    Serial.println();
    radio.startListening(); // start listening for data
}

//====================

void loop() {
  if (radio.available()){ // if there is data available:
    radio.read(&dataReceived, sizeof(dataReceived)); // get the data
    lcd.clear(); // clear the LCD
    lcd.setCursor(0, 0);
    lcd.print("New message:"); // print "New Message:" at 0, 0 (top left)
    lcd.setCursor(0, 1);
    lcd.print(messages[dataReceived]); // print the received message at 0, 1 (bottom left)
    delay(5000); // wait five seconds
  }
  changeMessage(); // change the message
  if (digitalRead(SW) == LOW){ // if the joystick button is pressed, send the message
    sendData();
  }
  delay(100); // do this ten times a second
}

//====================

void changeMessage(){
  int x = analogRead(VRY); // read the VRY pin (joystick pins forward)
  x = map(x, 0, 1023, -9, 10); // 10: left
  int y = analogRead(VRX); // the VRX pin reads the movement of the joystick to/from the pins on the front. If the joystick is held sideways, reverse these two values
  y = map(y, 0, 1023, -9, 10); // -9: forwards   You may need to change the -9 to a -10. My joystick was slightly off, so I had to correct it
  if (y < -1){ // change the message
    messageNumber -= 1;
    delay(500);
  }
  if (y > 1){ // change the message
    messageNumber += 1;
    delay(500);
  }
  if (messageNumber < 0){  // if the message number is less than the number of messages, reset it
    messageNumber = 26;
  }
  if (messageNumber > 26){  // if the message number is more than the number of messages, reset it
    messageNumber = 0;
  }
  lcd.clear(); // clear LCD
  lcd.setCursor(0, 0);
  lcd.print(">"); // print the ">" to the LCD
  lcd.setCursor(1, 0);
  lcd.print(messages[messageNumber]); // print the current message
  lcd.setCursor(1, 1);
  if ((messageNumber + 1) < 26){ // print the message after the current message
    lcd.print(messages[messageNumber + 1]);  
  }
  if ((messageNumber + 1) == 26){
    lcd.print(messages[0]);  
  }
}

void sendData(){ // send the number of the current message (ONLY WORKS IF BOTH MESSAGE LISTS ARE THE SAME!!!)
  dataToSend = messageNumber;
  radio.stopListening();
  radio.write(&dataToSend, sizeof(dataToSend));
  delay(5);
  radio.startListening();
}

Road Trip (Arduino 2)

C#
#include <LiquidCrystal_I2C.h> // I2C LCD library
LiquidCrystal_I2C lcd(0x27, 16, 2); // define the LCD
#include <SPI.h> // SPI library for the transceiver
#include <nRF24L01.h> // include both of the libraries needed for the transceiver
#include <RF24.h>
const String messages[26] = { // messages 
  "Hello",
  "How are you?",
  "Good",
  "Tired",
  "Hungry",
  "Bathroom break?",
  "Yes",
  "No",
  "Food Break?",
  "Where are you?",
  "Behind you",
  "In front of you",
  "Beside you",
  "Ha!",
  "BRB",
  "Disconnecting...",
  "No!",
  "Turn left",
  "Turn right",
  "Too fast",
  "Too slow",
  "Food soon?",
  "Break soon?",
  "Ok"
};
int messageNumber = 0; // which message the LCD is showing

const int VRX = 0; // joystick pin (analog)
const int VRY = 1; // joystick pin (analog)
const int SW = 8;  // joystick button pin (digital)

#define CE_PIN   9 // CE of radio
#define CSN_PIN 10 // CSN of radio

const byte sendAddress[5] = {'T','x','A','A','A'}; // address to send data
const byte receiveAddress[5] = {'R','x','A','A','A'}; // address to receive data

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int dataReceived;
int dataToSend;

void setup() {
  pinMode(SW, INPUT); // set the button pin as input
  digitalWrite(SW, HIGH);
  Serial.begin(9600); // begin Serial monitor (debugging)
  Serial.println("Starting lcd");
  lcd.backlight(); // turn on LCD backlight
  lcd.init(); // start the LCD
  lcd.clear(); // clear the LCD

    Serial.println("Starting Radio");

    radio.begin(); // start radio
    radio.setDataRate( RF24_250KBPS ); // set data rate
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(sendAddress); // open a pipe for data sending
    radio.openReadingPipe(1, receiveAddress); // open a pipe for receiving data
    Serial.println();
    radio.startListening(); // start listening for data
}

//====================

void loop() {
  while (!radio.available()){
    ;
  }
  if (radio.available()){ // if there is data available:
    radio.read(&dataReceived, sizeof(dataReceived)); // get the data
    lcd.clear(); // clear the LCD
    lcd.setCursor(0, 0);
    lcd.print("New message:"); // print "New Message:" at 0, 0 (top left)
    lcd.setCursor(0, 1);
    lcd.print(messages[dataReceived]); // print the received message at 0, 1 (bottom left)
    delay(5000); // wait five seconds
  }
  changeMessage(); // change the message
  if (digitalRead(SW) == LOW){ // if the joystick button is pressed, send the message
    sendData();
  }
  delay(100); // do this ten times a second
}

//====================

void changeMessage(){
  int x = analogRead(VRY); // read the VRY pin (joystick pins forward)
  x = map(x, 0, 1023, -9, 10); // 10: left
  int y = analogRead(VRX); // the VRX pin reads the movement of the joystick to/from the pins on the front. If the joystick is held sideways, reverse these two values
  y = map(y, 0, 1023, -9, 10); // -9: forwards   You may need to change the -9 to a -10. My joystick was slightly off, so I had to correct it
  if (y < -1){ // change the message
    messageNumber -= 1;
    delay(500);
  }
  if (y > 1){ // change the message
    messageNumber += 1;
    delay(500);
  }
  if (messageNumber < 0){  // if the message number is less than the number of messages, reset it
    messageNumber = 26;
  }
  if (messageNumber > 26){  // if the message number is more than the number of messages, reset it
    messageNumber = 0;
  }
  lcd.clear(); // clear LCD
  lcd.setCursor(0, 0);
  lcd.print(">"); // print the ">" to the LCD
  lcd.setCursor(1, 0);
  lcd.print(messages[messageNumber]); // print the current message
  lcd.setCursor(1, 1);
  if ((messageNumber + 1) < 26){ // print the message after the current message
    lcd.print(messages[messageNumber + 1]);  
  }
  if ((messageNumber + 1) == 26){
    lcd.print(messages[0]);  
  }
}

void sendData(){ // send the number of the current message (ONLY WORKS IF BOTH MESSAGE LISTS ARE THE SAME!!!)
  dataToSend = messageNumber;
  radio.stopListening();
  radio.write(&dataToSend, sizeof(dataToSend));
  delay(5);
  radio.startListening();
}

Road Trip Communication (buzzer)

C#
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const String messages[26] = {
  "Hello",
  "How are you?",
  "Good",
  "Tired",
  "Hungry",
  "Bathroom break?",
  "Yes",
  "No",
  "Food Break?",
  "Where are you?",
  "Behind you",
  "In front of you",
  "Beside you",
  "Ha!",
  "BRB",
  "Disconnecting...",
  "No!",
  "Turn left",
  "Turn right",
  "Too fast",
  "Too slow",
  "Food soon?",
  "Break soon?",
  "Ok"
};
int messageNumber = 0;

const int VRX = 0;
const int VRY = 1;
const int SW = 8;

#define CE_PIN   9
#define CSN_PIN 10
const int buzzerPin = 7;

const byte sendAddress[5] = {'R','x','A','A','A'};
const byte receiveAddress[5] = {'T','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int dataReceived;
int dataToSend;

void setup() {
  pinMode(buzzerPin, OUTPUT);
  pinMode(SW, INPUT);
  digitalWrite(SW, HIGH);
  Serial.begin(9600);
  Serial.println("Starting lcd");
  lcd.backlight();
  lcd.init();
  lcd.clear();

    Serial.println("Starting Radio");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(sendAddress);
    radio.openReadingPipe(1, receiveAddress);
    Serial.println();
    radio.startListening();
}

//====================

void loop() {
  if (radio.available()){
    radio.read(&dataReceived, sizeof(dataReceived));
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("New message:");
    lcd.setCursor(0, 1);
    lcd.print(messages[dataReceived]);
    for(int i = 0; i < 15; i++){ // buzz the buzzer 10 times a second for 3 seconds
      digitalWrite(buzzerPin, HIGH);
      delay(100);
      digitalWrite(buzzerPin, LOW);
      delay(100);
    }
    delay(2000)
  }
  changeMessage();
  if (digitalRead(SW) == LOW){
    sendData();
  }
  delay(100);
}

//====================

void changeMessage(){
  int x = analogRead(VRY);
  x = map(x, 0, 1023, -9, 10); // 10: left
  int y = analogRead(VRX);
  y = map(y, 0, 1023, -9, 10); // -9: forwards
  if (y < -1){
    messageNumber -= 1;
    delay(500);
  }
  if (y > 1){
    messageNumber += 1;
    delay(500);
  }
  if (messageNumber < 0){
    messageNumber = 26;
  }
  if (messageNumber > 26){
    messageNumber = 0;
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(">");
  lcd.setCursor(1, 0);
  lcd.print(messages[messageNumber]);
  lcd.setCursor(1, 1);
  if ((messageNumber + 1) < 26){
    lcd.print(messages[messageNumber + 1]);  
  }
  if ((messageNumber + 1) == 26){
    lcd.print(messages[0]);  
  }
}

void sendData(){
  dataToSend = messageNumber;
  radio.stopListening();
  radio.write(&dataToSend, sizeof(dataToSend));
  delay(5);
  radio.startListening();
}

Road Trip Communication (buzzer) (Arduino 2)

C#
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const String messages[26] = {
  "Hello",
  "How are you?",
  "Good",
  "Tired",
  "Hungry",
  "Bathroom break?",
  "Yes",
  "No",
  "Food Break?",
  "Where are you?",
  "Behind you",
  "In front of you",
  "Beside you",
  "Ha!",
  "BRB",
  "Disconnecting...",
  "No!",
  "Turn left",
  "Turn right",
  "Too fast",
  "Too slow",
  "Food soon?",
  "Break soon?",
  "Ok"
};
int messageNumber = 0;

const int VRX = 0;
const int VRY = 1;
const int SW = 8;

#define CE_PIN   9
#define CSN_PIN 10
const int buzzerPin = 7;

const byte sendAddress[5] = {'T','x','A','A','A'};
const byte receiveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int dataReceived;
int dataToSend;

void setup() {
  pinMode(buzzerPin, OUTPUT);
  pinMode(SW, INPUT);
  digitalWrite(SW, HIGH);
  Serial.begin(9600);
  Serial.println("Starting lcd");
  lcd.backlight();
  lcd.init();
  lcd.clear();

    Serial.println("Starting Radio");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(sendAddress);
    radio.openReadingPipe(1, receiveAddress);
    Serial.println();
    radio.startListening();
}

//====================

void loop() {
  while(!radio.available()){
    ;
  }
  if (radio.available()){
    radio.read(&dataReceived, sizeof(dataReceived));
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("New message:");
    lcd.setCursor(0, 1);
    lcd.print(messages[dataReceived]);
    for(int i = 0; i < 15; i++){ // buzz the buzzer 10 times a second for 3 seconds
      digitalWrite(buzzerPin, HIGH);
      delay(100);
      digitalWrite(buzzerPin, LOW);
      delay(100);
    }
    delay(2000)
  }
  changeMessage();
  if (digitalRead(SW) == LOW){
    sendData();
  }
  delay(100);
}

//====================

void changeMessage(){
  int x = analogRead(VRY);
  x = map(x, 0, 1023, -9, 10); // 10: left
  int y = analogRead(VRX);
  y = map(y, 0, 1023, -9, 10); // -9: forwards
  if (y < -1){
    messageNumber -= 1;
    delay(500);
  }
  if (y > 1){
    messageNumber += 1;
    delay(500);
  }
  if (messageNumber < 0){
    messageNumber = 26;
  }
  if (messageNumber > 26){
    messageNumber = 0;
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(">");
  lcd.setCursor(1, 0);
  lcd.print(messages[messageNumber]);
  lcd.setCursor(1, 1);
  if ((messageNumber + 1) < 26){
    lcd.print(messages[messageNumber + 1]);  
  }
  if ((messageNumber + 1) == 26){
    lcd.print(messages[0]);  
  }
}

void sendData(){
  dataToSend = messageNumber;
  radio.stopListening();
  radio.write(&dataToSend, sizeof(dataToSend));
  delay(5);
  radio.startListening();
}

Credits

ratack0
0 projects • 4 followers

Comments