Showing posts with label robot. Show all posts
Showing posts with label robot. Show all posts

Thursday, July 3, 2014

My First Arduino Robot

This is my first successful robot using an Arduino and a ping sensor. The forward and reverse circuit is the same as the forward and reverse circuit I have posted on this blog and YouTube. The motor is a set of motors i bought from Radio Shack. The big silver transistor is a NPN 2N3055 that controls the stearig motor. The code is at the bottom.








And here is the code.

// by BirdshoBrad @ YouTube & Blogger
const int pingPin = 7;
int pin1 = 10;
int pin2 = 11;
int pin3 = 12;



void setup() {

  Serial.begin(9600);  // initialize serial communication:
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
}

void loop()
{
  long duration;

  // The PING is triggered by a HIGH pulse of 5 microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING, a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
Serial.println(duration);
delay(100);

if (duration > 2500) // the distance....about 8-10 inches
{digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin3, HIGH); //forward
}

else {
  digitalWrite(pin3, LOW); // forward
  delay(1500); // rest
  digitalWrite(pin1, HIGH); // turnig transistor
digitalWrite(pin2, HIGH); // reverse
delay(3000);
digitalWrite(pin3, LOW);
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
delay(2000); //rest
}
 
}









Sunday, June 29, 2014

Forward and Reverse Circuit for a DC Motor

I've been wanting to build a robot that drove around and if it came to an object, it would sense it with a ping sensor and stop and turn the other way. I was in a hurry to build a circuit that would make a motor spin both ways, so it took a few hours to get it to work. I never looked to a schematic of an H-bridge. The hardest part was getting the transistors that controlled the two sets of transistors to work. The transistors do get hot, but I've never had one burn up.


Here is the schematic and the circuit on a breadboard on my robot.









Here is the video.