Friday, August 9, 2024

Servo at different angle (Sunil)

 #include <Servo.h>


Servo myServo;  // Create a servo object


void setup() {

  myServo.attach(9);  // Attach the servo to pin 9

}


void loop() {

  myServo.write(30);  // Rotate to 30 degrees

  delay(1000);        // Wait for a second


  myServo.write(60);  // Rotate to 60 degrees

  delay(1000);        // Wait for a second


  myServo.write(90);  // Rotate to 90 degrees

  delay(1000);        // Wait for a second


  myServo.write(120);  // Rotate to 120 degrees

  delay(1000);         // Wait for a second


  myServo.write(180);  // Rotate to 180 degrees

  delay(1000);         // Wait for a second

}


Thursday, August 8, 2024

Smart dustbin Sunil

 #include <Servo.h>


const int trigPin = 9;

const int echoPin = 10;

const int servoPin = 11;

const int detectionDistance = 50; // Distance in cm to detect an object

Servo myServo;


void setup() {

  Serial.begin(9600);

  pinMode(trigPin, OUTPUT);

  pinMode(echoPin, INPUT);

  myServo.attach(servoPin);

  myServo.write(0); // Initial position of the servo

}


void loop() {

  long duration, distance;

  digitalWrite(trigPin, LOW);

  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);


  duration = pulseIn(echoPin, HIGH);

  distance = duration * 0.034 / 2;


  Serial.print("Distance: ");

  Serial.println(distance);


  if (distance < detectionDistance) {

    myServo.write(120); // Rotate servo to 120 degrees

  } else {

    myServo.write(0); // Return servo to 0 degrees

  }


  delay(500);

}


MUD Three Mode operation Manual Automatic GPS

 Code for three mode operation: /*   3-Mode Headlight Controller   - Manual mode (driver uses a toggle to pick high/low)   - Auto mode (LDR...