Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started