Robotics EveryDay
Published © GPL3+

Making 3D Scanner | 3D Scan Object At Home | Plot in Python

This is a 3D Scanner. An ultrasonic sensor is rotated by the servo motor. The object to be scanned is revolved by a motor. Plots in Python.

BeginnerFull instructions provided8,152
Making 3D Scanner | 3D Scan Object At Home | Plot in Python

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Geared DC Motor, 12 V
Geared DC Motor, 12 V
×1
Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Servo Motor, Premium Male/Male Jumper Wires
Servo Motor, Premium Male/Male Jumper Wires
Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Custom parts and enclosures

CAD Design of 3D Scanner

Schematics

Schematic of 3D Scanner

Code

Code for 3D Scanner

Arduino
#include <Servo.h>
#include <math.h>

Servo m;

int t = 7;
int e=  6;
int n;

void setup() {
  pinMode(t, OUTPUT);  //trigger pin
  pinMode(e, INPUT);  //echo pin
  pinMode(8,OUTPUT); //pin to control DC motor, goes to mosfet
  m.attach(10);     //servo motor pin
  
  Serial.begin(9600);

}

int distance(){
  
  long duration, cm;
  
  digitalWrite(t, LOW);
  delayMicroseconds(2);
  digitalWrite(t, HIGH);
  delayMicroseconds(5);
  digitalWrite(t, LOW);
  
  duration = pulseIn(e, HIGH);

  cm = duration/ 29 / 2;
  
  return cm; //returns distance in centimeters
}

void revolve(){ // rotates motor 18 degree
 digitalWrite(8,HIGH);
 delay(120);
 digitalWrite(8,LOW);

}

void scan(){
  int i;
  for(i=70;i<=120;i+=1){
    m.write(i);
    
    delay(25);      
    
    float d= distance();

    if (d<30){
      
      Serial.print(n);
      Serial.print(",");
   
      Serial.print(d*cos((i-90)*3.14/180));
      Serial.print(",");
   
      Serial.print(d*sin((i-90)*3.14/180));
      Serial.println();  
      
      }
    
  

  }
  
  for(i=120;i>=70;i-=1){
    m.write(i);
    delay(20);
    }

}

void loop() {

  int i;

  Serial.println("Start");
  
  for(i=0;i<20;i+=1){ // scan 20 times, every revolution is 18° i.e. 20x18° = 360°
    n=i;
    
    scan();       //scan top to bottom
    revolve();   // revolve the object
    delay(50);  //repeat    
    
  }
 
 Serial.println("End");
 delay(50);
 
}

Credits

Robotics EveryDay

Robotics EveryDay

0 projects • 9 followers

Comments