Wednesday, 9 November 2016

ARDUINO BASICS: BLINKNG LED CODE EXPLAINED

Serial Communication

The Arduino board can communicate at various baud (“baud rates”). A baud is a measure of how many times the hardware can send 0s and 1s in a second. The baud rate must be set properly for the board to convert incoming and outgoing information to useful data. If your receiver is expecting to communicate at a baud rate of 2400, but your transmitter is transmitting at a different rate (for example 9600), the data you get will not make sense. To set the baud rate, use the following code:
void setup(){
Serial.begin(9600);
 }
9600 is a good baud rate to start with. Other standard baud rates available on most Arduino modules include: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200 and you are free to specify other baud rates. To output a value in the Arduino window, consider the following program

void setup()
(
Serial.begin(9600);
 } 
void loop()
{
Serial.println("hello robotics ");
}



Verify the program by pressing the “verify” button (looks like a “play” button in order version or a check sign in Arduino 1.0); you should not get any errors at the bottom of the screen. If you get errors, check that only the two numbers in the code are black, the rest of the text should have been automatically recognized and assigned a color. If part of the text is black, check the syntax (often copy/pasting text from another program can include unwanted formatting) and capitalization.
Next, upload the sketch to the board using the “Upload to I/O Board” button (arrow pointing right). Wait until the sketch has finished uploading. You will not see anything unless you then select the “Serial Monitor” button (rectangle with a circle that looks like a TV in the old software, or what looks like a magnifying glass in the new software). When you select the serial monitor, make sure the baud rate selected is the same as in your program. If you want to save all your programs, we suggest creating a new folder called “reference” and save this program as Hello World.

 Blink LED Program
     
           Connect the board to the computer if it is not already connected. In the Arduino software go to File ->  Examples -> Basics -> Blink LED. The code will automatically load in the window, ready to be transferred to the Arduino. Ensure you have the right board chosen in Tools -> Board, and have the right COM port as well under Tools -> Serial Port. If you are not sure which COM port is connected to the Arduino, (on a Windows machine) go to Device Manager under COM & Ports.
Press the “Upload” button and wait until the program says “Done Uploading”. You should see the LED next to pin 13 start to blink. Note that there is already a green LED connected to most boards – you don’t necessarily need a separate LED.


CODE :-
  

 






















UNDERSTANDING THE CODE:-


pinMode(13, OUTPUT);
This sets pin 13 as an output pin. The opposite, being INPUT, would have the pin wait to read a 5V signal. Note that the ‘M’ is capitalized. A lower case ‘m’ would cause the word “pinmode” to not be recognized.
digitalWrite(13, HIGH);     and digitalWrite(13, LOW);
The line digitalWrite(pin, HIGH); puts a specified pin high to +5V. In this case we chose pin 13 since on the Uno, the LED is connected to pin 13. Replacing HIGH with LOW, the pin is set to 0V. You can attach your own LED using a digital output and the GND pin. Note that the ‘W’ is capitalized.
delay(1000);
The delay(1000); line causes the program to wait for 1000 milliseconds before proceeding (where 1000 is just a convenient example to get a 1 second delay). Note that during a delay, the microcontroller simply waits and does not execute any additional lines of code.


FEEL FREE TO COMMENT BELOW IF U HAVE ANY DOUBTS OR PROBLEMSS

No comments:

Post a Comment