0% found this document useful (0 votes)
2 views4 pages

Codes (Robotics)

The document contains Arduino code for controlling a servo motor based on potentiometer input, measuring distance using an ultrasonic sensor, and detecting motion with a PIR sensor. It includes setup and loop functions for each component, with appropriate pin configurations and readings. The code demonstrates basic interactions with hardware components using the Arduino platform.

Uploaded by

Sidharth Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Codes (Robotics)

The document contains Arduino code for controlling a servo motor based on potentiometer input, measuring distance using an ultrasonic sensor, and detecting motion with a PIR sensor. It includes setup and loop functions for each component, with appropriate pin configurations and readings. The code demonstrates basic interactions with hardware components using the Arduino platform.

Uploaded by

Sidharth Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <Servo.

h>

Servo servoMotor;

int potPos;

void setup()

servoMotor.attach(9);

void loop ()

potPos = map(analogRead(A0), 0, 1023, 0, 180);

servoMotor.write(potPos);

delay(10);

}
int distanceThreshold = 0;

int cm=0;

int inches=0;

int traveltime=0;

long readUltrasonicDistance (int triggerPin, int echoPin)

pinMode(triggerPin, OUTPUT); //Clear the trigger

digitalWrite(triggerPin, LOW);

delayMicroseconds(2);

digitalWrite(triggerPin, HIGH);

delayMicroseconds(10);

digitalWrite(triggerPin, LOW);

pinMode(echoPin, INPUT);

return pulseIn(echoPin, HIGH);

void setup()

Serial.begin(9600);

void loop()

distanceThreshold = 0;

traveltime = readUltrasonicDistance(7,6);

cm = 0.0173*traveltime+0.5716;

Serial.println(cm);

}
int PIRINPUT = 0;

void setup()

pinMode(10, INPUT);

pinMode(11, OUTPUT);

void loop()

PIRINPUT = digitalRead(10);

if(PIRINPUT == HIGH)

digitalWrite(11, HIGH);

else

digitalWrite(11, LOW);

delay(1000); // Wait for 1000 millisecond(s)

You might also like