MicroST
Published © GPL3+

Control a 220VAC Universal AC Motor with Arduino

How to drive an universal AC motor (washing machine) with Arduino and the MST_K07_CL.

IntermediateShowcase (no instructions)27,545
Control a 220VAC Universal AC Motor with Arduino

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 4.75k ohm
Resistor 4.75k ohm
×1
Capacitor 10 µF
Capacitor 10 µF
×1
MST_K07_CL universal AC motor torque control
×1
VBOC.US PC817 optoisolator
×1

Story

Read more

Schematics

ARDUINO and MST_K07_CL wire connection

see wire connection

Code

CODE

Arduino
To control the motor with the Arduino Mega board (you can also use other cards like the nano version) you need to load the following code using the IDE software. Once the Arduino is connected to the PC and to the isolation board, use the IDE software serial monitors to control the motor using the commands:

1) a = switch the motor on at the speed already preset by the rxx command

2) s = turn off the motor

3) rxx: set the speed value (from 0 to 100) (for example r51 commands an adjustment to 51% of the maximum speed
[code]

/*PROGRAMMA CONTROLLO DEL REGOLATORE MST_K07 TRAMITE INTERFACCIA SERIALE BIDIREZIONALE
 
  I comandi accettati su monitor seriale sono i seguenti:
 
  a -  accende il MOTORE
  s -  spenge il MOTORE
  q - richiede lo stato del MOTORE. 
      Possibili risposte:
      MOTORE acceso con regolazione xxx %
      MOTORE spento
      Regolazione impostata al xxx%
  r xxx - scrive un valore di regolazione in %. Possibili
  valori per "xxx" vanno da 0 a 100. Gli spazi sono ignorati.
  I caratteri accettati sono solo quelli numerici (da 0 a 9).
*/

//pin
const byte vcnt = 13; //pin di output pwm

//variabili globali
byte regolazione = 0;  //contiene il valore in % del pwm sul pin 13
int start =0;          // abilita la accensione del regolatore
void setup() {
  pinMode(vcnt,OUTPUT);
  analogWrite(vcnt, regolazione);
  Serial.begin(9600); // apro la seriale
  delay(1000); //attendo che l'utente faccia altrettanto
  Serial.println(F("Interfaccia Seriale Pronta ")); //sono pronto
  Serial.println(F(" a= accensione; s= spegnimento; rxxx = regolazione al xxx%; q= status motore")); 
  
}

//programma principale
void loop() {
  int lettura; //contiene il valore di PWM letto dalla seriale
  unsigned long tempMillis; //serve per il timeout sulla ricezione del valore di PWM
  byte caratteri; //contiene il numero di caratteri ricevuti
  byte tempChar; //contiene il carattere letto

  //controllo se c'è qualcosa in arrivo sulla seriale
  if (Serial.available()) {
    byte command = Serial.read(); //leggo il primo byte
    switch (command) { //controllo che sia un comando valido
      case 'a': //accendo il MOTORE
        //;regolazione = 100;
        start =1;
        analogWrite(vcnt, start*regolazione*255/100);
        Serial.print(F("MOTORE"));
        Serial.print(F(" acceso con regolazione al "));
        Serial.print(regolazione, DEC);
        Serial.println("%");
        break;
      case 's': //spengo il MOTORE
        start=0;
        analogWrite(vcnt, 0);
        Serial.println(F("MOTORE spento"));
        break;
      case 'q': //l'utente vuole lo stato del MOTORE
        Serial.print(F("MOTORE "));
        if (start == 0) {
          Serial.print(F("spento"));
        } else if (start == 1) {
          Serial.print(F("acceso"));
        } 
          Serial.print(F(" regolazione al "));
          Serial.print(regolazione, DEC);
          Serial.println("%");
        
        break;
      case 'r': //imposto il PWM sul MOTORE
        lettura = 0;
        tempMillis = millis();
        caratteri = 0;
        //mi servono altri caratteri
        do {
          if (Serial.available()) {
            tempChar = Serial.read();
            caratteri++;
            if ((tempChar >= 48) && (tempChar <= 57)) { //è un numero? ok
              lettura = (lettura * 10) + (tempChar - 48);
            } else if ((tempChar == 10) || (tempChar == 13)) {
              //con invio e/o nuova linea esco
              break;
            }
          }
          //esco per timeout, per un valore di PWM maggiore di 255
          //oppure per troppi caratteri senza senso ricevuti
        } while ((millis() - tempMillis < 500) && (lettura <= 100) && (caratteri < 10));
        //se il valore di PWM è valido, lo imposto sul pin
        if (lettura <= 100) {
          regolazione = lettura;
          analogWrite(vcnt, start*regolazione*255/100);
          Serial.print(F("regolazione impostata a "));
          Serial.print(regolazione, DEC);
          Serial.println("%");
         }
        break;
    }
    //svuoto il buffer da eventuali altri caratteri che non mi servono più
    while (Serial.available()) {
      byte a = Serial.read();
    }
  }
}
[/code]

Credits

MicroST

MicroST

12 projects • 20 followers
Electronic is my life passion...

Comments