Testing Cytron motorcontroller with Arduino

I bought four motor contollers from the net, and I tested them with an Arduino. Here is the list of the electrics:
Arduino, Cytron , mercedes screen-wiper motor, potentialmeter.

We made an repositioning device as you can see in this video:

Don’t listen to the backgroundsound, he is trying to comment what you can see but … at least he tried it 🙂

Here you can see the code running on the Arduino:

int sensorValue = 0; 
const int analogInPin = A0; 
const int PwmPin = 5;
const int Direction = 2; 
int pos = 60;    // variable to store the servo position 
 
void setup() 
{ 
    Serial.begin(115200); 
    pinMode(PwmPin, OUTPUT);
    pinMode(Direction, OUTPUT);
} 
 
void loop() 
{ 
  if (Serial.available() > 0) {
   
    pos=Serial.read();
    Serial.print("pos: ");
     Serial.println(pos);
  }
  //myservo2.write(pos);
  delay(15);
  sensorValue = analogRead(analogInPin)/4;
  Serial.print("sensorValue: ");
  Serial.println(sensorValue);
  byte dataToWrite=0;
  if (pos>sensorValue){
       dataToWrite=pos-sensorValue;
      
      digitalWrite(Direction,HIGH);
      
  }else{
    dataToWrite=sensorValue-pos;  
    digitalWrite(Direction,LOW);
  }
  Serial.print("dataToWrite: ");
  Serial.println(dataToWrite);
  if (dataToWrite>245)dataToWrite=245;
  else if (dataToWrite<10) dataToWrite=0;
  analogWrite(PwmPin,dataToWrite );
} 

What’s happening?

You can send an position from 0 to 240, and if you try to move the object it will return it is original position after some beep. The Arduino is connected with the motor controller through PWM, and with the potentiometer. There is a shield on the Arduino, originaly it was made for servos, communicating with PWM so it is not necessary to be this complex.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s