First approach. Arduino powered engine

August 16th, 2022 Categories: Arduino


With the PN2222A transistor issue solved I was finally able to start programming, that was what I was looking for initially. I added one wheel to the engine and checked the voltage (4.54V max with a 1KOhm resistance). It’s really slow, this won’t move the whole car kit (500g).

I followed the scheme from the project 17 in the pdf included in the aliexpress Arduino starter kit that I talked about in the previous iteration, but I changed the order of base, collector and emitter this time in order to fit my special transistor. As it was more or less working, I added another wheel and another circuit with another transistor to move it.

With just one wheel it started to move at 1.5V, equivalent to 100-110 value by PWM, but when I added one more wheel it needed twice the voltage, so I tried with 200. When moving two wheels at the same time it didn’t have enough power, so I created this program to alternate first one wheel and then the other. The exact behaviour would be: first wheel starts moving from 120 to max (254) within 5 seconds, it will keep this speed for 2 more seconds, then this wheel will stop and the next wheel will repeat the same process, starting all over again when this second wheel will stop.

//Global variables
const int motor1Pin = 3;
const int motor2Pin = 5;
const int maxSpeed = 254;

//Initial setup
void setup()
{
  //Initializing output
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
}

//Main loop
void loop()
{
  accelerate(motor1Pin, 120, maxSpeed, 5); //Accelerate the motor 1, from 120 to maxSpeed in 5 seconds
  delay(2000);
  analogWrite(motor1Pin, 0);
  
  accelerate(motor2Pin, 120, maxSpeed, 5); //Accelerate the motor 2, from 120 to maxSpeed in 5 seconds
  delay(2000);
  analogWrite(motor2Pin, 0);
}

//Accelerate the motor from currentSpeed to maxSpeed in n seconds
void accelerate(int motor, int fromSpeed, int toSpeed, int sec)
{
  int initialFromSpeed = fromSpeed;
  for (; fromSpeed <= toSpeed; fromSpeed++)
  {
      analogWrite(motor, fromSpeed);
      delay((sec * 1000)/(toSpeed - initialFromSpeed));
  }  
}

Well, it works, but it doesn’t, in the next iteration I’ll power the engines separately so Arduino will only change the transistor bases.

Tags: ,
No comments yet.

Leave a Comment

Solve this *