

This circuit integrates an Arduino UNO microcontroller with various sensors and modules, including an RFID reader, an ultrasonic sensor, a stepper motor driver, a limit switch, and a power supply. The Arduino UNO controls the components and processes data from the sensors to perform specific tasks.
Arduino UNO
A4988 Stepper Motor Driver Carrier
Limit Switch 3wires
12v Power Supply
HC-SR04 Ultrasonic Sensor
Bipolar Stepper Motor (NEMA 17)
RFID-RC522
#include <NewPing.h>
#include <SPI.h>
#include <MFRC522.h>
const int stepPin = 3;
const int dirPin = 4;
const int UltrasonicPin = 6;
const int EndstopPin = 7;
const int Echo_Pin = 5;
const int MaxDistance = 200;
const int RST_PIN = 9; // Pin 9 para el reset del RC522
const int SS_PIN = 10; // Pin 10 para el SS (SDA) del RC522
MFRC522 mfrc522(SS_PIN, RST_PIN); // Crear instancia del MFRC522
byte validKey1[4] = { 0x40, 0x3E, 0x45, 0x39 }; // Clave valida
//Función para comparar dos vectores
bool isEqualArray(byte* arrayA, byte* arrayB, int length)
{
for (int index = 0; index < length; index++)
{
if (arrayA[index] != arrayB[index]) return false;
}
return true;
}
NewPing sonar(UltrasonicPin, Echo_Pin, MaxDistance);
void setup() { //Bucle Setup
Serial.begin(9600);
SPI.begin(); // Iniciar SPI
mfrc522.PCD_Init(); // Iniciar MFRC522
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(EndstopPin, INPUT);
}
void loop() { //Bucle Loop
ultrasonidos(); // Codigo de ultrasonidos
rfid(); // Codigo del lector de tarjetas
//stepper(); // Codigo del motor
int switchState = digitalRead(EndstopPin);
if(switchState == LOW) {
// switch is closed
Serial.println("Switch is Closed");
} else if(switchState == HIGH) {
// switch is open
Serial.println("Switch is Open");
}
}
void ultrasonidos(){
delay(100); // esperar 50ms entre pings
Serial.print(sonar.ping_cm()); // obtener el valor en cm (0 = fuera de rango)
Serial.println("cm");
if (sonar.ping_cm()>3 && sonar.ping_cm()<15) {
Serial.println("cocheeeeee");
}
}
void rfid() {
// Detectar tarjeta
if (mfrc522.PICC_IsNewCardPresent())
{
Serial.println("Tarjeta detectada");
//Seleccionamos una tarjeta
if (mfrc522.PICC_ReadCardSerial())
{
// Comparar ID con las claves válidas
if (isEqualArray(mfrc522.uid.uidByte, validKey1, 4))
Serial.println("Tarjeta valida");
else
Serial.println("Tarjeta invalida");
// Finalizar lectura actual
mfrc522.PICC_HaltA