Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with me project. I'm on an Arduino Uno. I need my servo to keep activating until the parallax ping sensor senses something

I need help with me project. I'm on an Arduino Uno. I need my servo to keep activating until the parallax ping sensor senses something in front of it that is 5cm or less. I'm making a food dispenser and the food will dispense when the servo is activated. Once the food is filled up and the ping sensor senses it is about 5 cm's away it will stop. Would be nice if someone could modify add to my code to make this happen. I have a push button as of now to turn the servo. Thanks

#include

Servo myservo;

const int servoPin = 9; const int buttonPin = 12; const int ledPin = 13; const int pingPin = 7;

void setup() { Serial.begin(9600); myservo.attach(servoPin); pinMode(buttonPin, INPUT); digitalWrite(buttonPin, HIGH); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); myservo.write(180); delay(1000); myservo.detach(); }

void loop() { int buttonVal = digitalRead(buttonPin); if(buttonVal == LOW) { myservo.attach(servoPin); myservo.write(30); delay(2000); myservo.write(180); delay(1500); myservo.detach(); delay(1000); } delay(13);

long duration, inches, cm;

pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

// convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration);

Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println();

delay(100);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

More Books

Students also viewed these Databases questions

Question

(3) Let T1=1,Tn=3Tn1+4 for n2. Show that Tn=3n2 for n1

Answered: 1 week ago