DEVTOME.COM HOSTING COSTS HAVE BEGUN TO EXCEED 115$ MONTHLY. THE ADMINISTRATION IS NO LONGER ABLE TO HANDLE THE COST WITHOUT ASSISTANCE DUE TO THE RISING COST. THIS HAS BEEN OCCURRING FOR ALMOST A YEAR, BUT WE HAVE BEEN HANDLING IT FROM OUR OWN POCKETS. HOWEVER, WITH LITERALLY NO DONATIONS FOR THE PAST 2+ YEARS IT HAS DEPLETED THE BUDGET IN SHORT ORDER WITH THE INCREASE IN ACTIVITY ON THE SITE IN THE PAST 6 MONTHS. OUR CPU USAGE HAS BECOME TOO HIGH TO REMAIN ON A REASONABLE COSTING PLAN THAT WE COULD MAINTAIN. IF YOU WOULD LIKE TO SUPPORT THE DEVTOME PROJECT AND KEEP THE SITE UP/ALIVE PLEASE DONATE (EVEN IF ITS A SATOSHI) TO OUR DEVCOIN 1M4PCuMXvpWX6LHPkBEf3LJ2z1boZv4EQa OR OUR BTC WALLET 16eqEcqfw4zHUh2znvMcmRzGVwCn7CJLxR TO ALLOW US TO AFFORD THE HOSTING.

THE DEVCOIN AND DEVTOME PROJECTS ARE BOTH VERY IMPORTANT TO THE COMMUNITY. PLEASE CONTRIBUTE TO ITS FURTHER SUCCESS FOR ANOTHER 5 OR MORE YEARS!

Engineering with the Arduino

The Arduino is a microcontroller placed on a single board along with its necessary components to compute. Its purpose is to provide readily available projects in electronics and mostly robotic engineering while at the same time providing a cheap price. They can be either pre-assembled if bought from one of their retailers, can come in kits or you can even build one yourself by using their schematics available on their website. The Arduino series consist of different kinds of boards with more or less functions, typically designed for different purposes. The most famous and used board is the Arduino Uno, to this date the Revision 3 board is the newest. In these tutorials, I will be programming and dealing with the Arduino Uno R3 so it’s recommended you get the same board too.

Installing the IDE

Arduino’s IDE is based off of Processing, another programming language and the Wiring projects. Its IDE is supposed to be very user friendly to people who doesn’t have much prior programming experience. Having color coded syntax and brace matching, even the simplest of people can use it depending on if they dedicate enough time. The language is based off of C and C++, and its library is based off of the Wiring Projects which allows input and output. The software is also available cross-platform so you can use it on almost all computers, in which you can download here.

Basic Syntax

Like I’ve said before, Arduino’s environment as well as the language is user friendly. There are really only two important functions the user has to create in order for a full ‘sketch’ to work:

  • setup() : Anything in this function will only run once first things first. Acting as a initialization to any code you place in here.
  • loop() : Anything in this function will be constantly ran until the board’s power is off.

If you were to do a bare minimum sketch, it would look something like this:

void setup() {
  // Code to run once:
}

void loop() {
  // Code to run again and again:
}

It’s pretty simple, also notice that I place two forward slashes behind one of the two sentences. This is a comment; the interpreter will ignore any line with two forward slashes, allowing the user to create a visual aid for them if you will. Once we got that part dealt with, we can step it up a little bit.

Hello LED

Rather than doing a Hello World application (notably because of no LCD displays on the Arduino by default), most user’s first test is usually a blinking LED. The code would look like this:

int led = 13;

void setup() { //the setup routine runs once when you press reset:
 pinMode(led, OUTPUT); // initialize the digital pin as an output.
}

// the loop routine runs over and over again forever:
void loop() {
 digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(1000);               // wait for a second
 digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
 delay(1000);               // wait for a second
}

It sounds and looks pretty complicated to you, and since we’re dealing with an electrical engineering project board I expect you to have the necessary tools. Right now, all we need is a suitable resistor and any standard 3mm LED. On the right is the circuitry schematic of how you should build the layout. LEDs are polarized so you would need to connect the anode (the right side or longer pins of the LED) to the resistor and then to the 13th header. Now that you have your LED set up, you are free to upload the ‘sketch’. If you want to stop the blinking process, all you have to do is unplug the board’s USB from the computer. I’m now going to breakdown each line of code and explain to you on what each one does (note that you end each line of code with a semicolon):

  • ‘int led = 13;’ is assigning an integer variable named ‘led’, and giving it the number 13
  • ‘pinMode(led, OUTPUT);’ ‘pinMode’ is assigning an input or output to any of the female headers on the board. You can use the variable ‘led’ that we created earlier, using it instead of the actual number 13. I’m adding another argument called ‘OUTPUT’ next to it which prepares Arduino to send out an active current from the pin ’13’.
  • ‘digitalWrite(led, HIGH);’ ‘digitalWrite’ is sending out the actual current to that pin (which is 13, should be obvious by now). Instead of using ‘1’ or on or ‘0’ or off, you can use HIGH which is another form of on and LOW which is off.
  • ‘digitalWrite(led, LOW);’ you can read the sentence above this, but this basically tells Arduino to stop sending out an electrical current from the pin.
  • ‘delay(1000);’ if we didn’t add a delay between the ‘HIGH’ and ‘LOW’ commands for the pin, we didn’t see the LED blink since the microprocessor is repeating the loop fast. In order to counter this you can add a ‘delay’ command which microseconds as the unit of time, so 1000 microseconds is a second in conversion.

After reading that, it should make a lot more sense to you. Hopefully you can flawlessly tinker around with the speed, change the pins and try it out yourself if you will. This is only the bare bones of electrical engineering with the help of a computer, so stay tuned for more!



Electrical Engineering


QR Code
QR Code engineering_with_the_arduino (generated for current page)
 

Advertise with Anonymous Ads