Friday, 16 August 2013

Project 18 Part 1 (Advance): 3D Infrared Scanner

This project is insane. Millions of my precious brain cells gave their lives in order to produce this scanner. /sarcasm

No really, this project is extremely difficult. Constructing and coding the servo motor's movement was simple overall but processing the data and creating a 3D image is not a walk in the park. The 3D image is created by Processing.

Processing

How does this work? There are 2 servo motors, where one of them is responsible for the panning motion and the other, tilting motion. Once the panning servo completed its 180 degree turn(incremented by 1 degree), the tilting servo will tilt 1 degree, and this process repeats itself. At all times, the sensor will be scanning for objects. The arduino will be sending 3 pieces of data: pan position, tilt position and the distance. These values will be picked up by Processing and for each set of data,(pan + tilt + distance), a dot will be mapped out.

This is where the fun comes in. We know 2 angles + distance, which could be interpreted as a vector. Using simple trigonometry, we can easily determine the x,y and z components 







Note: Ignore the purple dots
The image on the left is a good visualization of how the scanner works. The pink curve is the very first scan(tilt angle: 0 degrees and the panning angle ranges from 0-180). The green curve is exactly identical to the pink curve, but with a 10 degree tilt angle.









From this point, everything is generally simple. The hard part is to implement a "camera" movement algorithm in order to see the image at various perspectives. To get this to work, there is a massive problem. In order to change the point of view, the camera movement algorithm requires a complete deletion of the current image and redraw it. If I were to merge the camera algorithm with the mapping algorithm, I'll just get a blank screen with 1 dot that is constantly moving. This is because the data collected is not being stored and the image displayed is the current reading. Obviously, this has no use to me.

This is where arrays come in. In order to store these points, an array must be created. However, there is a TON of data. According to my calculation, there should be at least 32,400 points(x,y,z) that will be collected! Next, Each of these points will be written into a text file.

I then created a separate script, responsible for merging both the camera movement algorithm and plot all the points. Unfortunately, it crashes. Why? There is too much data. I wasted countless hours designing an algorithm which will plot the points and implementing a camera movement algorithm, which allows me to see the graph in different perspectives.

Now, I have no choice but to use another software. After some research, I decided to use matlab.All I have to do is copy and paste the coordinates into matlab and write a very simple code to graph these values. Once everything is completed, I decided to run a test trial. Both servos will be operating but the distance sensor will be turned off. Since this is a test trial, the micro controller will be sending "300cm" as the distance reading.

In this trial run, the tilting servo will be incremented by 10 degrees. As you can see, a portion of the image is missing. There is a bug in my code where the micro controller is not sending all the data for some reason.




For my second trial run, the tilting servo will be incremented by 1 degree. This scan took about 12 minutes and the results are beautiful. I can now conclude that my program is functional.







Hardware issues

