Requirements
- uArm Metal
You may also use other versions of uArm, but in this article the box to hold ultrasonic sensor is specifically designed for uArm Metal.
- Ultrasonic Ranging Module HC - SR04
You can easily find this Ultrasonic module in eBay or Amazon. However, I recommend you to buy this kind of modules from Seeed Studio or Sparkfun, they have almost all kinds of modules and accessories you need.
- Serval jumpers
You may need both female/male and female/female jumpers.
- 3D printer
Well, it is unrealistic to require everyone has a 3D printer. If it is hard for you to easily access a 3D printer and you don’t mind to pay a little money for that, you can a website called makeXYZ . It is a website that can 3D print your model and sent it to you.
- Screws
Two M3x8 screws and four M1.6x5 screws
Step 1: Print Sensor Holder
As I mentioned in the requirement, if you have your own 3D printer, you can just download the .stl file from GrabCAD and print it. Otherwise, you may also upload the .stl file to makeXYZ and let them print for you. Both way works.
Step 2: Install ultrasonic sensor and sensor holder
-
Screw sensor to the sensor holder with 4 M1.6x5 screws. (Pic 1)
-
Took off the screws on the back pump box, and screw the holder to pump box with 2 M1.6x5 screws. (Pic 2&3)
Step 3: Connect sensor to uArm
Following the pictures above, using male/female jumper to connect GND and VCC and using female/female jumper to connect Trig and Echo.
Step 4: Upload code to uArm
Use Arduino IDE to upload the following code to your uArm, and send ‘e’ in serial monitor to uArm to use this ultrasonic sensor. What this code dose is when the sensor detects anything pass before it, uArm will try to move something from its right side to left side. This code is only a example to let you know how to use the sensor, you can change it to anything you like.
#include "uarm_library.h"
const int TrigPin = 8;
const int EchoPin = 9;
const int StopperBtn = 2;
float cm;
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial port at 9600 bps
pinMode(StopperBtn,INPUT);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
uarm.init();}
int buttonState = 1;
double des_x = -20;
double des_y = -3;
double des_z = 9.25;
int time_travel = 2;
double final_x = 20;
double final_y = -15;
double final_z = 23;
double home_x = 0;
double home_y = -15;
double home_z = 12;
int value;
void loop() {
char readSerial = 'e';
Serial.println(readSerial);
if (readSerial == 'a') {
uarm.attachAll();
uarm.moveTo(des_x,des_y,des_z);
delay(1000);
}
if (readSerial == 'b') {
uarm.moveTo(home_x,home_y,home_z);
delay(1000);
}
if (readSerial == 'c') {
uarm.detachAll();
} if (readSerial == 'd') {
} if (readSerial == 'e') {
int stat = 1;
int haveSentT = 0;
int numberCount = 0;
while (stat)
{
if(Serial.available()>0){
stat = 0;
}
else{
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
cm = pulseIn(EchoPin, HIGH) / 58.0;
cm = (int(cm * 100.0)) / 100.0;
if ((cm<10)||(cm>70)){
numberCount = 0;
haveSentT = 0;
}
else{
numberCount = numberCount + 1;
if (numberCount >3){
if ( haveSentT == 0){
buttonState = 1;
uarm.moveTo(des_x,des_y,des_z,0,2,0); while (buttonState)
{
buttonState = digitalRead(StopperBtn);
if(buttonState == HIGH)
{
uarm.moveTo(0,0,-2,1,1,0);
}
delay(200);
}
digitalWrite(6,HIGH);
delay(1000);
uarm.moveTo(des_x,des_y,des_z+4,0,2,0);
delay(300);
uarm.moveTo(final_x,final_y,final_z,0,time_travel,-10);
delay(500);
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
delay(4000);
digitalWrite(5,LOW);
haveSentT = 1;
uarm.moveTo(home_x,home_y,home_z);
}
}
delay(200);
}
}
}
} if (readSerial == 'h') {
Serial.print("The current location is ");
Serial.print(uarm.getCalX());
Serial.print(" , ");
Serial.print(uarm.getCalY());
Serial.print(" , ");
Serial.print(uarm.getCalZ());
Serial.println();
delay(1000);
} if (readSerial == 'u') { int buttonState = 1;
uarm.moveTo(-9.2,-12,9.23);
while (buttonState)
{
buttonState = digitalRead(2);
if(buttonState == HIGH){
uarm.moveTo(0,0,-2,1,1);}
delay(200);
} digitalWrite(6,HIGH);
delay(1000);
uarm.moveTo(-9.2,-12,12);
delay(300);
uarm.moveTo(0,-15,12);
delay(300);
digitalWrite(6,LOW);
}
delay(500);
}