Project showcase
3D Room Visualizer

3D Room Visualizer © GPL3+

With only an arduino board, two servos, and an hc-sr04, and some python, you can create a room scanner that is capable of showing depth!

  • 18,840 views
  • 13 comments
  • 51 respects

Components and supplies

Necessary tools and machines

3drag
3D Printer (generic)

Apps and online services

Ide web
Arduino IDE
python IDE

About this project

This project was made for fun. I was bored and as always, I needed to program something. I came across an idea for just a 2d radar. I wanted to expand upon this. So I created a program that enables you to scan an entire room without needing to use a laser. It works by scanning 100 degrees along the x plane, then going up by 1 degree at a time along the y plane. It then send data via serial to a processing computer running the python program. 

Code

Python CodePython
Just run as-is. You may need to install pySerial and PILLOW
import PIL.Image
import serial
import time
img = PIL.Image.new('RGB', (100,100), "red") # create a new black image
pixels = img.load() # create the pixel map
ser = serial.Serial('COM1',9600)
for i in range(100):
    for j in range(100):
        msg = ser.readline()
        value = int(msg)
        print value
        time.sleep(.2)
        pixels[i,j] = (value, 0, 100)
img.show()
Arduino CodeC/C++
Upload as-is. Change pins if needed.
#include <Servo.h>
Servo servox; Servo servoy;
int servoPosx = 130;
int servoPosy = 130;
int pingPin = 3;
int echoPin = 4;
long duration;
long ping()
{
  // Send out PING))) signal pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);
  
  //Get duration it takes to receive echo
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  
  //Convert duration into distance
  return duration;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
servox.attach(9);
servox.write(130);
servoy.attach(10);
servoy.write(30);
}

void loop() {
  
  // put your main code here, to run repeatedly:
  for(int i=0;i<101;i++){
for(int x=0;x<101;x++){
    int distance = microsecondsToCentimeters(ping());
    Serial.println(distance);
    if (servoPosx <30){
      servoPosx = 130;
    }
    servoPosx -= 1;
    servox.write(servoPosx);
    delay(200);
  }
if (servoPosy > 130){
  servoPosy = 30;
}
servoPosy +=1;
servoy.write(servoPosy);
delay(200);
} 
}

Schematics

3d Imager Schematic
Attach as seen: servo ground wires to GND, power cables to 5V, and data wires to D9 & D10.
3dimager

Comments

Similar projects you might like

Room temperature sensor with display on Mobile

Project showcase by Kaustubh Agarwal

  • 24,480 views
  • 8 comments
  • 54 respects

Littlearm 2C: Build a 3D Printed Arduino Robot Arm

Project tutorial by Slant Concepts

  • 4,580 views
  • 1 comment
  • 33 respects

Ultrasonic Map-Maker using an Arduino Yun

Project tutorial by Satyavrat Wagle

  • 53,059 views
  • 37 comments
  • 155 respects

Windows 10 IoT Core: UltraSonic Distance Mapper

Project showcase by Anurag S. Vasanwala

  • 52,436 views
  • 23 comments
  • 141 respects

Head Tracking for Wireless 3D First Person Vision

Project showcase by twhi2525

  • 8,552 views
  • 7 comments
  • 54 respects

3D Printer Fire Safety

Project tutorial by Miles Nash

  • 7,011 views
  • 5 comments
  • 37 respects
Add projectSign up / Login