When I was start bike or blow horn then rc522 was disable I was trying shielding or use dc to dc isolator to isolate Arduino and sensor from battery of bike and also use inductor or x2 capacitor but it isn't work so what should I do?
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define LED_PIN_CORRECT 3
#define LED_PIN_WRONG 2
MFRC522 mfrc522(SS_PIN, RST_PIN);
// Define the correct card UID
byte correctCardUID[] = {0x23, 0x10, 0xC1, 0x1A, 0xEE};
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(LED_PIN_CORRECT, OUTPUT);
pinMode(LED_PIN_WRONG, OUTPUT);
}
void loop() {
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
byte buffer[4];
memcpy(buffer, mfrc522.uid.uidByte, 4);
if (compareUID(buffer, correctCardUID)) {
blinkLED(LED_PIN_CORRECT, 1); // Blink once for correct card
} else {
blinkLED(LED_PIN_WRONG, 5); // Blink 5 times for wrong card
Serial.print("Wrong card UID: ");
printUID(buffer); // Print UID of the wrong card
Serial.println();
}
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
}
bool compareUID(byte* uid1, byte* uid2) {
for (int i = 0; i < 4; i++) {
if (uid1[i] != uid2[i]) {
return false;
}
}
return true;
}
void blinkLED(int pin, int count) {
for (int i = 0; i < count; i++) {
digitalWrite(pin, HIGH);
delay(500);
digitalWrite(pin, LOW);
delay(500);
}
}
void printUID(byte* uid) {
for (int i = 0; i < 4; i++) {
Serial.print(uid[i], HEX);
Serial.print(" ");
}
}
Tell us about the try. Did you use shielded wires for all connections with the only one end of the shield connected to the bike chassis? Did you put all the Arduino and other electronics in a metal box connected to the bike chassis? Do you have bypass caps connected between all wires and ground on the Arduino?
Wire was shiI used an X2 capacitor and an inductor in a C-L-C method to reduce EMI. I also used multiple X2 capacitors in the circuit near the DC-DC isolator. First, I applied a C-L-C filter near the horn, and the second C-L-C was used in the circuit. This setup works perfectly fine if I don't connect the RC522 directly to the bike. I supply the horn and Arduino circuit with isolation from another battery, and when the horn blows, it doesn't affect the RC522. The problem only occurs when I connect it to the bike.
I used aluminum foil to shield the wire, but I didn't common shielded cable's shield. Instead, I applied shielding for each sensor's wire from end to end, but I haven't placed the Arduino circuit in a metal case. I also used an optocoupler and a DC-DC isolator, but the EMI doesn't affect the other sensors—only the RC522. Last night, I watched a YouTube video where the YouTuber's RC522 worked even after the bike was started.
If what you show in the picture is your idea of shielded wire, then no, that will be of no help. Use REAL shielded wire. Wire made with a braided wire over the inner wire insulation. Connect one end of the braided wire to the bike frame.
Making a solid electrical connection to aluminum foil is nearly impossible because of the oxide coating of the aluminum.
And put your Arduino and all other components inside a metal box and the box firmly connected to the bike frame
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
This should help:
To protect a bike's electronics from electromagnetic interference (EMI), especially if it's a modern bike with sensors, lights, or a GPS, there are several strategies you can employ. EMI can cause malfunctions or degradation in performance if not properly mitigated. Here are some approaches you can consider:
1. Shielding
Shielded cables: Use cables with shielding (like braided metal or foil wraps) to reduce the amount of EMI they emit or pick up.
Enclosures: Place sensitive electronics in metal or conductive enclosures (Faraday cages) to block external electromagnetic fields.
2. Grounding
Proper grounding: Ensure that all electronic components and their enclosures are properly grounded to prevent stray electromagnetic signals from affecting them. Grounding can direct EMI away from sensitive components.
3. Ferrite Beads
Ferrite beads: Install ferrite beads on cables that run to and from sensitive electronics. These components help suppress high-frequency EMI by dissipating it as heat.
4. Twisted Pair Cables
Twisted pair wiring: If you're running wires, use twisted pair cables for signal lines. The twisting helps cancel out EMI that would otherwise be picked up by the wires.
5. Capacitors and Filters
EMI filters: Install EMI filters (low-pass, high-pass, or band-stop) on power supply lines or signal lines to prevent high-frequency noise from reaching sensitive electronics.
Capacitors: Capacitors between power lines and ground can help smooth out high-frequency noise.
6. Distance from EMI Sources
Separation: Keep sensitive electronics as far away as possible from sources of EMI, such as motors, ignitions, and power cables.
7. Proper Cable Routing
Avoid running signal cables near power lines, ignition systems, or any high-current cables to reduce the possibility of picking up interference.
8. Use EMI-Resistant Components
Whenever possible, use components that are specifically designed to be resistant to EMI, such as EMI-hardened sensors, controllers, and processors.
9. Suppress Noise at the Source
Suppress ignition noise: Use resistor-type spark plugs or ignition leads with built-in suppression to reduce EMI from the bike’s engine and ignition system.
DC-DC converters: For bikes with electric systems, install noise-suppressed DC-DC converters to minimize EMI from power supplies.
By implementing a combination of these techniques, you can significantly reduce the impact of EMI on your bike’s electronics. If you need help with a specific part or scenario, feel free to provide more details!