# LIDAR ROBOT - nrf24l01 rf transceiver + LCD + TF-Mini S

**URL:** <https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410>\
**Category:** Sensors\
**Created:** [July 27, 2023, 8:47pm UTC](https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410 "2023-07-27T20:47:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![enrlfrod](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@enrlfrod](https://forum.arduino.cc/u/enrlfrod)\
**Post date:** [July 27, 2023, 8:47pm UTC](https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410/1 "2023-07-27T20:47:52Z")

</div>

Hello,

Working on a project for university a LIDAR Robot which is capable of mapping a room.

I have started by creating a receiver using an Arduino uno with an LCD mounted to a breadboard.

The LIDAR Robot also uses an Arduino Uno with a TF-Mini S as the LIDAR Sensor and both components use nrf24l01 rf to transmit and receive.

I have coded the LIDAR Robot and reciever.

Each component works separately but not combined.

Code Shown Below:

```arduino
// LIDAR ROBOT
#include <SoftwareSerial.h>
#include "TFMini.h"
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <Servo.h> // Library used for servo motors with predefined functions and methods
TFMini tfmini;
int E1 = 0; //Enable1 set to digital pin 0 - Front Left Wheel
int M1 = 1; //Motor1 set to digital pin 1 - Front Left Wheel
int E2 = 2; //Enable2 set to digital pin 2 - Front Right Wheel
int M2 = 3; //Motor2 set to digital pin 3 - Front Right Wheel
int E3 = 4; //Enable3 set to digital pin 4 - Back Left Wheel
int M3 = 5; //Motor3 set to digital pin 5 - Back Left Wheel
int E4 = 6; //Enable4 set to digital pin 6 - Back Right Wheel
int M4 = 7; //Motor4 set to digital pin 7 - Back right Wheel
int Distance = 0; //set distance value to 0
int Strength = 0; //set strength value to 0
int pos = 0; // variable to store the servo position
boolean object;
SoftwareSerial Serial0(12, 13);
float time = 0;
long duration, cm;
int i;
int Check;
int data = 0;
int uart[10]; //save data measured by LiDAR
const int HEADER = 0x59; //frame header of data package
RF24 radio(9, 8); // CE, CSN
const byte address[6] = "00001";
Servo myservo;

void setup()
{
  Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer
  Serial0.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  myservo.attach(10); // attach the servo to our servo object
  myservo.write(98);
  pinMode(M1, OUTPUT); //sets Left Motor to OUTPUT
  pinMode(M2, OUTPUT); //sets Right Motor to OUTPUT
  pinMode(E1, OUTPUT); //sets Left Enable to OUTPUT
  pinMode(E2, OUTPUT); //sets Right Enable to OUTPUT
  pinMode(M3, OUTPUT); //sets Left Motor to OUTPUT
  pinMode(M4, OUTPUT); //sets Right Motor to OUTPUT
  pinMode(E3, OUTPUT); //sets Left Enable to OUTPUT
  pinMode(E4, OUTPUT); //sets Right Enable to OUTPUT
}
 
 
void loop() {
  radio.stopListening ();
  for (pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);
  if (Serial0.available()) //check if serial port has data input
  {
    if (Serial0.read() == HEADER) //assess data package frame header 0x59
    {
      uart[0] = HEADER;
      if (Serial0.read() == HEADER) //assess data package frame header 0x59
      {
        uart[1] = HEADER;
        for (i = 2; i < 9; i++) //save data in array
        {
          uart[i] = Serial0.read();
        }
        Check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
        if (uart[8] == (Check & 0xff)) //verify the received data as per protocol
        {
          Distance = uart[2] + uart[3] * 256; //calculate distance value
          Strength = uart[4] + uart[5] * 256; //calculate signal strength value;
          Serial.print("Distance = ");
          Serial.print(Distance);  
          Serial.print('\t');
          Serial.print("Strength = ");
          Serial.print(Strength);  
          Serial.print('\n');
          {
          radio.write(&data, sizeof(data));
          Serial.print("Distance = ");
          Serial.println(Distance);
          delay(400);
          }
        }
      }
    }
  }
  }
}

```

```arduino
#Receiver  
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <LiquidCrystal.h>

RF24 radio(8, 9); // CE, CSN
const byte address[6] = "00001";
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int txt = 0;

void setup() 
{
  while (!Serial);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, address);
  lcd.begin(16, 2);
}

void loop()
{
radio.startListening();
{
  if (radio.available()) 
  {
  while (radio.available()) 
  {
  if (Serial.available()) {
  radio.read(&txt, sizeof(txt));
  lcd.clear();
  lcd.write("Distance = ");
  while (Serial.available() > 0) {
  lcd.write(Serial.read());
  }
}
}
}
}
}

```

Thank you for reading.

Any Help is Appreciated 👍

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [July 27, 2023, 9:01pm UTC](https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410/2 "2023-07-27T21:01:09Z")

</div>

> [@enrlfrod](#):
>
> ```arduino
> if (radio.available()) 
> {
> while (radio.available()) 
> {
> if (Serial.available()) {
> 
> ```

What if serial becomes available, but no radio?

Why the if, followed by while?

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [July 27, 2023, 9:02pm UTC](https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410/3 "2023-07-27T21:02:02Z")

</div>

> [@enrlfrod](#):
>
> `int E1 = 0;`

Don't you want this for debugging?

---

<div class="post-metadata">

**Author:** ![enrlfrod](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@enrlfrod](https://forum.arduino.cc/u/enrlfrod)\
**Post date:** [July 27, 2023, 9:15pm UTC](https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410/4 "2023-07-27T21:15:57Z")

</div>

Hello

Thank you for your response.

I should i have clarified the e1 m1 etc are for my wheels which will be mounted to a chasis.

I am using a dual h bridge motor

The if followed by while was due to me being able to show the readings on the serial monitor but not on the lcd screen. I was hoping by creating an if serial available it would work.

Thanks

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [July 27, 2023, 9:18pm UTC](https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410/5 "2023-07-27T21:18:26Z")

</div>

> [@enrlfrod](#):
>
> I should i have clarified the e1 m1 etc are for my wheels which will be mounted to a chasis

Pins 0 and 1 on the Uno are used by Serial

---

<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:** [January 23, 2024, 9:18pm UTC](https://forum.arduino.cc/t/lidar-robot-nrf24l01-rf-transceiver-lcd-tf-mini-s/1152410/6 "2024-01-23T21:18:53Z")

</div>

Closed on January 23, 2024, 9:18pm UTC

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