Sunday 15 November 2015

Arduino tutorial 3: millis() function

If you are new for my tutorial,just check out this

Things to know about ARDUINO

ARDUINO TUTORIAL 1: Reading analog sensor

Arduino tutorial 2:basic programmings

millis()
  • It is a inbuilt function of arduino(so we need not to include any preprocessor statement to use this).
  • If you use the millis() function,it gives the number of milliseconds since the arduino started running the sketch. so it is named as millis().
  • Delay() function is also an inbuilt function as like millis().If we invoke delay() function nothing will be happen untill delay() has finished.
  • So at that time ,the response from arduino would not instantaneous.It is a drawback
  • Some critical situation you may not use delay() function in your program.Instead of that you can use millis().
  • ()-represents that it is a function.
  • This function is also used to measure frequency using arduino,to find the toggle time and most importantly for deb-ounce. 

Serial monitor
  • On top right corner of the above image is a button for Serial monitor.
  • It displays the Serial data from arduino.
  • If you want to use this ,you want to begin this in setup().
  • Serial.begin(9600) is used to begin communication to Serial monitor.9600 is the baud rate which defines the rate of speed of data transfer.
  • Serial.print("Arduino program"),this command print "Arduino program".

millis() program:

  •  In above program,Serial communication to Serial monitor is invoked in setup().
  • In loop,Reasonable delay for better visibility. you can change the delay time and you get the corresponding output change.
  • Serial.println() -It print consecutive data in new line.Instead of this if you use Serial.print() ,the new line would not be invoked.
  • just run this on your arduino and see what it will do.
millis() counter for 10 sec:

This is to count 10 sec using millis() and It is little bit complicated than what we seen before.explanation is on image itself.


   
The output of this program is :







If you have any douts,feel free to ask me in comment box.
To get more updates like my page in facebook
Learn Electronics-Facebook

Friday 6 November 2015

Arduino tutorial 2:basic programmings


Hi guys,

This is the continuity of tutorial 1, i hope you got knowledge about analog sensors and its working.

If you haven't got my tutorial 1,Here the link:
ARDUINO TUTORIAL 1: Reading analog sensor
If you miss that, Don't worry!
Go and study then you got better idea about this one.

Arduino is an integrated development environment ( both software and hardware).So only,the software to program arduino is named as Arduino IDE and it's available in www.arduino.cc.
Just go there and download and install that.
  If you are a windows user,make sure you successfully installed driver also.
 Your Arduino IDE looks like this .


In above image you can see 2 functions or Methods.One is void setup() and other is void loop()

void setup()
{
}

void-It denotes ,this function does not return any value.
setup()-It is set your projects input and output pins. 
It is used to give a overview about your project to arduino.
It is enough now,for upcoming tutorials you get a better idea about this.

void loop()
{
}
your program must be inside this loop.then only it continuously run your program.It is a never ending loop.

Now come back to reading analog sensor.The program for reading analog sensor is given below.


This program is to read the value of analog out and print it in a serial monitor(looks in right corner of arduino IDE).
  • The analogRead(a0) gets reading of analog sensor and give it to the variable sensorValue  .
  • Serial.println(sensorValue) is to print the values in serial monitor
  • delay(1) is give the appropriate delay to took reading .the delay here is 1 milli seconds .you can change it to delay(1000)-( 1000 ms=1 sec) to get a better visibility.
  • This program is available in File>Examples >Basics>analogSerialread.
  • On the top of the IDE,there is a tick symbol . It is used to compile the program.
  • On next to that,the arrow is used to send the program to arduino.
  • Before sending the program,make sure you haven't get any error.
If you have any problem for troubleshooting,make sure about your COM ports.
verify the program twice,and make sure for no error.

If you have any doubt,ask me in comment box

Follow me on facebook to get more updates:
Learn Electronics- Facebook