As for hardware issues, My arduino board couldn't supply enough power to run 2 servo motors simultaneously. An external power source will be required to power 1 of the servo motors. I'll be using 1 micro servo and 1 medium servo(this servo requires more power). I tried using 4AA batteries(measured it with a multimeter and got 5.3v) but it simply wasn't enough to power the servo motor. I guess the batteries wasn't supplying enough current.I have 9 volt batteries but those things die way too quickly(mine is rated at 200 mah and I might be able to power the motor for 1 hour, if I'm lucky).

I decided to get a little creative. The most reliable power source available is my computer. I'll be using the USB port to power both my arduino and my medium servo. I found an old cell phone usb charger, cut off 1 end of the wire and soldered it onto a 2 wires. Next, I measured the voltage using a multimeter and its exactly 5volts! Finally, I tested my circuit and everything is running smoothly.



Future Plans

This project is not yet completed. As of now, the only thing I successfully accomplished is creating a program that can split the readings into 3D points and graph it using a plotting software(matlab). The scanner itself needs some serious improvements. From the images You can see that the sensor's position is changing. (For example, starting position is about 5cm below the tilt servo and the end position is 5cm above the tilt servo).  Unfortunately my program assumes that the sensor will always be in the same position. I tried to take this into consideration (software wise) but it's not very effective.
Tilt Angle: 0°
Tilt Angle: 180°






































Top View



















 I need to replace my micro servo. Physically, it can only turn up to 160-170 degrees, which could
explain why the scanned image is not perfect. The image above shows that the 2 objects are not at a 90 degree angle. On the bright side, the corner readings are pretty accurate. The top right image of my laundry boxes shows that one box is slightly curved in. Thankfully, the infrared sensor noticed this!

This is a very challenging project and I still need to improve my physical scanner. Hopefully by then, I'll get more accurate readings.

Monday, 12 August 2013

Project 17 (Advance): Ultrasonic Alarm System (Version 2), with Sonar Display

After creating my ultrasonic alarm system, I wanted to map nearby objects onto a screen, similar to radars. To do this, I need another software called Processing. Processing is a programming language which is used to create images, animations and a bunch of other stuff. In my case, I wanted to create a radar screen. Luckily, the programming language and syntax is exactly identical to the arduino IDE. All I had to do is figure out how to draw basic shapes and the rest is just math and coding.

The features in this project is exactly the same as my previous alarm system(version 1). I replaced my LCD screen with a sonar display produced from Processing. The arduino board will be sending data onto my computer serially, which is then picked up by Processing. The arduino will be sending the servo's angle position and the ultrasonic sensor's reading. The sonar screen is produced by using basic trigonometry.

On the sonar screen, the top right hand corner will display the status of the system. On the bottom right hand corner, the distance between the sensor and the object in front of it is displayed and is being constantly updated in real time. The little red dots are the detected objects.

"Normal" indicates that everything is running normally and nothing is within the danger limits.
Also, a green light indicates that the sensor/servo motor is operating as expected.




 "Caution" indicates that either the servo motor or the ultrasonic sensor is not working properly. If someone manages to trespass into the safety limits and attempted to disable the sensor, the caution light will be turned on. In addition, the speaker will produce a loud buzz every second, until the ultrasonic sensor is enabled.

"Danger" indicates that an object is detected within safety limits. The alarm will then be triggered and the sonar screen will no longer update itself. A hard reset will be required to restart the sonar display.





This is my most proudest invention yet and over time, I will add more features. The speaker is not very punishing so I want to add something else that will PUNISH anyone where dares to enter the safety limits. What I have in mind is a sentry bb gun, which will shoot the intruder. The next step is to add motion tracking. Unfortunately, none of this will be accomplished(yet). I'm missing lots of materials and if you were to check my current balance (project 15: Digital Piggy Bank), my wallet is practically empty.

Thursday, 8 August 2013

Project 16 (Moderate): Ultrasonic Alarm System (Version 1)

This is my favorite project yet. I've created a motion detector that scans the room and if it detects any object within 25cm, the speaker will go nuts.


As for the alarm, a piezo buzzer is not very loud. so I went to a local electronics store and bought new speakers + an audio amplifier. An audio amplifier pretty much converts small inputs and outputs something much bigger. The arduino digital pin can only output 5 volts and any more would damage the board. In order to make the speaker louder, I need more voltage. That's where the audio amplifier comes in.












At first, the arduino board was suppling all the power but I noticed that the LCD display was flickering.
Due to the high power requirements, I need an external power source. A 9 volt battery will be powering the audio amplifier, which means the speaker will be even louder than before. 4 AA batteries(about 5 volts) will power the servo motor. The arduino will only be powering the LCD display and the ultrasonic sensor. With this setup, the LCD display is no longer flickering!

Features:
- an ultrasonic sensor, mounted onto a servo motor will scan for nearby objects(can detect objects up to 3 meters away!)
- the distance will be displayed on a LCD display
- once the alarm is triggered, "INTRUDER ALERT!!" will be displayed on the LCD

Parts:
- 1x ultrasonic sensor
- 1x servo motor
- 1x RGB LCD display (16 X 2)
- 1x 8 ohm speaker (0.25 watt)
- 1x 10k potentiometer
- 1x lm386
- 1x 220uf capacitor
- 1x 9v battery and a battery holder (to power the audio amplifier)



Scanner Limits

The ultrasonic sensor has a range from 2cm to 3 meters. Also, I noticed that the sensor has issues detecting corners. This is because the sound waves emitted from the sensor will bounce off the surface at an angle. Instead of going directly back to the sensor, it will then bounce off another surface, and then back. Thus it will take a lot longer for the sensor to read the sound. The longer it takes to read the sounds, the farther the distance is. Also, any object that can absorb sound(ex. sponges) will disrupt the readings.

Tuesday, 6 August 2013

Project 15 (Moderate): Digital Piggy Bank

Detecting a coin and its weight can be complicated and expensive. I came up with several solutions to this problem. One of which, I tried to create a switch out of aluminum foil. Whenever a coin is inserted, it will cause the aluminum foil to come in contact, and therefore completing the circuit. However, this switch is too big for my tiny piggy bank.












I decided to use a photoresistor as a "coin detector". When the arduino is powered up, it will go through a calibration state. During this phase, the arduino will be recording the light intensity for about 5 seconds and after that, it will calculate the average light intensity. Finally, the arduino will now accept coins. Once coin is inserted, the light intensity will change. This is a very basic way of detecting a coin. 









As of right now, I don't know how to create a simple and efficient way to detect what kind of coin is inserted. So instead, I'll create a user interface to record the deposit. This will consist of 5 buttons. Each button will represent a state (see picture on the left). The LED will indicate which state you are in. From left to right, the states are $0.05, $0.10, $0.25, $1.00 and $2.00.

Once the state has been determined, simply insert the coin and your deposit will be incremented by the amount specified.




features:
- 5 buttons (5 cent, 10 cent, 25 cent, 1 dollar, 2 dollar)
- 5 LED's will represent each button to identify the current state  
- current balance will be displayed on LCD
- savings will be recorded and saved (unless the power is turned off)
- a photoresistor will be used as a coin detector



Parts:
- 5x red LEDs
- 5x 330 ohm resistor
- 5x pushbuttons
- 6x 10k ohm resistor
- 1x photoresistor
- 1x RGB LCD (16 x 2)
- 1x 10k potentiometer


Using a photoreisstor as a coin detector can cause some problems. For example, suppose the arduino is running its calibration in a very bright room. When the calibration period is over, turning off the lights will confuse the arduino and it will think that a coin is constantly being inserted. This is because the arduino is comparing the average light intensity during the calibration period with the current light intensity. When there is a significant difference between these light intensities, the balance will be incremented. 

Sunday, 4 August 2013

Project 14 (Novice): Ultrasonic Distance Sensor

My ultrasonic sensor finally arrived in the mail. Time to make a reliable distance sensor.

features:
- capable of detecting an object up to 3 meters!
- the distance (in cm) will be displayed on a LCD

parts:
- 1x ultrasonic sensor
- 1x RGB LCD (16 X 2)
- 1x 10k potentiometer













 I have great plans for this magnificent sensor.

project 12 (Novice): stopwatch

I finally got my LCD to work and used it to make a simple project.


Features:
- a pause button, which pauses time
- a reset button, sets the timer to 00:00
- the reset button can also start the timer


Parts:
- 1x RGB LCD (16 X 2)
- 2x pushbuttons
- 2x 10k ohm resistor
- 1x 10k potentiometer
 

Using an LCD display was a lot easier than using a 7 digit segment display. Also, the LCD is simply stunning, so I don't think I'll use a 7 digit segment display again.




Project 11 (Moderate): TV-B-GONE

This is one of the coolest gadgets I've ever made. For those who didn't know, tv-b-gone is a device that turns off ANY tv. Visit the tv aisle at best buy, whip this gadget out and watch as each tv shuts down. If you are brave enough, go to a sports bar during a very important match and .... (you get the idea).

If you want to make your own tv-b-gone, visit this link. The author made an excellent tutorial and even provided their code!