Arduino for beginners •Arduino is a open-source • It consists of a circuit board, which can be programed (referred to as a microcontroller) a • a ready-made software called Arduino IDE
3.
Features of Arduino •Analog and Digital data • Various sensor , actuator, led, cloud • Control board through Arduino IDE • USB • C++, Packages
Arduino Board description 9.ICSP pin (12) 10. Power LED indicator(13) 11. Tx and Rx LEDs(14) 12. Digital IO(15) 13. AREF (16)
9.
Arduino installation • Arduinoboard any type • USB cable (A to B type) • Download Arduino IDE software. • Power up your board • Launch Arduino IDE • Open your first project
Data Types inprogramming void Boolean char Unsigned char byte int Unsigned int word long Unsigned long short float double array String-char array String- object
Function type int sum_func(int x, int y) // function declaration { int z = 0; z = x+y ; return z; // return the value } void setup () { Statements // group of statements } void loop () { int result = 0 ; result = Sum_func (5,6) ; // function call }
digitalWrite • Digital writefunction is used to write LOW or HIGH • digitalWrite(pin, value) • analogRead(pin ,value)
22.
int button =5 ; // button connected to pin 5 int LED = 6; // LED connected to pin 6 void setup () { pinMode(button , INPUT_PULLUP); // set the digital pin as input with pull-up resistor pinMode(button , OUTPUT); // set the digital pin as output } void setup () { If (digitalRead(button ) == LOW) // if button pressed { digitalWrite(LED,HIGH); // turn on led delay(500); // delay for 500 ms digitalWrite(LED,LOW); // turn off led delay(500); // delay for 500 ms } }
23.
LED blinking • ComponentsRequired • You will need the following components − • 1 × Breadboard • 1 × Arduino Uno R3 • 1 × LED • 1 × 330Ω Resistor • 2 × Jumper
Code to BlinkLED void setup() { // initialize digital pin 13 as an output pinMode(2, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(2, HIGH); delay(1000); // wait for a second digitalWrite(2, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
26.
PIR sensor • ComponentsRequired • You will need the following components − • 1 × Breadboard • 1 × Arduino Uno R3 • 1 × PIR Sensor (MQ3)
Button to LEDglow const int buttonPin = 8; // the number of the pushbutton pin const int ledPin = 2; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } }