0% found this document useful (0 votes)
222 views3 pages

GSM Based Stepper Motor Control

This Arduino code controls a stepper motor connected to an A4988 motor driver. It uses an SMS SIM800L module to receive SMS commands ("kanan", "kiri", "off") to control the direction of the stepper motor. When it receives an SMS with one of the commands, it will print the SMS to the serial monitor and spin the motor in the corresponding direction (clockwise, counterclockwise, or off) for 200 steps. It initializes the SIM800L module and sets the SMS mode before entering a loop to continuously check for incoming SMS commands and control the motor accordingly.

Uploaded by

AriPermana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
222 views3 pages

GSM Based Stepper Motor Control

This Arduino code controls a stepper motor connected to an A4988 motor driver. It uses an SMS SIM800L module to receive SMS commands ("kanan", "kiri", "off") to control the direction of the stepper motor. When it receives an SMS with one of the commands, it will print the SMS to the serial monitor and spin the motor in the corresponding direction (clockwise, counterclockwise, or off) for 200 steps. It initializes the SIM800L module and sets the SMS mode before entering a loop to continuously check for incoming SMS commands and control the motor accordingly.

Uploaded by

AriPermana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Arduino Code - Mengontrol Motor Stepper A4988

// Define pin connections & motor's steps per revolution


const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;

void setup()
{
// Declare pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);

// Spin motor slowly


for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(1000); // Wait a second

// Set motor direction counterclockwise


digitalWrite(dirPin, LOW);

// Spin motor quickly


for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000); // Wait a second
}

1
PROJECT SMS SIM 800L WITH MOTOR STEPPER <By : Toko Tronik>

#include <SoftwareSerial.h>
SoftwareSerial gsm(2,3); // Rx/Tx wavecom di pin 2 dan 3
String sms = "";
char str;
const int stepPin = 3;
const int dirPin = 4;
int flag = 0;

void setup() {
delay(20000);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
Serial.begin(9600);
gsm.begin(9600); // init wavecom dg baudrate 9600
delay(3000);
gsm.println("AT+CMGF=1"); // Set mode sms
delay(500);
Get_sms(); // Baca respon gsm wavecom
if(sms.indexOf("OK") >= 0) { // Jika respon OK
Serial.println("OK");
sms="";
}
else {
Serial.println("Gagal");
sms="";
while(1);
}
delay(2000);
gsm.println("AT+CNMI=1,2,0,0,0"); // Set mode sms
delay(500);
Get_sms(); // Baca respon gsm wavecom
if(sms.indexOf("OK") >= 0) { // Jika respon OK
Serial.println("OK");
sms="";
}
else {
Serial.println("Gagal");
sms="";
while(1);
}
delay(2000);
}

void loop() {

2
Get_sms();
if(sms.indexOf("kanan") >= 0) {
flag = 1;
Serial.println(sms);
Serial.println("Putar Kanan");
sms = "";
} else if(sms.indexOf("kiri") >= 0) {
flag = 2;
Serial.println(sms);
Serial.println("Putar Kiri");
sms = "";
} else if(sms.indexOf("off") >= 0) {
flag = 0;
Serial.println(sms);
Serial.println("OFF");
sms = "";
}

if(flag==1) {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
} else if(flag==2) {
digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
}
}

void Get_sms() {
while(gsm.available()>0) {
str = (char)gsm.read();
sms += String(str);
Serial.write(str);
}
}

You might also like