LOGIN
John Rodrigues
Mechanical Engineer |certified professional in product design and analysis |MEP Engineer|blogger at designwithjohn.com (Project Leader)
 · HonnavarIndia
Edit
Delete
Share
Report
TASK
Open
  ·  Close Task

Task is to come up with a circuit for the following code

int inp1 =2;
int inp2 =3;
int inp3 =4;
int inp4 =5;
const int pingPin = 7;
void setup() {
  Serial.begin(9600);
  pinMode(inp1, OUTPUT);
  pinMode(inp2, OUTPUT);
  pinMode(inp3, OUTPUT);
  pinMode(inp4, OUTPUT);
}


Task is to come up with the circuit for the above code
void loop() {
  //---------This section is for Distance ----------------------------------------------------
  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);
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(100);
  //-------------this secton is for motor logic-------------------------------------------------
  if(cm < 10)
{
  digitalWrite(inp1, LOW);
  digitalWrite(inp2, HIGH);
  digitalWrite(inp3, HIGH);
  digitalWrite(inp4, LOW);
  delay(500);
}
if(cm == 10)
{
  digitalWrite(inp1, LOW);
  digitalWrite(inp2, LOW);
  digitalWrite(inp3, HIGH);
  digitalWrite(inp4, LOW);
  delay(500);
}
if(cm < 10)
{
  digitalWrite(inp1, LOW);
  digitalWrite(inp2, HIGH);
  digitalWrite(inp3, LOW);
  digitalWrite(inp4, LOW);
  delay(500);
}
}

long microsecondsToInches(long microseconds) {
  return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) {
  return microseconds / 29 / 2;


}
Contributions
Awais Khawar

Awais has given us the code
Thanks alot Awais
He has been very Helpful
Keep up the Good Job

added by:   John Baptist Rodrigues
2 likes 
Like
Share
Load 2 previous comments
Steven Reubenstone
Mechanical Engineer & Collaborizm Mentor. Join our iOT Hackathon!
 · New YorkU.S.
Edit
Delete
Share
Report

yes just click edit from the drop down

0 like 
Awais Khawar
Btech Electronic and Telecom is in progress
 · PeshawarPakistan
Edit
Delete
Share
Report

Thanks for Positive Response

2 likes 
Steven Reubenstone
Mechanical Engineer & Collaborizm Mentor. Join our iOT Hackathon!
 · New YorkU.S.
Edit
Delete
Share
Report

Excellent work here guys, I love this robot. I want to continue to make it more powerful

0 like 
Steven Reubenstone
Mechanical Engineer & Collaborizm Mentor. Join our iOT Hackathon!
 · New YorkU.S.
Edit
Delete
Share
Report

I have added Awais as official mentor of this project

0 like 
Talha Hashmi
Student of Avionics Engineering
 · IslamabadPakistan
Edit
Delete
Share
Report

Is this motor code is of controlling robot or suctioning(Vaccum) ?

0 like 
Awais Khawar
Btech Electronic and Telecom is in progress
 · PeshawarPakistan
Edit
Delete
Share
Report

motor code with distance censer

0 like 
Leave a reply...
DISCOVER
CHAT
ALERTS
-2
DISCUSSIONS
-1
FEED