Self Balancing Robot Tutorial – Part 1

Posted on by Steven McConnon

I was talking with some of my friends at UCF and discovered that there exists an inexpensive microcontroller that can be programmed to do embedded systems called the Arduino. Since embedded systems is the whole reason I’m going to college, a week after hearing about the Arduino, I’ve bought it and a slew of parts to create my very own self balancing robot with hopes to scale it up and create my own segway.

Here is a video to show you what I’m talking about (not mine):

Basically, I’m going to be teaching you all how to build your very own version of this robot as I build it myself.

Here is a list of things I have bought so far. I have done lots of research to keep costs low on this project. This parts lists costs approximately $210.

1. Arduino Uno
2. Pololu MinIMU-9
3. Sabertooth dual 5A motor driver
4. Parallax Motor/Bracket/Wheel Kit
5. 2- 1/4 Inch diameter x 36in threaded rods
5. Spare plywood
6. Wire
7. A battery
8. 24 – 1/4″ Nuts (for threaded rod)
9. 8 – #8 Machine Screw Nuts
10. 8 – #8 Threaded Machine Screws

Why I chose the Arduino:

I chose the Arduino over cheaper, more powerful microcontrollers like the Teensy, Propeller, and the PicAXE because of the huge user base of it. I know that if I run into any problems there will be thousands of other users to help me in the forums. Anyone who knows anything about programming knows that it’s much easier to use something with a large community.

Why I chose the Pololu MinIMU-9:

Basically for this project, all that’s needed for the robot to keep balance is 3-degrees of freedom in an IMU, but this was the cheapest thing I could find. This particular IMU was actually retired which is why I think it was so cheap. It will do the trick.

Why I chose the Sabertooth dual 5A motor driver:

It’s simply the cheapest motor controller that can stand 5A worth of current and spikes up to 10A. My motors have a stall rating of 4.8A so this is perfect.

Why I chose the Parallax Motor/Bracket/Wheel Kit:

Believe me, I have looked at other kits such as this, but items like that are more expensive, slower, have less torque, and are heavier. Granted, I could have found my own motors, wheels, and mounting brackets separately, but that would be very very time consuming to find something comparable. To me, time is money and I can’t spend the time it takes to put some stuff like that together.

Gamification for higher user engagement.

Posted on by Steven McConnon

I was working on a fitness directory application for a personal project a while back. While the web application is no longer live, I gained a lot of experience from it. I built the application and spent a very small amount of money on advertising. One of the main problems of launching a free web application is how to gain the initial users. Although it did not occur to me at the time, I could have enticed the 100 or so initial users to use my site more if I had used game dynamics.

Gamification, or adding game dynamics to a web application is a great way to make your users stay on your site for longer and fill out their profiles more completely. Basically, the premise behind gamification is that if you create a rewards for users who complete tasks on your site, they will use your site more, thus accomplishing the goal of making an application more engaging. Some of the techniques for gamification include, giving points, badges, and awards to users who do things you want. Some of these things could include posting helpful things to other users, filling out their profiles more completely, and adding more friends. Progress bars showing completion of tasks give the users more incentive to finish because they don’t want to see that they have only completed 60% or their profile or whatever. One of the ways that yahoo answers uses gamification is through their point and level system. With each post I make on Yahoo answers, the more points I get, then after a certain number of points I go up a level or receive a badge. The perks of being a level 3 are that I now have the ability to do more things such as give more thumbs ups or make more posts within a given time period.

So a little creative thinking can go a long way and make the difference between making a successful and fun to use web application, and a boring web application that nobody wants to use. Use gamification to improve the user experience and you will see the engagement rate of your users increase.

Arrange Rows in Columns of 2 or 3

Posted on by Steven McConnon

When making a CMS web application, the layout should be dynamic. In the case of arranging hundreds of textboxes neatly, some logic is involved. Here is a snippet of code that creates an array for the number of columns each row has.

For example, if we have a prime number of textboxes, we want things arranged neatly like this:

/*//Here is a sketch of we want to happen:
	//if it's 1
	1 - row of 1
 
	//evenly divisible by 2, and not by 3		
	2 - row of 2
	4 - row of 2
	8 - row of 2
	10- row of 2
	14- row of 2
 
	//evenly divisible by 3 or 6 
	3 - row of 3
	6 - row of 3
	9 - row of 3
	12- row of 3
 
	//if it's prime and then the last row has the remainder
	5 - row of 3 then 2
	7 - row of 3 then 2
	11- row of 3 then 2
	13- row of 3 then 1
	17- row of 3 then 2
	19- row of 3 then 1
	23- row of 3 then 2
	29- row of 3 then 2
	31- row of 3 then 1
	37- row of 3 then 1
*/
 
$map = array();
 
