Skip to main content
Question Protected by VE7JRO
appended answer 71197 as supplemental
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

I am using the pc usb power cable to power on the arduino and 2 accelerometers and one SG90 hobby servomotor. Would the best way power on the 1 servo with its own power supply ?

What power supply would you suggest for 1 servomotor?

When not connected to the pc, I use 9v battery to power on together the arduino and the one servomotor

thanks!


It is the part of the code for moving forward and backward in this locomotion system I came up with

https://github.com/marcob2178/Arduino-Based-Game-Locomotion

https://www.youtube.com/watch?v=OYTlF2GhXpQ

Sensors are mounted on shoes


I am using the pc usb power cable to power on the arduino and 2 accelerometers and one SG90 hobby servomotor. Would the best way power on the 1 servo with its own power supply ?

What power supply would you suggest for 1 servomotor?

When not connected to the pc, I use 9v battery to power on together the arduino and the one servomotor

thanks!


It is the part of the code for moving forward and backward in this locomotion system I came up with

https://github.com/marcob2178/Arduino-Based-Game-Locomotion

https://www.youtube.com/watch?v=OYTlF2GhXpQ

Sensors are mounted on shoes

Fixed code formatting and capitalization, removed duplicate text, added tag.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

Is there a reason why my arduino unoArduino Uno freezes after a few minutes of running with power coming from a usb cable connected to my pc?

Hi#include guys<GY6050.h>
#include Is<Wire.h>
#include there<VarSpeedServo.h>

#define aangle1 reason20
#define whyangle2 my90

#define arduinoSensor_BL unoA0
#define freezesSensor_BR afterA1

VarSpeedServo aservo;

GY6050 fewgyro1(0x68);
GY6050 minutesgyro2(0x69);

int ofX running= with0;
int powerY coming= from0;

int ay1_axis usb= cable0;
int connectedy2_axis to= my0;

int pcsensorBL;
int sensorBR;

int speed = 0;
int angle = 0;

int prev_y1_axis = 0;
int y1_hold = 0;
unsigned long timer;
int start = 1;
byte step = 0;
String steps , laststep;
int freq;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  gyro1.initialisation();
  gyro2.initialisation();
  delay(100);
  servo.attach(8);
  servo.write(90);
}

void loop() {
  y1_axis = gyro1.refresh('A', 'Y');
  y2_axis = gyro2.refresh('A', 'Y');
  sensorBL = analogRead(Sensor_BL);
  sensorBR = analogRead(Sensor_BR);

  //0 right - 90 centr - 180 left

  if (sensorBL > 250) {
    speed = map( sensorBL , 0 , 1023 , 0 , 255);
    if (sensorBL < 700) { //less pressure 90+20=110
      servo.write(95 , speed);
      angle = 95;
    }
    else if (sensorBL > 700) { //more pressre 90+90 = 180
      servo.write(105 , speed);
      angle = 105;
    }
  }
  else if (sensorBR > 250) {
    speed = map( sensorBR , 0 , 1023 , 0 , 255);
    if (sensorBR < 700) {
      servo.write(95 , speed);
      angle = 95;
    }
    else if (sensorBR > 700) {
      servo.write(105 , speed);
      angle = 105;
    }
  }
  else if ((start == 0 || millis() - timer > 800) && y1_axis > -90 && y1_axis < 20 && y2_axis > -90 && y2_axis < 20 && sensorBL < 10 && sensorBR < 20) //flat dead end no servo movement - center position - can we separate on different lines the pressure sensor and accell so that I can set the dead end value separately for the press sens and acc ?
  {
    servo.write( 85 , 15);
    //Serial.println("Servo goes to zero");
    start = 1;
    step = 0;
    angle = 0;
    steps = "0";
  }
  else if ((y1_axis < 60 & y1_axis >40) && (step == 0 || step == 2))
  {
    step = 1;
    steps = "1";
  }
  else if ((y2_axis < 55 & y2_axis > 40) && (step == 0 || step == 1))
  {
    step = 2;
    steps = "2";
  }

  if (!steps.equals(laststep)) {

    if ((step == 1 || step == 2) && millis() - timer <= 700) {
      if (freq > 1) {
        servo.write(70 , 20);
        angle = 70;
      }
      else {
        servo.write(78 , 20);
        angle = 78;
      }
      freq++;
    }
    else if ((step == 1 || step == 2 && millis() - timer > 750)) {
      servo.write(78 , 20);
      angle = 78;
      freq = 0;
    }

    timer = millis();
  }
  //Serial.println("Y1: " + String(y1_axis) + " Y2: " + String(y2_axis) + " S1: " + String(sensorBL) + " S2: " + String(sensorBR) + " Millis: " + String(millis() - timer) + " Step: " + String(steps) + " Last: " + String(laststep) + " Angle: " + String(angle));
  Serial.println("Millis: " + String(millis() - timer) + " Angle: " + String(angle));

  laststep = steps;

}

