Controlling rc car with arduino uno wifi

I have created a code with my beginner knowledge for an rc car, I have an step motor for rear wheels and servo for the front, the code may be a little confusing as i have combined multiple codes, I have created a basic html website and with that we can control the car but its not great, Main problem is that website glitches out after pressing multiple buttons at same time and than i have to wait for it to get together again. I want to be able to hold down "naprid" button and car to keep going forward until i stop holding it, rn when i press "naprid" button it goes for a few seconds than stops and i have to press the button again, same for servo, when i press for example left, i have to have another button to center it.

Summary: I want to have an responsive code for an rc car with a step and servo motor


#include <SPI.h>
#include <WiFiNINA.h>
#include <Stepper.h>
#include <Servo.h>

char ssid[] = "Gas";
char pass[] = "gasermali";
int keyIndex = 0;
int servoPin = 6;                                                                                                                                                                      


#define IN1  2
#define IN2  3
#define IN3  4
#define IN4  5

int status = WL_IDLE_STATUS;
WiFiServer server(80);
Servo Servo1;
const int stepsPerRevolution = 2038;
Stepper myStepper = Stepper(stepsPerRevolution, 2, 4, 3, 5);


String readString;

void setup() {
  Servo1.attach(servoPin);
  WiFiDrv::pinMode(26, OUTPUT); //define red pin
  WiFiDrv::pinMode(27, OUTPUT); //define blue pin
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(9600);
  

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    WiFiDrv::analogWrite(27, 25);
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  WiFiDrv::analogWrite(27, 0);    
  }
  server.begin();
  WiFiDrv::analogWrite(27, 0);

  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  WiFiDrv::analogWrite(26, 25);
}

void loop() {
  WiFiClient client = server.available();
  if (client)
  {
    Serial.println("new client");

    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();
        if (readString.length() < 100)
        {
          readString += c;
          Serial.write(c);
          
          if (c == '\n') {
            client.println("<table style=\"width:100%\"\"><tr><th></th><th><a href=\"/?naprid\"\"><button><p style = \"font-size:130px\"\">....^....</p></button></a></th><th></th></tr><tr><th><a href=\"/?livo\"\"><button><p style = \"font-size:130px\"\">....<....</p></button></a></th><th><a href=\"/?ravno\"\"><button><p style = \"font-size:130px\"\">....^....</p></button></a></th><th><a href=\"/?desno\"\"><button><p style = \"font-size:130px\"\">....>....</p></button></th></tr><tr><th></th><th><a href=\"/?rikverc\"\"><button><p style = \"font-size:130px\"\">Rikverc</p></button></a></th><th></th></tr><tr><th><a href=\"/?lighton\"\"><button><p style = \"font-size:130px\"\">LED_B_ON</p></button></a></th><th><a href=\"/?lightoff\"\"><button><p style = \"font-size:130px\"\">LED_B_OFF</p></button></a></th><th><a href=\"/?but1\"\"><button><p style = \"font-size:130px\"\">But1</p></button></a></th></tr><tr><th><a href=\"/?but2\"\"><button><p style = \"font-size:130px\"\">But2</p></button></a></th><th><a href=\"/?but3\"\"><button><p style = \"font-size:130px\"\">But3</p></button></a></th><th><a href=\"/?but49\"\"><button><p style = \"font-size:130px\"\">But4</p></button></a></th></tr>");  

            delay(1);
            
            if(readString.indexOf("?lighton") > 0)
            {
              digitalWrite(LED_BUILTIN, HIGH);
              delay(1);
            }
            else{
              if(readString.indexOf("?lightoff") > 0)
              {
                digitalWrite(LED_BUILTIN, LOW);   
                delay(1);
              }
              else{
                if(readString.indexOf("?naprid") > 0)
                {
                  myStepper.setSpeed(15);
                  myStepper.step(-stepsPerRevolution);; 
                  delay(1);
                }
                else{
                  if(readString.indexOf("?livo") > 0)
                  {
                    Servo1.write(85);   
                    delay(1);
                  }
                  else{
                    if(readString.indexOf("?desno") > 0)
                    {
                      Servo1.write(10);  
                      delay(1);
                    }
                    else{
                      if(readString.indexOf("?rikverc") > 0)
                      {
                        myStepper.setSpeed(15);
                        myStepper.step(stepsPerRevolution);
                      }
                      else{
                        if(readString.indexOf("?but1") > 0)
                        {
                          digitalWrite(4, HIGH);   
                          delay(1);
                        }
                        else{
                          if(readString.indexOf("?but2") > 0)
                          {
                            digitalWrite(4, LOW);   
                            delay(1);
                          }
                          else{
                            if(readString.indexOf("?but3") > 0)
                            {
                              digitalWrite(5, HIGH);   
                              delay(1);
                            }
                            else{
                              if(readString.indexOf("?but4") > 0)
                              {
                                digitalWrite(5, LOW);   
                                delay(1);
                              }
                              else{
                              if(readString.indexOf("?ravno") > 0)
                              {
                                Servo1.write(45);   
                                delay(1);
                              }
                              }
                            }
                          }
                        }
                      }
                    } 
                  }
                }
              }
            }
            readString="";

            delay(1);
            client.stop();
            Serial.println("client disonnected");
          }
        }
      }
    }
  }
}

I have used this video for all the wifi nina stuff: Arduino Uno WiFI Turn LED On and Off - YouTube

I will probably end up buying the bluetooth module if this doesent work out.

Thank you for your help.

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