Hola! soy nueva con motores y tenia una duda ya que estoy haciendo una aplicación y las luces me funcionan bien cuando envió los strings desde esta pero cuando oprimo el botón de la aplicación de las luces, el stepper motor se acciona solo sin que yo le haya dado la señal, me podrían ayudar por favor.
Hello! I am new with motors and I had a question since I am making an application and the lights work fine for me when I send the strings from this but when I press the button of the application of the lights, the stepper motor activates itself without my having given it the signal, could you help me please.
#include <Stepper.h>
#include <RTClib.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 53
#define RST_PIN 5
#define SERVO_PIN A1
MFRC522 rfid(SS_PIN, RST_PIN);
Servo servo;
byte authorizedUID1[4] = {0xB7, 0x3B, 0x08, 0x52};
byte authorizedUID2[4] = {0x6B, 0x9A, 0x7C, 0x1B};
int angle = 0; // the current angle of servo motor
int rojo=13;
int led_azul=9;
int rele_luz=3;
int rele_ventilacion=5;
#include <Wire.h>
RTC_DS3231 rtc;
int hora_enc;
int min_enc;
int hora_apa;
int min_apa;
int step = 2038;
int motSpeed = 10;
//Stepper myStepper(step, 11,9,10,8);
Stepper myStepper(step, 8, 10, 9, 11);
int dt = 500;
void setup() {
myStepper.setSpeed(motSpeed);
pinMode(rele_luz,OUTPUT);
Serial.begin(9600);//puerto rtc
rtc.begin();
Wire.begin();
Serial1.begin(9600);//puerto bl
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
}
//rtc.adjust(DateTime(F(DATE), F(TIME)));//
//se ajusta solo 1 vez ya que si no se actualizaria
//cada vez que corrieramos el programa
SPI.begin(); // init SPI bus
rfid.PCD_Init(); // init MFRC522
servo.attach(SERVO_PIN);
servo.write(angle); // rotate servo motor to 0°
Serial.println("Tap RFID/NFC Tag on reader");
}
void loop() {
DateTime now = rtc.now();
delay(1000);
if(Serial1.available()){
String datos = Serial1.readString();
Serial.println(datos);
String peticion = Serial1.readString();
Serial.println(peticion);
if(datos.startsWith("<")){
datos.remove(0,1);
hora_enc = (datos.toInt()) ;
datos.remove (0,((datos.indexOf(","))+ 1));
min_enc = (datos.toInt()) ;
datos.remove (0,((datos.indexOf(","))+ 1));
hora_apa = (datos.toInt()) ;
datos.remove (0,((datos.indexOf(","))+ 1));
min_apa = (datos.toInt()) ;
datos.remove (0,((datos.indexOf(">"))+ 1));
}
if(datos.indexOf("encender_luz")){
digitalWrite(rele_luz,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
if(datos.indexOf("apagar_luz")){
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
if(datos.indexOf("b")){
myStepper.step(step);
}
if(datos.indexOf("n")){
myStepper.step(-step);
}
}