Making an Electric Skateboard with control

Hello i have done this project where i build a electric skateboard But need some help with coding and wiring of the controller

So the wiring of the skateboard look like this:

https://ggyazo.com/329882ddb9295fc7a328900f12ce2a61

The red board that is connected to the ESC is the receiver which look like this:

https://gyazo.com/1223b7fedae7738ed925673e3dcbaeb2

And to that there is a transmitter that look like this:

https://gyazo.com/3db8bc74223914219fe95c0e13a71b1c

And i wonder how i can connect and program the arduino together with the transmitter and receiver and with the help of a potentiometer control the speed of the motor on skateboard? and also how i can add a button to the controller so i can turn it on and off.

And also if i could add a led which activates when the battery percentage is like 20%

What are all the components i need to accomplish this and how do i do it??

I need a bit of help with the coding and wiring and how i can do this!

The basic coding i have is this:

#include <SoftwareServo.h> 
int potentiometer=A7;
int potval;
int curval;


SoftwareServo ESC;

void setup() {
 
 pinMode(potentiometer, INPUT);
 ESC.attach(9);    
 Serial.begin(9600);  
 curval=0;
 ESC.setMinimumPulse(800);
 ESC.setMaximumPulse(2000);
}

void loop() {

 potval=analogRead(potentiometer);
 potval=map(potval,0,1023,0,180);
 
 while(curval<potval){
   potval=analogRead(potentiometer);
   potval=map(potval,0,1023,0,180);
   curval=curval+1;
   ESC.write(curval);
   SoftwareServo::refresh();
   Serial.println(curval);
   delay(50);}

 while(curval>potval){
   potval=analogRead(potentiometer);
   potval=map(potval,0,1023,0,180);
   curval=curval-1;
   ESC.write(curval);
   SoftwareServo::refresh();
   Serial.println(curval);
   delay(50);}

   ESC.write(curval);
   SoftwareServo::refresh();
   Serial.println(curval);
}

Like would that work? or do i need to change/add anything?

So basically what i want is when i turn the potentiometer i change the speed of the motor on the skateboard!!

What do i need and how do i do it??

Ive also add another code in the attachments which is for a smartphone app if you maybe could change it a bit and use that!!

Help is very much appreciated Thanks ahead!

I now its a much info :smiley:

ArduinoNanowithDelay.ino (874 Bytes)

ESC_Serial_Controller.ino (1.26 KB)

Alright… first, put your code between code tags. Use the </> button in the editor. This way it is horrible to read.
Second, your pictures are not showing, that doesn’t really help

Okey sorry for that! it should now be fixed :smiley: