Friday, January 17, 2020

Simple Arduino program, blinking a LED for beginners

A Simple Arduino program, blinking a LED for beginners

Introduction:- Arduino  board is a complete board for learning use of micro controller.It uses micro controller IC ATMega328 16 Mega Hertz. It is 8 bit micro controller with 32 kb of program memory. It has inbuilt programmer to upload program through USB port. Input dc supply jack is provided for giving input dc supply 8-12 volt. Inbuilt voltage regulator are used to provide 5 volt and 3.3 volt regulated power supply for internal use. 13 numbers digital input / output pins are provided for external devices connection. one LED is internally connected to pin number 13. Analog I/O pins, PWM pin and serial transfer Rx Tx pins are also provided.




Micro controller is a very small computer on a single chip. It consist of inbuilt CPU, storage memory, input output ports. Arduino board has every thing required for use of micro controller. It needs to upload a program and run. In this post I am writing a very small program to explain program structure and syntax use for Arduino programming. It used open source integrated environment development software for arduino. Screen shot of arduino IDE for windows is as shown below. Software can be downloaded from net.


When you open this arduino IDE in PC you will see this screen. Open blink example from menu bar
file  examples//basic/ blink . you will see screen open with above code. now please see the code it is similar to c++ programming language. this is very first and small program for beginners. first part of program is void setup() in this function we write the code which has to executed  only once. To use any digital input/output pin we have to configure the pin as input or output with a line of code like pinMode(pin number, OUTPUT/INPUT). Here we are using function pinMode to declare LED_BUILTIN (pin 13) as a output pin.

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

Second part of program is loop function it runs continuously till the program is not stopped.
In loop function   digitalWrite(LED_BUILTIN, HIGH);  is use to write (give) a high value to  LED_BUILTIN (pin  13). when high value is given to pin 13 led connected to this pin gets on. Function   delay(1000);   Provides a delay of 1000 mili  seconds. This keeps pin 13 high for 1000 ms. Then the function digitalWrite(LED_BUILTIN, LOW);  is use to write low on  LED_BUILTIN (pin  13). When low value is given to pin 13 led connected to this pin gets off. Again function delay(1000); is used to give 1000 ms off time for pin 13 led. this complete code is repeated continuously as it is in loop function. Code for loop function is as given below.

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

After writing the program code in editor window it need to compile. in editor. Below menu bar there is a tool bar. In tool bar there are tab buttons for compile and upload the program.there is tool tip on each button. so by clicking on compile button program will compile and a message of successfully compiled or some error will display in output window.if your program is written correctly it will compile successfully.after compile we have to upload the program in Arduino board. For this we have to connect our board to computer with the help of USB cable which comes with board. The USB cable serves two purpose first it gives the power supply to the board and second it upload the hex code to the board. As soon as code upload is completed a message is displayed on IDE that upload is completed. Now micro controller runs this program and you will see that led connected to pin 13 starts blinking at the rate  of 1 second off and 1 second on. To blink a led can be done by any electronic circuit. but to change on/ ff duration will required to change components. With micro controller we have to change delay time in our program and upload. you can experiment by changing time period. any other output pin can also be use to control other led. We can also use 5 volt miniature relay in place of led and control any device from relay. Maximum output current of any output pin is max 50 ma. so we should be care full to connect load to pin that current should be in safe limit. Arduino is very vast can not be cover in such a small post. so for any doubt please ask in comment or take some help from net.
This program as well as many programs are given in  examples of arduino IDE that can be used for further learning. I hope this post will help full to you. your valuable suggestion and comments are welcome for improvement.



https://vijayelectronicsforu.blogspot.com/2018/06/transformer-introduction-and.html

https://vijayelectronicsforu.blogspot.com/2018/06/dc-motor-construction-and-working.html

http://vijayelectronicsforu.blogspot.com/2018/07/radio-receiver-block-diagram.html

4 comments:

  1. Thank you for this useful information :)

    ReplyDelete
  2. If I see a good post, you will not go without praising me, because every word written in the post you have written is very thoughtful, your way of writing is very beautiful and your views are also very good. This is a commendable post, as much as this post is praised, it is less, you should keep writing more beautiful posts in your life.
    Desi Girls Gurugram
    Escort Services in Noida
    Gurugram Call Girls Service
    Ordinary call girls in Gurugram

    ReplyDelete