Lil' Rover
An RC car converted into an arduino powered rover with the ESP32-Cam.
Components and supplies
2
DC/DC Converter, Buck Regulator
1
Resistor 10k ohm
2
nRF24 Module (Generic)
1
Resistor 100k ohm
1
Arduino Nano R3
1
SparkFun Full-Bridge Motor Driver Breakout - L298N
2
Joystick, 10 kohm
1
Servo Module (Generic)
1
Arduino UNO
2
Capacitor 10 µF
Tools and machines
1
3D Printer (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
Car
arduino
Code for the car
1/*This code was written by learnayg 2021*/ 2#include <SPI.h> 3#include 4 <nRF24L01.h> 5#include <RF24.h> 6RF24 radio(7,8); 7const byte address[6] = 8 "00001"; 9 10include <Servo.h> 11Servo cameraMount; 12 13const int forward=6; 14const 15 int backward=5; 16const int turnLeft=10; 17const int turnRight=9; 18const int 19 buzzer=2; 20void setup(){ 21 radio.begin(); 22 radio.openReadingPipe(0, address); 23 24 radio.setPALevel(RF24_PA_MAX); 25 radio.setDataRate(RF24_250KBPS); 26 radio.startListening(); 27 28 29 cameraMount.attach(3); 30 pinMode(forward, OUTPUT); 31 pinMode(backward, 32 OUTPUT); 33 pinMode(turnLeft, OUTPUT); 34 pinMode(turnRight, OUTPUT); 35} 36void 37 loop(){ 38 checkBattery(); 39 // Read the message sent from the remote 40 char 41 message[32] = ""; 42 radio.read(&message, sizeof(message)); 43 String command=String(message); 44 45 46 // Seperate the values 47 String forwardSpeed=String(command.charAt(0))+String(command.charAt(1))+String(command.charAt(2)); 48 49 String backwardSpeed=String(command.charAt(3))+String(command.charAt(4))+String(command.charAt(5)); 50 51 String turnLeftSpeed=String(command.charAt(6))+String(command.charAt(7))+String(command.charAt(8)); 52 53 String turnRightSpeed=String(command.charAt(9))+String(command.charAt(10))+String(command.charAt(11)); 54 55 String cameraMountPosition=String(command.charAt(12))+String(command.charAt(13))+String(command.charAt(14)); 56 57 String buzzerState=String(command.charAt(15))+String(command.charAt(16))+String(command.charAt(17))+String(command.charAt(18)); 58 59 60 cameraMount.write(cameraMountPosition.toInt()); 61 analogWrite(forward,forwardSpeed.toInt()); 62 63 analogWrite(backward,backwardSpeed.toInt()); 64 analogWrite(turnLeft,turnLeftSpeed.toInt()); 65 66 analogWrite(turnRight,turnRightSpeed.toInt()); 67 68 if(buzzerState=="HIGH"){ 69 70 digitalWrite(buzzer,HIGH); 71 }else{ 72 digitalWrite(buzzer,LOW); 73 74 } 75 delay(25); 76} 77void checkBattery(){ 78 const int batteryLight=4; 79 80 const int analogInput=A5; 81 float voltageOut; 82 float batteryVoltage; 83 84 float resistor1=100000.0; // Resistance of Resistor1 (100K) 85 float resistor2=10000.0; 86 // Resistance of Resistor2 (10K) 87 88 pinMode(batteryLight, OUTPUT); 89 90 pinMode(analogInput,INPUT); 91 92 int rawValue=analogRead(analogInput); 93 94 voltageOut=(rawValue*5)/1024.0; 95 batteryVoltage=voltageOut/(resistor2/(resistor1+resistor2)); 96 97 // If the battery voltage is to low turn the LED on 98 if(batteryVoltage<9){ 99 100 digitalWrite(batteryLight,HIGH); 101 }else{ 102 digitalWrite(batteryLight,LOW); 103 104 } 105}
Remote
arduino
Code for the remote
1/*This code was written by learnayg 2021*/ 2#include <SPI.h> 3#include 4 <nRF24L01.h> 5#include <RF24.h> 6 7RF24 radio(7,8); 8const byte address[6] 9 = "00001"; 10 11const int cameraMountControl=A2; 12const int driveControl=A4; 13const 14 int turnControl=A6; 15const int lightButton=3; 16const int buzzerButton=2; 17String 18 buzzerState; 19void setup(){ 20 radio.begin(); 21 radio.openWritingPipe(address); 22 23 radio.setPALevel(RF24_PA_MAX); 24 radio.setDataRate(RF24_250KBPS); 25 radio.stopListening(); 26 27 28 pinMode(cameraMountControl,INPUT); 29 pinMode(driveControl,INPUT); 30 31 pinMode(turnControl,INPUT); 32 pinMode(lightButton,INPUT_PULLUP); 33 pinMode(buzzerButton,INPUT_PULLUP); 34} 35void 36 loop(){ 37 if(digitalRead(buzzerButton)==0){ 38 buzzerState="HIGH"; 39 40 }else{ 41 buzzerState="LOW"; 42 } 43 int cameraMountControlReading=analogRead(cameraMountControl); 44 45 int cameraMountPosition=(180./1023.)*cameraMountControlReading; 46 47 int driveControlReading=analogRead(driveControl); 48 49 int forward; 50 int backward; 51 if(driveControlReading<=511){ // 52 DRIVE FORWARD 53 forward=(-255./511.)*driveControlReading+255.; 54 backward=0; 55 56 }else if(driveControlReading>=513){ // DRIVE BACKWARD 57 forward=0; 58 59 backward=(255./513.)*driveControlReading-255.; 60 }else{ // 61 STOP 62 forward=0; 63 backward=0; 64 } 65 66 int turnLeft; 67 int 68 turnRight; 69 int turnControlReading=analogRead(turnControl); 70 if(turnControlReading<=511){ 71 // TURN RIGHT 72 turnRight=(-255./511.)*turnControlReading+255.; 73 74 turnLeft=0; 75 }else if(turnControlReading>=513){ // TURN LEFT 76 turnRight=0; 77 78 turnLeft=(255./513.)*turnControlReading-255.; 79 }else{ // 80 DON'T TURN 81 turnLeft=0; 82 turnRight=0; 83 } 84 85 // This ensures 86 that the values each have three characters 87 // this makes it easier to read 88 on the receiver's side 89 int stringLength; 90 String forwardSpeed=String(forward); 91 // Convert the value to a string 92 stringLength = int(forwardSpeed.length()); 93 // Read the length of the string 94 for(int i=stringLength; i<3; i++){ // 95 If the length of the string is less than 96 forwardSpeed = String("0" + forwardSpeed); 97 // three characters add a zero in the front 98 } 99 String backwardSpeed=String(backward); 100 101 stringLength = int(backwardSpeed.length()); 102 for(int i=stringLength; i<3; 103 i++){ 104 backwardSpeed = String("0" + backwardSpeed); 105 } 106 String turnLeftSpeed=String(turnLeft); 107 108 stringLength = int(turnLeftSpeed.length()); 109 for(int i=stringLength; i<3; 110 i++){ 111 turnLeftSpeed = String("0" + turnLeftSpeed); 112 } 113 String turnRightSpeed=String(turnRight); 114 115 stringLength = int(turnRightSpeed.length()); 116 for(int i=stringLength; i<3; 117 i++){ 118 turnRightSpeed = String("0" + turnRightSpeed); 119 } 120 String 121 cameraMountSend=String(cameraMountPosition); 122 stringLength = int(cameraMountSend.length()); 123 124 for(int i=stringLength; i<3; i++){ 125 cameraMountSend = String("0" + cameraMountSend); 126 127 } 128 // Combine all of the values into one string 129 String message=forwardSpeed+backwardSpeed+turnLeftSpeed+turnRightSpeed+cameraMountSend+buzzerState; 130 131 int textLength=int(message.length())+1; 132 char textSend[32]=""; 133 // Convert 134 the string into a char 135 message.toCharArray(textSend,textLength); 136 radio.write(&textSend, 137 sizeof(textSend)); 138}
Downloadable files
Car
Circuit for the car
Car
Car
Circuit for the car
Car
Remote
Circuit for the remote
Remote
Car
Circuit for the car
Car
Remote
Circuit for the remote
Remote
Comments
Only logged in users can leave comments