Skill Dev IV: Working with Motors and Actuators

Made by Peng Dou

Drive a DC motor

Created: December 1st, 2022

0

Outcome

    • As the code is excuted, the motor will be driven.

0
0

Process

I connected the circuit as required. Also I attached an extra 5V power source. I used the code from the sample and everything worked as expected.

0
int solPin = D2;

bool shouldActivate = false;

void setup()
{
  pinMode(solPin, OUTPUT);
  Particle.function( "activate", activateSolenoid );
}

void loop()
{
  if( shouldActivate ){
    doSolenoid(  );
    shouldActivate = false;

  }
  delay( 100 );

}

void doSolenoid(  ){
  for( int i = 0; i < 5; i++ )
  {
    digitalWrite(solPin, HIGH);
    delay( 100 ) ;
    digitalWrite(solPin, LOW);
    delay( 100 );
  }
}


int activateSolenoid( String command ){
  shouldActivate = true;
  return 1;

}
Click to Expand
0

Reflection

When I was helping other with this project, I found out sometimes the connection of the cable was not stable, and it was hard to debug. Thus, I used multimeter for that, and it really helped a lot!

x