Robotics Module

I have encountered a problem with my Robotics: Building a Robot module where after following the instructions in the video about the code and uploading the code to the robot if I disconnect the USB cable and connect it to the adaptor it only executes the first function or the first two functions in the void Loop. For example if the code is
void loop()
{
stop()
delay(5000);
forward();
delay(5000);
reverse();
delay(5000);

and so on.
lf I upload this code to the robot, then when the USB cable is connected to the laptop it executes all functions as mentioned in the video thoroughly, but when I disconnect it from the laptop and power it with the adaptor, it waits for 5 seconds, moves forward for 5 seconds, waits again for 5 seconds and then moves forward for 5 seconds in an endless loop.

Kindly Assist.

Whenever you use the motor, try changing the polarity of the source you are giving, the motor will rotate in opposite directions (clockwise and anticlockwise) whenever you change polarity, the problem u are facing is the change in polarity itself, the code cannot do anticlockwise(reverse) if there is no polarity change, for this use a speed controller.

Sir is the speed controller the motor driver shield because I am using it and none of the other components in the kit have that name.

The speed controller is different than motor driver but if you are using motor driver then that should do the job of reversing as well as forwarding the bot.

Okay Sir, but the problem is that I had already connected the motor driver, while coding the robot, uploading the code and powering it.

Add delay of 500ms as below between switching directions command like forward,backward,right,left.

void loop()
{
stop()
delay(5000);
forward();
delay(5000);
stop();
delay(500);
reverse();
delay(5000);

I have been having 2 problems with the obstacle avoiding robot.

Firstly the detector detects the obstacle when it is too close therefore hitting it and then only reversing, secondly after detecting an obstacle for the first time, first after reversing the obstacle LED turns on and then after turning also it turns on even when there is not obstacle; it then ends up in an endless loop.

pls share ur code.try tuning the sensor for better sensitivity using potentiometer on the sensor

void innit()
{
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
pinMode (4, OUTPUT);
pinMode(7, OUTPUT);
}
void stop()
{
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
}
void forward()
{
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);
}
void reverse()
{
digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
}
void right()
{

 digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);

}
void left()
{
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, HIGH);
digitalWrite(7, LOW);

}
void leftf()
{
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);
}
void rightf()
{
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
}
void rl()
{
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
}
void rr()
{
digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
}
void setup() {
// put your setup code here, to run once:
pinMode(11, INPUT);
innit();
}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(11) == HIGH)
{
forward();
delay(500);
}
else
{
reverse();
delay(1000);
left();
delay(3000);
}
}

The pins which are set as high for certain functions in the above code are different from what is shown in the video but it follows orders such as forward, reverse, left, right etc. properly but the problem is that the LED on the sensor turns on after finishing any function such as forward, reverse etc. therefore it gets the message that there is an obstacle hence ending up in an endless loop.

Also, I tried adjusting the sensor sensitivity but the change is very minimal.

add a stop command followed by delay of 500ms after any command like fwd, reverse so that high current is not drawn by the motor due to instant switching causing voltage drop and reset.The output of TSOP sensor is low when obstacle is detected and high otherwise.

After uploading the code into the internet controlled robot, it only accepts the first two commands and then although on the screen 1 is displayed next to success, it does not follow any commands and remains stationary.
Here is my code:
#include <BoltIoT-Arduino-Helper.h>
void innit()
{
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
pinMode (4, OUTPUT);
pinMode(7, OUTPUT);
}
void stop()
{
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
}
void forward()
{
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);
}
void reverse()
{
digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
}
void right()
{

 digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);

}
void left()
{
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, HIGH);
digitalWrite(7, LOW);

}
void left_forward()
{
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);
}
void right_forward()
{
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
}
void rl()
{
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
}
void rr()
{
digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
}
String doMotion(String *data)
{
if(data[0] == “q”)
{
left_forward();
}
if(data[0] == “w”)
{
forward();
}
if(data[0] == “e”)
{
right_forward();
}
if(data[0] == “a”)
{
left();
}
if (data[0] == “s”)
{
stop();
}
if(data[0] == “d”)
{
right();
}
if(data[0] == “z”)
{
rl();
}
if(data[0] == “x”)
{
reverse();
}
if(data[0] == “c”)
{
rr;
}
}
void setup() {
// put your setup code here, to run once:
innit();
boltiot.begin(Serial);
boltiot.setCommandString(“doMotion”, doMotion, 1);
}

void loop() {
// put your main code here, to run repeatedly:
boltiot.handleCommand();
}

copy the code as it is from training and execute.one reason may be You have been rate limited. This means that you made more than 20 API calls within a minute. You will have to wait for 6 hours to be able to do the API call again.The code is working perfectly fine with api call.verify ur api key and bolt id