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 4cm 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 about 4 cm's away it will stop. Would be nice if someone could modify add to my code to make this happen. 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_2

Step: 3

blur-text-image_3

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Describe the Indian constitution and political system.

Answered: 1 week ago

Question

Explain in detail the developing and developed economy of India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = X 52+7 - 1)(x+2) dx

Answered: 1 week ago

Question

What is gravity?

Answered: 1 week ago

Question

What is the Big Bang Theory?

Answered: 1 week ago