#include <GY6050.h> #include <Wire.h> #include <VarSpeedServo.h>

#define angle1 20 #define angle2 90

#define Sensor_BL A0 #define Sensor_BR A1

VarSpeedServo servo;

GY6050 gyro1(0x68); GY6050 gyro2(0x69);

int X = 0; int Y = 0;

int y1_axis = 0; int y2_axis = 0;

int sensorBL; int sensorBR;

int speed = 0; int angle = 0;

int prev_y1_axis = 0; int y1_hold = 0; unsigned long timer; int start = 1; byte step = 0; String steps , laststep; int freq;

void setup() { Serial.begin(9600); Wire.begin(); gyro1.initialisation(); gyro2.initialisation(); delay(100); servo.attach(8); servo.write(90); }

void loop() { y1_axis = gyro1.refresh('A', 'Y'); y2_axis = gyro2.refresh('A', 'Y'); sensorBL = analogRead(Sensor_BL); sensorBR = analogRead(Sensor_BR);

//0 right - 90 centr - 180 left

if (sensorBL > 250) { speed = map( sensorBL , 0 , 1023 , 0 , 255); if (sensorBL < 700) { //less pressure 90+20=110 servo.write(95 , speed); angle = 95; } else if (sensorBL > 700) { //more pressre 90+90 = 180 servo.write(105 , speed); angle = 105; } } else if (sensorBR > 250) { speed = map( sensorBR , 0 , 1023 , 0 , 255); if (sensorBR < 700) { servo.write(95 , speed); angle = 95; } else if (sensorBR > 700) { servo.write(105 , speed); angle = 105; } } else if ((start == 0 || millis() - timer > 800) && y1_axis > -90 && y1_axis < 20 && y2_axis > -90 && y2_axis < 20 && sensorBL < 10 && sensorBR < 20) //flat dead end no servo movement - center position - can we separate on different lines the pressure sensor and accell so that I can set the dead end value separately for the press sens and acc ? { servo.write( 85 , 15); //Serial.println("Servo goes to zero"); start = 1; step = 0; angle = 0; steps = "0"; } else if ((y1_axis < 60 & y1_axis >40) && (step == 0 || step == 2)) { step = 1; steps = "1"; } else if ((y2_axis < 55 & y2_axis > 40) && (step == 0 || step == 1)) { step = 2; steps = "2"; }

if (!steps.equals(laststep)) {

if ((step == 1 || step == 2) && millis() - timer <= 700) { if (freq > 1) { servo.write(70 , 20); angle = 70; } else { servo.write(78 , 20); angle = 78; } freq++; } else if ((step == 1 || step == 2 && millis() - timer > 750)) { servo.write(78 , 20); angle = 78; freq = 0; }

timer = millis(); } //Serial.println("Y1: " + String(y1_axis) + " Y2: " + String(y2_axis) + " S1: " + String(sensorBL) + " S2: " + String(sensorBR) + " Millis: " + String(millis() - timer) + " Step: " + String(steps) + " Last: " + String(laststep) + " Angle: " + String(angle)); Serial.println("Millis: " + String(millis() - timer) + " Angle: " + String(angle));

laststep = steps;

}

Is there a reason why my arduino uno freezes after a few minutes of running with power coming from a usb cable connected to my pc?

Hi guys. Is there a reason why my arduino uno freezes after a few minutes of running with power coming from a usb cable connected to my pc?

#include <GY6050.h> #include <Wire.h> #include <VarSpeedServo.h>

#define angle1 20 #define angle2 90

#define Sensor_BL A0 #define Sensor_BR A1

VarSpeedServo servo;

GY6050 gyro1(0x68); GY6050 gyro2(0x69);

int X = 0; int Y = 0;

int y1_axis = 0; int y2_axis = 0;

int sensorBL; int sensorBR;

int speed = 0; int angle = 0;

int prev_y1_axis = 0; int y1_hold = 0; unsigned long timer; int start = 1; byte step = 0; String steps , laststep; int freq;

void setup() { Serial.begin(9600); Wire.begin(); gyro1.initialisation(); gyro2.initialisation(); delay(100); servo.attach(8); servo.write(90); }

void loop() { y1_axis = gyro1.refresh('A', 'Y'); y2_axis = gyro2.refresh('A', 'Y'); sensorBL = analogRead(Sensor_BL); sensorBR = analogRead(Sensor_BR);

//0 right - 90 centr - 180 left

if (sensorBL > 250) { speed = map( sensorBL , 0 , 1023 , 0 , 255); if (sensorBL < 700) { //less pressure 90+20=110 servo.write(95 , speed); angle = 95; } else if (sensorBL > 700) { //more pressre 90+90 = 180 servo.write(105 , speed); angle = 105; } } else if (sensorBR > 250) { speed = map( sensorBR , 0 , 1023 , 0 , 255); if (sensorBR < 700) { servo.write(95 , speed); angle = 95; } else if (sensorBR > 700) { servo.write(105 , speed); angle = 105; } } else if ((start == 0 || millis() - timer > 800) && y1_axis > -90 && y1_axis < 20 && y2_axis > -90 && y2_axis < 20 && sensorBL < 10 && sensorBR < 20) //flat dead end no servo movement - center position - can we separate on different lines the pressure sensor and accell so that I can set the dead end value separately for the press sens and acc ? { servo.write( 85 , 15); //Serial.println("Servo goes to zero"); start = 1; step = 0; angle = 0; steps = "0"; } else if ((y1_axis < 60 & y1_axis >40) && (step == 0 || step == 2)) { step = 1; steps = "1"; } else if ((y2_axis < 55 & y2_axis > 40) && (step == 0 || step == 1)) { step = 2; steps = "2"; }

if (!steps.equals(laststep)) {

if ((step == 1 || step == 2) && millis() - timer <= 700) { if (freq > 1) { servo.write(70 , 20); angle = 70; } else { servo.write(78 , 20); angle = 78; } freq++; } else if ((step == 1 || step == 2 && millis() - timer > 750)) { servo.write(78 , 20); angle = 78; freq = 0; }

timer = millis(); } //Serial.println("Y1: " + String(y1_axis) + " Y2: " + String(y2_axis) + " S1: " + String(sensorBL) + " S2: " + String(sensorBR) + " Millis: " + String(millis() - timer) + " Step: " + String(steps) + " Last: " + String(laststep) + " Angle: " + String(angle)); Serial.println("Millis: " + String(millis() - timer) + " Angle: " + String(angle));

laststep = steps;

}

Is there a reason why my Arduino Uno freezes after a few minutes of running with power coming from a usb cable connected to my pc?

#include <GY6050.h>
#include <Wire.h>
#include <VarSpeedServo.h>

#define angle1 20
#define angle2 90

#define Sensor_BL A0
#define Sensor_BR A1

VarSpeedServo servo;

GY6050 gyro1(0x68);
GY6050 gyro2(0x69);

int X = 0;
int Y = 0;

int y1_axis = 0;
int y2_axis = 0;

int sensorBL;
int sensorBR;

int speed = 0;
int angle = 0;

int prev_y1_axis = 0;
int y1_hold = 0;
unsigned long timer;
int start = 1;
byte step = 0;
String steps , laststep;
int freq;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  gyro1.initialisation();
  gyro2.initialisation();
  delay(100);
  servo.attach(8);
  servo.write(90);
}

void loop() {
  y1_axis = gyro1.refresh('A', 'Y');
  y2_axis = gyro2.refresh('A', 'Y');
  sensorBL = analogRead(Sensor_BL);
  sensorBR = analogRead(Sensor_BR);

  //0 right - 90 centr - 180 left

  if (sensorBL > 250) {
    speed = map( sensorBL , 0 , 1023 , 0 , 255);
    if (sensorBL < 700) { //less pressure 90+20=110
      servo.write(95 , speed);
      angle = 95;
    }
    else if (sensorBL > 700) { //more pressre 90+90 = 180
      servo.write(105 , speed);
      angle = 105;
    }
  }
  else if (sensorBR > 250) {
    speed = map( sensorBR , 0 , 1023 , 0 , 255);
    if (sensorBR < 700) {
      servo.write(95 , speed);
      angle = 95;
    }
    else if (sensorBR > 700) {
      servo.write(105 , speed);
      angle = 105;
    }
  }
  else if ((start == 0 || millis() - timer > 800) && y1_axis > -90 && y1_axis < 20 && y2_axis > -90 && y2_axis < 20 && sensorBL < 10 && sensorBR < 20) //flat dead end no servo movement - center position - can we separate on different lines the pressure sensor and accell so that I can set the dead end value separately for the press sens and acc ?
  {
    servo.write( 85 , 15);
    //Serial.println("Servo goes to zero");
    start = 1;
    step = 0;
    angle = 0;
    steps = "0";
  }
  else if ((y1_axis < 60 & y1_axis >40) && (step == 0 || step == 2))
  {
    step = 1;
    steps = "1";
  }
  else if ((y2_axis < 55 & y2_axis > 40) && (step == 0 || step == 1))
  {
    step = 2;
    steps = "2";
  }

  if (!steps.equals(laststep)) {

    if ((step == 1 || step == 2) && millis() - timer <= 700) {
      if (freq > 1) {
        servo.write(70 , 20);
        angle = 70;
      }
      else {
        servo.write(78 , 20);
        angle = 78;
      }
      freq++;
    }
    else if ((step == 1 || step == 2 && millis() - timer > 750)) {
      servo.write(78 , 20);
      angle = 78;
      freq = 0;
    }

    timer = millis();
  }
  //Serial.println("Y1: " + String(y1_axis) + " Y2: " + String(y2_axis) + " S1: " + String(sensorBL) + " S2: " + String(sensorBR) + " Millis: " + String(millis() - timer) + " Step: " + String(steps) + " Last: " + String(laststep) + " Angle: " + String(angle));
  Serial.println("Millis: " + String(millis() - timer) + " Angle: " + String(angle));

  laststep = steps;

}
Source Link

arduino uno freezes

Is there a reason why my arduino uno freezes after a few minutes of running with power coming from a usb cable connected to my pc?

Hi guys. Is there a reason why my arduino uno freezes after a few minutes of running with power coming from a usb cable connected to my pc?

#include <GY6050.h> #include <Wire.h> #include <VarSpeedServo.h>

#define angle1 20 #define angle2 90

#define Sensor_BL A0 #define Sensor_BR A1

VarSpeedServo servo;

GY6050 gyro1(0x68); GY6050 gyro2(0x69);

int X = 0; int Y = 0;

int y1_axis = 0; int y2_axis = 0;

int sensorBL; int sensorBR;

int speed = 0; int angle = 0;

int prev_y1_axis = 0; int y1_hold = 0; unsigned long timer; int start = 1; byte step = 0; String steps , laststep; int freq;

void setup() { Serial.begin(9600); Wire.begin(); gyro1.initialisation(); gyro2.initialisation(); delay(100); servo.attach(8); servo.write(90); }

void loop() { y1_axis = gyro1.refresh('A', 'Y'); y2_axis = gyro2.refresh('A', 'Y'); sensorBL = analogRead(Sensor_BL); sensorBR = analogRead(Sensor_BR);

//0 right - 90 centr - 180 left

if (sensorBL > 250) { speed = map( sensorBL , 0 , 1023 , 0 , 255); if (sensorBL < 700) { //less pressure 90+20=110 servo.write(95 , speed); angle = 95; } else if (sensorBL > 700) { //more pressre 90+90 = 180 servo.write(105 , speed); angle = 105; } } else if (sensorBR > 250) { speed = map( sensorBR , 0 , 1023 , 0 , 255); if (sensorBR < 700) { servo.write(95 , speed); angle = 95; } else if (sensorBR > 700) { servo.write(105 , speed); angle = 105; } } else if ((start == 0 || millis() - timer > 800) && y1_axis > -90 && y1_axis < 20 && y2_axis > -90 && y2_axis < 20 && sensorBL < 10 && sensorBR < 20) //flat dead end no servo movement - center position - can we separate on different lines the pressure sensor and accell so that I can set the dead end value separately for the press sens and acc ? { servo.write( 85 , 15); //Serial.println("Servo goes to zero"); start = 1; step = 0; angle = 0; steps = "0"; } else if ((y1_axis < 60 & y1_axis >40) && (step == 0 || step == 2)) { step = 1; steps = "1"; } else if ((y2_axis < 55 & y2_axis > 40) && (step == 0 || step == 1)) { step = 2; steps = "2"; }

if (!steps.equals(laststep)) {

if ((step == 1 || step == 2) && millis() - timer <= 700) { if (freq > 1) { servo.write(70 , 20); angle = 70; } else { servo.write(78 , 20); angle = 78; } freq++; } else if ((step == 1 || step == 2 && millis() - timer > 750)) { servo.write(78 , 20); angle = 78; freq = 0; }

timer = millis(); } //Serial.println("Y1: " + String(y1_axis) + " Y2: " + String(y2_axis) + " S1: " + String(sensorBL) + " S2: " + String(sensorBR) + " Millis: " + String(millis() - timer) + " Step: " + String(steps) + " Last: " + String(laststep) + " Angle: " + String(angle)); Serial.println("Millis: " + String(millis() - timer) + " Angle: " + String(angle));

laststep = steps;

}