Tuesday, August 16, 2016

Blink

This program is about

  • Turns on an LED on for one second, then off for one second, repeatedly.
Important - Most Arduinos have an on-board LED you can control. On the Uno and

                  Leonardo, it is attached to digital pin 13. If you're unsure what
                  pin the on-board LED is connected to on your Arduino model, check
                  the documentation.
According to the above selection set a LED(+ pin) to 13th pin of the arduino board. Then it's (-) pin should connect arduino board ground port.

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

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

Write this code in compiler. Then verify -> Upload.

  • the setup function runs once when you press reset or power the board.
After upload code to the arduino. You will see the blinking LED. 





Sunday, August 7, 2016

Analog Read Serial

Analog Read Serial

       Before you start to write programs you should download the relevant compiler.  To download the compiler before you should check the version according to your computer/ Your operating system. Assume your computer has Windows Operating System, You should download the Windows Installer.  
       After install the compiler successfully connect Arduino device to the computer.
Then open the compiler, If it successfully connected you will see the device name under the left-hand side down corner. go to Tools -> Port. Then you will see the port number connected to the device. 

       This program is about 
  • Reads an analog input on pin 0, prints the result to the serial monitor.
  • Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  •  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

void setup() { // initialize serial communication at 9600 bits per second: 
  Serial.begin(9600);
}

void loop() {// the loop routine runs over and over again forever:
  int sensorValue = analogRead(A0);  // read the input on analog pin 0: 
  Serial.println(sensorValue); // print out the value you read:
  delay(1);        // delay in between reads for stability
}

To demonstrate that program we connect LM35 temperature sensor to thr A0 port.
Then go to Tools -> serial Plotter, you will see the temperature value on it.