TUTORIALS Robotics

# Mikey Go Home!

DFRobot Aug 11 2015 244

Mikey, the robot with vision (as seen in previous post) can now see how to go home to his charger.

### Step 1

To build a charging station, I used a 6" x 18" piece of aluminum, 6" of 1/4" diameter aluminum rod, three 1/4" x 2 1/2" x .016" springs, two 7/16" x 8 1/2" x .047" springs, a 9 volt dc power supply, 2" wide aluminum duct tape (16 inches) and misc. connectors and hardware.

Add tape to the bottom of the robot.

### Step.2

Create a connector to attach to the tape. Note that the tape only conducts on the non-sticky side, therefore each piece of tape must be electrically connected to the circuit.

### Step 3

3D design files are here:
http://www.thingiverse.com/thing:335442
Drill holes in the rod and press fit the rods into the holders

### Step 4

Attach the braket to the robot.

### Step.5

Wire the robot as shown in the schematic. I used a prototype board to make connections more easily.

### Step.6

Add the spring holder (3D printed) and springs. Attach the two springs in the center by soldering bare copper wire between them. Drill holes three inches apart (slightly smaller than the spring) and place the small springs (cut into 1 1/4" pieces) into the holes. Attach the dc power supply, positive to the upper springs and negative to the base plate.

### Step.7 Code

#### Load the code below into the Arduino that controls the motors.

int charge=0; int val=0; int val1=0; int valm=0; int valm1=0; int jump=3; int ctr=0;//counter const int pwmA=3; const int pwmB=11; const int brakeA=9; const int brakeB=8; const int dirA=12; const int dirB=13; const int right=5; const int left=7; const int chglt=6; void setup() { pinMode(dirA, OUTPUT); pinMode(brakeA, OUTPUT); pinMode(dirB, OUTPUT); pinMode(brakeB, OUTPUT); pinMode(right,INPUT); pinMode(left,INPUT); pinMode(chglt,OUTPUT); digitalWrite(dirA, HIGH);//forward A digitalWrite(brakeA,LOW);//release brakeA analogWrite(pwmA,100);//set speed A digitalWrite(chglt,HIGH);//test charge light digitalWrite(dirB,HIGH);//forward B motor digitalWrite(brakeB,LOW);// analogWrite(pwmB,100);//set speed B delay(700); digitalWrite(chglt,LOW);//set charge light off } void loop () { if (jump==0) { analogWrite(pwmA,0);//charge found analogWrite(pwmB,0); digitalWrite(chglt,HIGH); delay(50000); } if (jump==1) { valm=analogRead(0); valm1=analogRead(1); if(valm>500 or valm1>500) { valm=analogRead(0); valm1=analogRead(1); if(valm>450 or valm1>450) { digitalWrite(brakeA, HIGH); digitalWrite(brakeB, HIGH); digitalWrite(dirA, LOW);//reverse A digitalWrite(brakeA, LOW);// analogWrite(pwmA, 200); digitalWrite(dirB,LOW); digitalWrite(brakeB,LOW); analogWrite(pwmB,200); delay(700);//backup digitalWrite(brakeA,HIGH);//stop one wheel analogWrite(pwmA,0); delay(1000); digitalWrite(brakeB,HIGH);//stop other wheel //start both wheels forward digitalWrite(dirA,HIGH); digitalWrite(brakeA,LOW); analogWrite(pwmA,140); digitalWrite(dirB,HIGH); digitalWrite(brakeB,LOW); analogWrite(pwmB,140); delay(1000); }}} //find station if (jump==3) { analogWrite(pwmA,0); analogWrite(pwmB,0); val=digitalRead(right); val1=digitalRead(left); if (val==HIGH && val1==HIGH) { analogWrite(pwmA,140); analogWrite(pwmB,140); if (ctr<150) { ctr=ctr+1; charge=analogRead(2);//test for charge station if(charge>100) { jump=0; ctr=5000; } if(ctr==150) { ctr=0; }} } if (val==HIGH &&val1==LOW) { analogWrite(pwmA, 190); analogWrite(pwmB,50); if (ctr<150) { ctr=ctr+1; charge=analogRead(2);//test for charge station if(charge>100) { jump=0; ctr=5000; } if(ctr==150) { ctr=0; }} } if (val1==HIGH && val==LOW) { analogWrite(pwmB,190); analogWrite(pwmA,50); if (ctr<150) { ctr=ctr+1; charge=analogRead(2);//test for charge station if(charge>100) { jump=0; ctr=5000; } if(ctr==150) { ctr=0; }} } }}

### Step 8. Finish!

Place the target color in the center of the springs and power the robot on. It should seek the home base and stop when it arrives.
Future additions will make the robot leave the base, run around for a while, then return.