Second approach. Externally powered engine

August 28th, 2022 Categories: Arduino

In order to externally power the engines I’ll use a 8-battery rechargeable pack that I bought long time ago for a led strip. This pack offers 1.2*8=9.6V and 2.3mAh when it’s totally charged. I welded a power jack plug to power Arduino, but it’ll be more helpful powering batteries, so I grabbed a male power jack to connect it, the protoboard will be connected with 2 stripped cables.

The scheme will be this one reported in this arduino forum https://forum.arduino.cc/index.php?topic=256290.0. He says that it’s not working, but it’s working perfectly for me and it seems that the transistor and diode are not heating up, so I’ll go ahead with this to test 😀

The code will be similar to the one in the pdf from the 17th exercise in the Arduino starter pack that I’ve used in previous iterations. It’ll just change the engines speed by emitting values (from 0 to 254) through serial port.

//Global variables
int motor1Pin = 3;
int motor2Pin = 5;

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

  //Begin serial port communication
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 254");
} 
 
//Main loop
void loop() 
{ 
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed < 255)
    {
      analogWrite(motor1Pin, speed);
      analogWrite(motor2Pin, speed);
    }
  }
} 

So I already have 2 wheels running, now it’ll be great to be able to change the direction to go backwards, I could achieve it by using the L293D chip that I got in the Arduino starter kit, so that will be the next iteration

Tags:
No comments yet.

Leave a Comment

Solve this *