What It Does (Yeh Kya Karta Hai?)
Factories mein bari machines ke sath hamesha ek Laal Button (Red Button) hota hai. Agar koi haadsa honay wala ho, to usay daba kar machine ko usi waqt rok diya jata hai. Is project mein:
- Normal: Servo Motor lagataar 0 se 180 degree ghoomti rahegi (Kaam chal raha hai).
- Emergency: Jaise hi Button dabaya, Servo wahin ruk jayegi (Stop). Button chorne par dobara kaam shuru hoga.
Components Required
- Arduino Uno
- Servo Motor (SG90)
- Push Button
- Jumper Wires (M/M)
Wiring (Taarein Jorna)
Hum Button ke liye phir se Internal Resistor (Smart Wiring) use karenge taake connection simple rahe.
A. Servo Motor:
- Brown (GND): Arduino GND
- Red (VCC): Arduino 5V
- Orange (Signal): Arduino Pin 9
Push Button (Emergency Switch):
- Pehli Taang: Arduino GND
- Dusri Taang: Arduino Pin 2
- (Button ki cross wiring na karein, same side wali taangein use karein)
Code
Yeh code thora special hai. Ismein hum Servo ko ghumayenge, lekin har qadam par check karenge ke “Kya button dabaya gaya?”
/*
* Project 28: Emergency Stop System
* Platform: PlzPapa Robotic Kit
* * Logic: Servo moves 0-180 continuously.
* If Button is pressed (LOW) -> Stop moving immediately.
*/
#include <Servo.h>
Servo myServo; // Servo ka naam
const int buttonPin = 2; // Emergency Button
const int servoPin = 9; // Servo Motor
int pos = 0; // Servo ki current position
void setup() {
myServo.attach(servoPin);
// Button ke liye Internal Pull-up (Bina resistor ke)
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// Machine Forward Jaa rahi hai (0 se 180)
for (pos = 0; pos <= 180; pos += 1) {
if (checkEmergency()) return; // Agar button dabaya to ruk jao
myServo.write(pos);
delay(15); // Speed control
}
// Machine Wapis Aa rahi hai (180 se 0)
for (pos = 180; pos >= 0; pos -= 1) {
if (checkEmergency()) return; // Agar button dabaya to ruk jao
myServo.write(pos);
delay(15);
}
}
// Yeh function check karta hai ke kya button daba hua hai?
bool checkEmergency() {
// Button dabane par value LOW hoti hai (Internal Pullup ki wajah se)
if (digitalRead(buttonPin) == LOW) {
Serial.println("EMERGENCY STOP ACTIVATED!");
// Jab tak button daba hua hai, yahin rukay raho (Loop freeze)
while(digitalRead(buttonPin) == LOW) {
// Machine is stopped holding position
delay(10);
}
Serial.println("System Resumed...");
return true; // Batao ke emergency thi
}
return false; // Sab normal hai
}Kese Check Karein (Testing)
- System On: Jaise hi power denge, Servo motor left-right (wipe) karna shuru kar degi. Yeh normal operation hai.
- Stop: Ab Button ko daba kar rakhein.
- Result: Servo motor foran usi jagah ruk jani chahiye jahan wo thi. Wo hilna band kar degi.
- Resume: Button chor dein, Motor wapis chalna shuru ho jayegi.