//detects prime numbers
function is_prime($i) {
	if($i % 2 != 1) return false;
	$d = 3;
	$x = sqrt($i);
	while ($i % $d != 0 && $d < $x) $d += 2;
	return (($i % $d == 0 && $i != $d) * 1) == 0 ? true : false;
}
 
 
array_push($map, 1);
//do the array for the suites
for($i=0; $i<($roomBlock->numSuites * $roomBlock->maxPplSuites); $i++) {
	$title = 0;
	echo $i . "  - ";
	//every $roomBlock->maxPplSuites number of times, add a 1 for the title
	if($i%$roomBlock->maxPplSuites == 0) {
		array_push($map, 1);
		$j=0;
		$primeRows = 0;
	}
 
	if($roomBlock->maxPplSuites%2 == 0 && $roomBlock->maxPplSuites%3 != 0 && $j<($roomBlock->maxPplSuites/2))
		array_push($map, 2);
 
	if(($roomBlock->maxPplSuites%3 == 0 || $roomBlock->maxPplSuites%6 == 0) && $j<($roomBlock->maxPplSuites/3))
		array_push($map, 3);
 
	if(is_prime($roomBlock->maxPplSuites) && $j<($roomBlock->maxPplSuites/3) ) {
		//add to number of rows
		$primeRows = $primeRows + 3;
 
		if($roomBlock->maxPplSuites%$primeRows >= 1 && ($roomBlock->maxPplSuites - $primeRows) < 1){
			$val = $roomBlock->maxPplSuites%($primeRows - 3);
			array_push($map, $val);
		} else {
			array_push($map, 3);
		}
 
	}
 
	$j++;
}

How to show errors on ASP.NET website

Posted on by Steven McConnon

I was recently working on an ASP.NET 4.0 application and had some problems when uploading my site on to Godaddy’s servers. Basically I was getting INTERNAL SERVER 500 ERROR. This isn’t very useful for a developer who is trying to fix the error, although it looks better than just showing a bunch of details from a security standpoint. Basically all you have to do is modify the Web.Config file and add this into it:

<system.webServer>
     <validation validateIntegratedModeConfiguration="false" />
     <asp scriptErrorSentToBrowser="true"/>
     <httpErrors errorMode="Detailed"/>
</system.webServer>

and bam, there ya go, error messages for you and the world to see.

How to blink text in all browsers

Posted on by Steven McConnon

I am not saying that <blink></blink>  tags are smart, but sometimes clients want things to blink indefinitely. So here is a snippet of code that will help you on your way.

Javascript:

<script type="text/javascript" language="javascript">
 window.onload=blinkOn;
 
function blinkOn()
{
  document.getElementById("blink").style.color="#CCC"
  setTimeout("blinkOff()",1000)
}
 
function blinkOff()
{
  document.getElementById("blink").style.color=""
  setTimeout("blinkOn()",1000)
}
 
 
 
</script>

HTML:

<div id="blink">Hello World!</div>

How to link includes to full url

Posted on by Steven McConnon

When working on a project for a blog recently I tried linking my includes to something like this:

1
<?php include("http://sitename.com/includes/header.php"); ?>

And it would not work. The proper way to link that would be

1
<?php include($_SERVER['DOCUMENT_ROOT'] . "/includes/header.php"); ?>

The $_SERVER['DOCUMENT_ROOT'] refers to /home1/orlandp9/public_html which is the full document root.

There is actually a way to link to a full external url but it is not safe because a criminal hacker could include files that are malicious and an external include could be configured to steal credit card or other personal information. Another malicious thing that I have seen with a remote include is that the hacker includes a file full of html links to his site effectively creating back links to whoever he wanted. The hacker who was hacking into sites and creating back links to his sites must have been involved in SEO. I do not condone any use of malicious code and you shouldn’t either.

If you are really desperate and are not afraid to get hacked then you can turn on a php configuration in php.ini called allow_url_include or allow_url_fopen.

How to center a div on the page using CSS

Posted on by Steven McConnon

A long time ago when I first started doing web-design I would always run into the problem of how to center a div on the page. Now of course that is a very simple problem for experienced coders but this tutorial is made for the beginners.

Example:

This is an outer div centered in the page.

This nested inner div is centered.

View full entry

Rounding up to the nearest 5 or 9 in PHP

Posted on by Steven McConnon

Sometimes when using large numbers, retailers want their numbers to look prettier, so they want things rounded up to the nearest 5 or 9. For example the number 101.99 would round to 105.00 and the number 106.99 would round to 109.00. Use this function to do just that.

View full entry

Polyatomic Ions Game

Posted on by Steven McConnon

A few days ago I noticed a need for a game like this online, there aren’t enough resources online to learn the Polyatomic Ions in Chemistry. So… I made one! There are 30 unique Polyatomic Ions to chose from to help you study.

This is released under GNU public license so the code and the game is free.

Here is the full-screen version: http://stevenmcconnon.com/polyatomicIonGame/polyatomic_ion_game.swf

Importance of having a blog

Posted on by Steven McConnon

As a computer programmer and web developer, it is important for me to have a blog. Here are some of the reasons why I need a blog.
1. Keep track of things I have learned
When I am building websites I frequently come across problems that need special tricks to get past the problem. I can update my blog to remind myself and others neat ways to get past the problem.
2. Give back to the community
I have learned a lot from public blogs about web-development and programming and I feel it is my job to give something back to the online community that has helped me. By posting tutorials and tricks other web developers can get their work done faster by looking at my solution to the particular problem.
3. Free advertisement
Creating a blog on my website increases my businesses signature on the web and also gives employers a sense that I am on top of my game and constantly changing with the industry.