ARDUINO           
Tutorial Series
Led Intensity Control,Motor Control,Serial Communication etc..

 Posted by  Vivek Singh on September 20, 2015

Intro to Arduino :

Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. All this is defined by a set of instructions programmed through the Arduino Software (IDE). 

Over the years Arduino has been the brain of thousands of projects, from everyday objects to complex scientific instruments. A worldwide community of makers - students, hobbyists, artists, programmers, and professionals - has gathered around this open-source platform, their contributions have added up to an incredible amount of accessible knowledge that can be of great help to novices and experts alike.

Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping, aimed at students without a background in electronics and programming. As soon as it reached a wider community, the Arduino board started changing to adapt to new needs and challenges, differentiating its offer from simple 8-bit boards to products for IoT applications, wearable, 3D printing, and embedded environments. All Arduino boards are completely open-source, empowering users to build them independently and eventually adapt them to their particular needs. The software, too, is open-source, and it is growing through the contributions of users worldwide.

Arduino UNO

Led Blink

The Arduino has rows of connectors along both sides that are used to connect to electronic devices and plug-in 'shields' that allow the Arduino to do more. 

However, the Arduino also has a single LED that you can control from your sketches. This LED is built onto the Arduino board and is often referred to as the 'L' LED as this is how it is labelled on the board.

Arduino uno Led Placement

Loading the 'Blink' Example

We may find that your Arduino board's 'L' LED already blinks when you connect it to a USB plug. This is because Arduino boards are generally shipped with the 'Blink' sketch preinstalled. 

In this we will reprogram the Arduino with our own Blink sketch and then change the rate at which it blinks.Setup your Arduino IDE and made sure that you could find the right serial port for it to connect to your Arduino board. The time has now come to put that connection to the test and program your Arduino board. Load the 'Blink' sketch that you will find in the IDE's menu system under File→ Examples→ 01.Basics 

Arduino IDE

When the sketch window opens, enlarge it so that you can see the whole of the sketch in the window.

Uploading Blink to the Board

Attach your Arduino board to your computer with the USB cable and check that the 'Board Type' and 'Serial Port' are set correctly.

If you watch the status area of the IDE, you will see a progress bar and a series of messages. At first it will say 'Compiling Sketch..'. This converts the sketch into a format suitable for uploading to the board.
Next, the status will change to 'Uploading'. At this point, the LEDs on the Arduino should start to flicker as the sketch is transferred.
Finally, the staus will change to 'Done'.


How 'Blink' Works

Here is the code for the Blink sketch.

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, 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
}

The first thing to note is that quite a lot of this sketch is what is called 'comments'. Comments are not actual program instructions, they are just comments about how the program works. They are there for out benefit, so that there is some explanation to accompany the sketch. 

Everything between /* and */ at the top of the sketch is a block comment, that explains what the sketch is for. 

There are also single line comments that start with // and everything up intil the end of the line counts as being a comment. 

The first actual line of code is:

int led = 13;

As the comment above explains, this is giving a name to the pin that the LED is attached to. This is 13 on most Arduinos, including the Uno.
Next, we have the 'setup' function. Again, as the comment says, this is run when the reset button is pressed. It is also run whenever the board resets for any reason, such as power first being applied to it, or after a sketch has been uploaded.

void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

Every Arduino sketch must have a 'setup' function, and the part of it where you might want to add instructions of your own is between the { and the }.
In this case, there is just one command there, which, as the comment states tells the Arduino board that we are going to use the LED pin as an output.

It is also mandatory for a sketch to have a 'loop' function. Unlike the 'setup' functio n that o nly runs o nce, after a reset, the 'lo o p' function will, after it has finished running its commands, immediately start again.

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
}

Inside the loop function, the commands first of all turn the LED pin on (HIGH), then 'delay' for 1000 milliseconds (1 second), then turn the LED pin off and pause for another second.




Comments:


If You Like this tutorial series, Please Like our Page


Top