Devices & Components
Arduino Uno Rev3
Ultrasonic Sensor - HC-SR04
9V 1A Switching Wall Power Supply
Dual H-Bridge motor drivers L293D
Geared DC Motor, 12 V
SG90 Micro-servo motor
Hardware & Tools
Breadboard, 170 Pin
Servo Motor, Premium Male/Male Jumper Wires
Software & Tools
Arduino IDE
Project description
Code
Code for 3D Scanner
arduino
1#include <Servo.h> 2#include <math.h> 3 4Servo m; 5 6int t = 7; 7int e= 6; 8int n; 9 10void setup() { 11 pinMode(t, OUTPUT); //trigger pin 12 pinMode(e, INPUT); //echo pin 13 pinMode(8,OUTPUT); //pin to control DC motor, goes to mosfet 14 m.attach(10); //servo motor pin 15 16 Serial.begin(9600); 17 18} 19 20int distance(){ 21 22 long duration, cm; 23 24 digitalWrite(t, LOW); 25 delayMicroseconds(2); 26 digitalWrite(t, HIGH); 27 delayMicroseconds(5); 28 digitalWrite(t, LOW); 29 30 duration = pulseIn(e, HIGH); 31 32 cm = duration/ 29 / 2; 33 34 return cm; //returns distance in centimeters 35} 36 37void revolve(){ // rotates motor 18 degree 38 digitalWrite(8,HIGH); 39 delay(120); 40 digitalWrite(8,LOW); 41 42} 43 44void scan(){ 45 int i; 46 for(i=70;i<=120;i+=1){ 47 m.write(i); 48 49 delay(25); 50 51 float d= distance(); 52 53 if (d<30){ 54 55 Serial.print(n); 56 Serial.print(","); 57 58 Serial.print(d*cos((i-90)*3.14/180)); 59 Serial.print(","); 60 61 Serial.print(d*sin((i-90)*3.14/180)); 62 Serial.println(); 63 64 } 65 66 67 68 } 69 70 for(i=120;i>=70;i-=1){ 71 m.write(i); 72 delay(20); 73 } 74 75} 76 77void loop() { 78 79 int i; 80 81 Serial.println("Start"); 82 83 for(i=0;i<20;i+=1){ // scan 20 times, every revolution is 18° i.e. 20x18° = 360° 84 n=i; 85 86 scan(); //scan top to bottom 87 revolve(); // revolve the object 88 delay(50); //repeat 89 90 } 91 92 Serial.println("End"); 93 delay(50); 94 95}
Code for 3D Scanner
arduino
1#include <Servo.h> 2#include <math.h> 3 4Servo m; 5 6int t = 7; 7int e= 6; 8int n; 9 10void setup() { 11 pinMode(t, OUTPUT); //trigger pin 12 pinMode(e, INPUT); //echo pin 13 pinMode(8,OUTPUT); //pin to control DC motor, goes to mosfet 14 m.attach(10); //servo motor pin 15 16 Serial.begin(9600); 17 18} 19 20int distance(){ 21 22 long duration, cm; 23 24 digitalWrite(t, LOW); 25 delayMicroseconds(2); 26 digitalWrite(t, HIGH); 27 delayMicroseconds(5); 28 digitalWrite(t, LOW); 29 30 duration = pulseIn(e, HIGH); 31 32 cm = duration/ 29 / 2; 33 34 return cm; //returns distance in centimeters 35} 36 37void revolve(){ // rotates motor 18 degree 38 digitalWrite(8,HIGH); 39 delay(120); 40 digitalWrite(8,LOW); 41 42} 43 44void scan(){ 45 int i; 46 for(i=70;i<=120;i+=1){ 47 m.write(i); 48 49 delay(25); 50 51 float d= distance(); 52 53 if (d<30){ 54 55 Serial.print(n); 56 Serial.print(","); 57 58 Serial.print(d*cos((i-90)*3.14/180)); 59 Serial.print(","); 60 61 Serial.print(d*sin((i-90)*3.14/180)); 62 Serial.println(); 63 64 } 65 66 67 68 } 69 70 for(i=120;i>=70;i-=1){ 71 m.write(i); 72 delay(20); 73 } 74 75} 76 77void loop() { 78 79 int i; 80 81 Serial.println("Start"); 82 83 for(i=0;i<20;i+=1){ // scan 20 times, every revolution is 18° i.e. 20x18° = 360° 84 n=i; 85 86 scan(); //scan top to bottom 87 revolve(); // revolve the object 88 delay(50); //repeat 89 90 } 91 92 Serial.println("End"); 93 delay(50); 94 95}
Downloadable files
Schematic of 3D Scanner
Schematic of 3D Scanner
Documentation
CAD Design of 3D Scanner
CAD Design of 3D Scanner
CAD Design of 3D Scanner
CAD Design of 3D Scanner
Comments
Only logged in users can leave comments