Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
Hand tools and fabrication machines | ||||||
|
To start off the project we used an old RC car from New Bright. We removed the cover and control board. We then secured a sheet of ABS plastic and mounted the battery holder and L298N motor driver. Using PVC pipe as stand-offs we mounted the top platform where the arduino board, esp32 cam and buck converter will be placed. We also placed a 3D printed camera holder on top of a servo motor to allow the camera to look around.
/*This code was written by learnayg 2021*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8);
const byte address[6] = "00001";
include <Servo.h>
Servo cameraMount;
const int forward=6;
const int backward=5;
const int turnLeft=10;
const int turnRight=9;
const int buzzer=2;
void setup(){
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
cameraMount.attach(3);
pinMode(forward, OUTPUT);
pinMode(backward, OUTPUT);
pinMode(turnLeft, OUTPUT);
pinMode(turnRight, OUTPUT);
}
void loop(){
checkBattery();
// Read the message sent from the remote
char message[32] = "";
radio.read(&message, sizeof(message));
String command=String(message);
// Seperate the values
String forwardSpeed=String(command.charAt(0))+String(command.charAt(1))+String(command.charAt(2));
String backwardSpeed=String(command.charAt(3))+String(command.charAt(4))+String(command.charAt(5));
String turnLeftSpeed=String(command.charAt(6))+String(command.charAt(7))+String(command.charAt(8));
String turnRightSpeed=String(command.charAt(9))+String(command.charAt(10))+String(command.charAt(11));
String cameraMountPosition=String(command.charAt(12))+String(command.charAt(13))+String(command.charAt(14));
String buzzerState=String(command.charAt(15))+String(command.charAt(16))+String(command.charAt(17))+String(command.charAt(18));
cameraMount.write(cameraMountPosition.toInt());
analogWrite(forward,forwardSpeed.toInt());
analogWrite(backward,backwardSpeed.toInt());
analogWrite(turnLeft,turnLeftSpeed.toInt());
analogWrite(turnRight,turnRightSpeed.toInt());
if(buzzerState=="HIGH"){
digitalWrite(buzzer,HIGH);
}else{
digitalWrite(buzzer,LOW);
}
delay(25);
}
void checkBattery(){
const int batteryLight=4;
const int analogInput=A5;
float voltageOut;
float batteryVoltage;
float resistor1=100000.0; // Resistance of Resistor1 (100K)
float resistor2=10000.0; // Resistance of Resistor2 (10K)
pinMode(batteryLight, OUTPUT);
pinMode(analogInput,INPUT);
int rawValue=analogRead(analogInput);
voltageOut=(rawValue*5)/1024.0;
batteryVoltage=voltageOut/(resistor2/(resistor1+resistor2));
// If the battery voltage is to low turn the LED on
if(batteryVoltage<9){
digitalWrite(batteryLight,HIGH);
}else{
digitalWrite(batteryLight,LOW);
}
}
/*This code was written by learnayg 2021*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8);
const byte address[6] = "00001";
const int cameraMountControl=A2;
const int driveControl=A4;
const int turnControl=A6;
const int lightButton=3;
const int buzzerButton=2;
String buzzerState;
void setup(){
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
pinMode(cameraMountControl,INPUT);
pinMode(driveControl,INPUT);
pinMode(turnControl,INPUT);
pinMode(lightButton,INPUT_PULLUP);
pinMode(buzzerButton,INPUT_PULLUP);
}
void loop(){
if(digitalRead(buzzerButton)==0){
buzzerState="HIGH";
}else{
buzzerState="LOW";
}
int cameraMountControlReading=analogRead(cameraMountControl);
int cameraMountPosition=(180./1023.)*cameraMountControlReading;
int driveControlReading=analogRead(driveControl);
int forward;
int backward;
if(driveControlReading<=511){ // DRIVE FORWARD
forward=(-255./511.)*driveControlReading+255.;
backward=0;
}else if(driveControlReading>=513){ // DRIVE BACKWARD
forward=0;
backward=(255./513.)*driveControlReading-255.;
}else{ // STOP
forward=0;
backward=0;
}
int turnLeft;
int turnRight;
int turnControlReading=analogRead(turnControl);
if(turnControlReading<=511){ // TURN RIGHT
turnRight=(-255./511.)*turnControlReading+255.;
turnLeft=0;
}else if(turnControlReading>=513){ // TURN LEFT
turnRight=0;
turnLeft=(255./513.)*turnControlReading-255.;
}else{ // DON'T TURN
turnLeft=0;
turnRight=0;
}
// This ensures that the values each have three characters
// this makes it easier to read on the receiver's side
int stringLength;
String forwardSpeed=String(forward); // Convert the value to a string
stringLength = int(forwardSpeed.length()); // Read the length of the string
for(int i=stringLength; i<3; i++){ // If the length of the string is less than
forwardSpeed = String("0" + forwardSpeed); // three characters add a zero in the front
}
String backwardSpeed=String(backward);
stringLength = int(backwardSpeed.length());
for(int i=stringLength; i<3; i++){
backwardSpeed = String("0" + backwardSpeed);
}
String turnLeftSpeed=String(turnLeft);
stringLength = int(turnLeftSpeed.length());
for(int i=stringLength; i<3; i++){
turnLeftSpeed = String("0" + turnLeftSpeed);
}
String turnRightSpeed=String(turnRight);
stringLength = int(turnRightSpeed.length());
for(int i=stringLength; i<3; i++){
turnRightSpeed = String("0" + turnRightSpeed);
}
String cameraMountSend=String(cameraMountPosition);
stringLength = int(cameraMountSend.length());
for(int i=stringLength; i<3; i++){
cameraMountSend = String("0" + cameraMountSend);
}
// Combine all of the values into one string
String message=forwardSpeed+backwardSpeed+turnLeftSpeed+turnRightSpeed+cameraMountSend+buzzerState;
int textLength=int(message.length())+1;
char textSend[32]="";
// Convert the string into a char
message.toCharArray(textSend,textLength);
radio.write(&textSend, sizeof(textSend));
}
Comments