Commit ac6624fb authored by sonaraju's avatar sonaraju
Browse files

Updated main_with_motor.ino- added 3rd US and 2nd motor

parent fd8c7a5f
const int trigPin = 13;
const int echoPin = 12;
const int trigPin = 12;
const int echoPin = 11;
const int trigPin2 = 9;
const int echoPin2 = 8;
const int trigPin2 = 8;
const int echoPin2 = 9;
const int trigPin3 = 5;
const int echoPin3 = 4;
const int motor = 3;
const int motor1 = 3;
const int motor2 = 2;
const int button = 13;
//const int button = 13;
const int potentiometer = A0;
//const int potentiometer = A0;
long duration3;
long duration2;
long duration;
int distance;
int distance2;
int distance3;
int volume;
int volumeScaled;
//void setUS(int trigPin, int echoPin) {
//pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
//pinMode(echoPin, INPUT);
//}
void setup() {
//US1
......@@ -30,54 +40,65 @@ pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(trigPin2, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin2, INPUT); // Sets the echoPin as an Input
pinMode(potentiometer, INPUT);
pinMode(button, INPUT_PULLUP);
pinMode(motor, OUTPUT);
//US3
pinMode(trigPin3, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin3, INPUT); // Sets the echoPin as an Input
//pinMode(potentiometer, INPUT);
//pinMode(button, INPUT_PULLUP);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}
void loop() {
if(digitalRead(button)== HIGH) {
//if(digitalRead(button)== HIGH) {
// Clears the trigPin
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin3, LOW);
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin2, HIGH);
digitalWrite(trigPin3, HIGH);
digitalWrite(trigPin2, HIGH);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin3, LOW);
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration2 = pulseIn(echoPin2, HIGH);
duration3 = pulseIn(echoPin3, HIGH);
duration2 = pulseIn(echoPin2, HIGH);
duration = pulseIn(echoPin, HIGH);
//Potentiometer
volume = analogRead(potentiometer);
volumeScaled = volume* 0.25;
//volume = analogRead(potentiometer);
//volumeScaled = volume* 0.25;
// Calculating the distance
distance = duration * 0.034/2;
distance2 = duration2 * 0.034/2;
distance3 = duration3 * 0.034/2;
Serial.println(distance1);
Serial.println(distance2);
Serial.println(distance3);
if (distance2 > 30) {
Serial.println("No output");
}111
}
if (distance2 < 30) {
if (distance < 75) {
Serial.println(distance);
analogWrite(motor, volumeScaled);
Serial.println(distance2);
digitalWrite(motor1, HIGH);
digitalWrite(motor1, HIGH);
delay(distance * 15);
}
else{
}
}
else{
......@@ -86,9 +107,9 @@ Serial.begin(9600); // Starts the serial communication
}
if(digitalRead(button)== LOW) {
digitalWrite(motor, LOW);
}
// if(digitalRead(button)== LOW) {
//digitalWrite(motor, LOW);
//}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment