Home » Ardunio » Tilting my Arduino

Tilting my Arduino

Today I spent some time also playing with my Ardunio Uno which I got for my birthday, I had used quiet alot of the sensors in the kit I had received but not the tilt sensors which are the two black boxes on either corner of the board (will tell you why two in a bit), with playing about and seeing what kind of data I get from them seemed fairly jumpy so with a bit of searching around I found out I needed to de-bounce the signal I had heard of this before in electronics just competently forgot about it until the second I read up on it again.
When learning how to use the Ardunio I found Adafruiet to be a great resource and the method I used in this is put in this nice PDF download http://learn.adafruit.com/downloads/pdf/tilt-sensor.pdf
When I was testing it I wanted to see if I could get a precise rotation amount but without hacking around with the numbers too much I thought of a good idea of implementing two sensors since the rotation amount is from the sensor itself so just placing one would mean it would have to be right in the centre of the board which is kinda impractical especially since I set it up so the whole board could be moved with no cables dangling with a cunning use of a rubber band for the board aswell as the battery!

Upon looking at the photo once it was on my computer I noticed it could be very confusing for anyone to see which wires was going where, tends to happen in electronics when prototyping so off to the internet I went again to see if there was any design tools to lay out diagrams like what I have seen all over on the web which brings me onto Fritzing which complies with the whole openness of Ardunio and is completely free which is always nice!

This gave me a nice interface in which to lay out the cables in a clean ordered manor (deficiently doesn’t resemble my real breadboard prototyping!)

Best thing about it is that it includes all the shields and the Ardunio images themselves have snappable cables within the interface which I liked very much, seemly you can get into the schematics and even save them to be able to be printed into a real board for you so you can make your own shields which is rather impressive but I’m sure a pretty price tag would come with such a service! So that’s my ramble of still learning how to use the Ardunio but waiting for University loan to buy a few parts and make my first larger project which may contain a robot (depends on cost)

Also the final outcome of the program into a image form is here:

Then the programming side of Arduino if you haven’t had chance to play with one is seemly similar to C but since I have never done pure C just C++ and C# but its fairly simple to pick up long as you learn the different methods which have to be in the program then theres a few Arduino specific stuff like the ability to make pins high and low and digital writes/ reads. But if you are wanting to run my very simple code which turns a LED on and off at greater than 90 degrees this is the only code you need and if you are wanting one tilt sensor the blue cables on the diagram can be removed and I just used the power horizontal lines because of my current tilt sensors like to pop out of anywhere else, no other reason so don’t comment on these are meant to be for power, still works that’s the main thing.
//Tilt sensor testing
 //Set the pin numbers of the LED and Tilt Sensor
 int inPin = 2;
 int outPin = 4;

//Set up variables
 int LEDState = HIGH;
 int reading;
 int previous = LOW;

//set some debounce values 50 seems a random number I'm not sure either but it works and that's from adafruits tutorial
 long time = 0;
 long debounce =50;

//very important function this just gets run once
 void setup()

//as the name suggests this is what runs over and over again so its important anything that changes constantly goes in here
 void loop()
 int switchState;
 if(reading != previous)
 if((millis() - time) > debounce)

So that about raps up my little Arduino segment hopefully with more money it will get a bit more interesting then a couple sensors lighting a LED but its the basics that are very important and learning about resistance and the general coding around electronics micro controllers.
Posted in Ardunio, Life and tagged as , , , , , , , ,