Arduino by bishal bhattarai IOE, Pashchimanchal Campus Pokhara, Nepal

48
GENERATING PROJECTS IDEA ON [email protected] 1 BY:BISHAL BHATTARAI IOE, Pashchimanchal Campus Pokhara, Nepal

Transcript of Arduino by bishal bhattarai IOE, Pashchimanchal Campus Pokhara, Nepal

Page 1: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

GENERATING PROJECTS IDEA ON

[email protected]

BY:BISHAL BHATTARAIIOE, Pashchimanchal Campus

Pokhara, Nepal

Page 2: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

TOPICS:

1. Introduction to Arduino

2. Arduino Boards

3. Integrated Development Environment-IDE

4. What it can do?

5. Why arduino?

6. Arduino Uno complete description

7. Projects

Page 3: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

1. Introduction:

• First Arduino was introduced in 2005• Arduino is an open-source prototyping platform • It is based on easy-to-use hardware and software• Microcontroller board design manufactured

primarily by Smart Projects in Italy

Open Source Hardware

Page 4: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

2. Arduino Boards:

Page 5: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

2. Arduino Boards cont…

Arduino miniFLORA

Page 6: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

3. Integrated Development Environment(IDE):

•IDE a cross-platform application written in Java

• Designed to introduce programming to artists and other newcomers unfamiliar with software development

• Code editor with features such as:  i. syntax highlighting ii. brace matching iii. automatic indentation• Compiling and uploading programs to the board with a single click • A program or code written for Arduino is called a "sketch”• Arduino programs are written in C or C++

Page 7: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

3. IDE cont…

• The Arduino IDE comes with a software library called "Wiring”

• Two functions to make an executable cyclic executive program:

•setup(): function run once at the start of a program that can initialize settings•loop(): function called repeatedly until the board powers off

Page 8: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

3. IDE cont…

Functions in Setup()1. pinMode(13,OUTPUT)://makes pin 13 as output pin2. pinMode(8, INPUT);//makes pin 8 as input pin3. Serial.begin(9600) ;//starts serial communication

with Baudrate 9600Functions in loop()• 1. digitalWrite(13, HIGH): makes pin 13 high ie pin13=ON;• 2. delay(500) : delays system by 500 ms.• 3. analogRead() : Reads analog value• 4. analogWrite() : writes anlog value(PWM)• 5. Serial.print() : Prints at serial monitor• 6. Serial.println() : prints at serial monitor with line break

Page 9: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

3. IDE cont…

1.Verify

2.Upload

3.NEW

4.Open :Library, example

5.Save

7.Message Panel

6.Code Panel

*Port connected to IDE/Arduino board

*Tool: port setting, board selection

*Serial Monitor

Page 10: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

4. What it can do?

• Sensors ( to sense stuff )

– Push buttons*, touch pads, tilt switches.– Variable resistors* (eg. volume knob / sliders)– Photoresistors* (sensing light levels)– Thermistors* (temperature)– Ultrasound (proximity range finder)

• Actuators ( to do stuff )

– Lights, LED’s*– Motors*– Speakers– Displays (LCD)*

Page 11: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

5.Why Arduino?

• Simplify working with microcontr• Inexpensive compare to other u-controller platform• Cross platform• Simple, clear programming environment • Simple, clear programming environment • Open source and extensible hardware

Page 12: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

6.Arduino Uno Description:

Digital output~: PWM.1,0: Serial port Tx and Rx

In circuit Serial programming

Atmel MicroController

Analog input.Power out and In

USB port for power or programming

12v Power input

13 pin LED

POWER on/off LED

Page 13: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

6.Arduino Uno Description cont..

Page 14: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

6.Arduino Uno Description cont..

Page 15: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

7. Projects Idea:

1. LED Blink program

2. LED Fading

3. Variable Resistor controlled LED Blink

4. Variable Resistor controlled LED Intensity

5. LCD Interface

6. Keyboard Interface

Page 16: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

7. Projects Idea cont…

7. Digital thermometer

8. Motor control via Button

9. Variable Resistor Controlled Servo Motor

10. Ultra Sonic Sensor Interface for Distance calculation

Page 17: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

1. LED BLINK

// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(13 LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second }

Page 18: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

1. LED BLINK Proteus circuit

Page 19: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

2.LED FADING:int ledPin = 9; // LED connected to digital pin 9void setup() { pinMode(ledPin, OUTPUT); // nothing happens in setup}void loop() { // fade in from min to max in increments of 5 points: for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { analogWrite(ledPin, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30);

Page 20: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

2.LED FADING cont….

} // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(ledPin, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); }}

Page 21: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

2.LED FADINGProteus circuit:

Page 22: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

3.Variable resistor controlledLED BLINK

Page 23: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

3.Variable resistor controlledLED BLINK cont..

int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 13; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensor

void setup() { pinMode(ledPin, OUTPUT);pinMode(lsensorPin, INPUT);}

void loop() { sensorValue = analogRead(sensorPin); digitalWrite(ledPin, HIGH); delay(sensorValue); digitalWrite(ledPin, LOW); delay(sensorValue);}

Page 24: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

4. Variable resistor controlledLED Intensity

Do Yourself……..IDEA to program this:1. Read variable resistor value assign it to ‘C’2. Convert this ‘C’ value so that you supply that

amount voltage to output pin3. write this value to PWM pin using

analogWrite() function

Page 25: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

LCD Introduction:

Page 26: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

6.LCD Interface:

*4 to 4lcd *5 to 6lcd *6,7,8,9 To 11, 12 13, 14 resp*VSS , R/W to Gnd *VDD to power

Page 27: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

6.LCD Interface:

• #include <LiquidCrystal.h>• LiquidCrystal lcd(4, 5, 6, 7, 8, 9); // pins for RS, E, DB4, DB5, DB6, DB7• void setup()• {• lcd.begin(16,2);• lcd.clear();• }• void loop()• {• lcd.setCursor(5,0);• lcd.print("Hello");• lcd.setCursor(5,1);• lcd.print("world!");• delay(10000);• }

Page 28: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

7. Keyboard interface:

Page 29: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

7. Keyboard interface:

LCD:RS,E,11,12,13,14To:A0,A1,A2,A3,A4,A5*Vss –Gnd, *VDD-power*R/W- GndKeyboard:(8,7,6)A to (1,2,3)K(5,4,3,2)A to (ABCD)K

5

432

8 7 6

Page 30: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

7. Keyboard interface cont..• #include <LiquidCrystal.h>• #include <Keypad.h>• LiquidCrystal lcd(A0,A1,A2, A3, A4, A5);• const byte ROWS = 4; //four rows• const byte COLS = 3; //three columns• char keys[ROWS][COLS] = {• {'1','2','3'},• {'4','5','6'},• {'7','8','9'},• {'*','0','#'}• };• byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad• byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad• Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

Page 31: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

7. Keyboard interface cont..• void setup(){• lcd.begin(16,2);• lcd.clear();• lcd.setCursor(0,0);• keypad.setHoldTime(500); // Default is 1000mS• keypad.setDebounceTime(50); // Default is 50mS• }

• void loop(){• char key = keypad.getKey();• if(key)• {• lcd.print(key);• }• }

Page 32: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

8. Digital thermometer:

REQUREMENT:

16X2 LCD

Arduino uno

Page 33: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

8. Digital thermometer:

Circuit Diagram

Page 34: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

8. Digital thermometer: CODE:

#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 5, 6, 7, 8, 9);int sensorPin = A0; //analog pin location

void setup(){ Serial.begin(9600); //Start the serial connection with the computer lcd.begin(16,2); //Must be defined or it goes to 16X1 lcd.clear(); // Starts with a clean screen}

Page 35: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

8. Digital thermometer: CODE cont..

void loop() { //getting the voltage reading from the temperature sensor int reading = analogRead(sensorPin); // converting that reading to voltage, for 3.3v arduino use 3.3 float voltage = reading * 5.0; voltage /= 1024.0; // now print out the temperature (voltage-0.5) float temperatureC = (voltage ) * 100 ; //converting from 10 mv per degree

wit 500 mV offset //to degrees ((voltage - 500mV) times 100)

Page 36: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

8. Digital thermometer: CODE cont..

lcd.setCursor(0,0); lcd.print(temperatureC); lcd.println(" Celsius "); //Shows reading on LCD // now convert to Fahrenheit float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; lcd.setCursor(0,1); lcd.print(temperatureF); lcd.println(" Fahrenheit"); //Shows reading on LCD delay(500); //Update every 5 seconds, the value is

measured in milliseconds )}

Page 37: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

9. Motor Control:

Requirements:1. Keyboard interface idea2. Motor interface with digital o/p pin3. Condition checking process in program if…else, switch(), OR anything….

Page 38: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

[email protected] 38

9. Motor Control cont..

Page 39: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

[email protected] 39

9. Motor Control cont..

• const int motorR = 13; //right direction motion assign pin • const int motorRB = 12;//right direction backward motion assign pin • const int motorL = 11; //left direction motion assign pin • const int motorLB = 10;//left direction backward motion assign pin • #include <Keypad.h>• const byte ROWS = 2; //2 rows• const byte COLS = 2;//2 column• char keys[ROWS][COLS] = {• {'1','2'},• {'3','4'},• };• byte rowPins[ROWS] = {5, 4}; //connect to the row pinouts of the keypad• byte colPins[COLS] = {8, 7};// to coloumn pinout• Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

Page 40: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

[email protected] 40

9. Motor Control cont..

• void setup() {• // initialize the LED pin as an output:• pinMode(motorR, OUTPUT);• pinMode(motorRB, OUTPUT);• pinMode(motorL, OUTPUT);• pinMode(motorLB, OUTPUT);• pinMode(9, OUTPUT);• pinMode(6, OUTPUT);• // initialize the pushbutton pin as an input:• keypad.setHoldTime(500);• }

Page 41: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

[email protected] 41

9. Motor Control cont..

• void loop() {• char key = keypad.getKey();• if(key)• {• switch(key)• {• case ('1'): • right();• break;• case ('2'):• left();• break;

• case ('3'):• forward();• break;• case ('4'):• backward();• break;• default:• stopp();• }• • }• }

Page 42: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

[email protected] 42

9. Motor Control cont..• void right()• { digitalWrite(9,HIGH);• digitalWrite(6,LOW);• digitalWrite(motorR,HIGH);• digitalWrite(motorRB,LOW);• delay(300);• digitalWrite(motorR,HIGH);• digitalWrite(motorRB,HIGH);• }

• void left()• { digitalWrite(6,HIGH);• digitalWrite(9,LOW);• digitalWrite(motorL,HIGH);• digitalWrite(motorLB,LOW);• delay(300);• digitalWrite(motorL,HIGH);• digitalWrite(motorLB,HIGH);• }

• void forward()• { digitalWrite(9,HIGH);• digitalWrite(6,HIGH);• digitalWrite(motorR,HIGH);• digitalWrite(motorRB,LOW);• digitalWrite(motorL,HIGH);• digitalWrite(motorLB,LOW);• delay(300);• digitalWrite(motorL,HIGH);• digitalWrite(motorLB,HIGH);• digitalWrite(motorR,HIGH);• digitalWrite(motorRB,HIGH);• }• void backward()• { digitalWrite(9,HIGH);• digitalWrite(6,HIGH);• digitalWrite(motorR,LOW);• digitalWrite(motorRB,HIGH);

• digitalWrite(motorL,LOW);• digitalWrite(motorLB,HIGH);• delay(300);• digitalWrite(motorL,HIGH);• digitalWrite(motorLB,HIGH);• digitalWrite(motorR,HIGH);• digitalWrite(motorRB,HIGH);• }

• void stopp()• { digitalWrite(9,HIGH);• digitalWrite(6,HIGH);• digitalWrite(motorL,HIGH);• digitalWrite(motorLB,HIGH);• digitalWrite(motorR,HIGH);• digitalWrite(motorRB,HIGH);• }

Page 43: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

10. Controlling Servo motor:

Requirements:1. Potentiometer interface2. Motor interface3. Variable data from POT applying to motor

interface pin4. Code on IDE: File>>Example>>servo>>knobOR follow the note code

Page 44: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

[email protected] 44

10. Controlling Servo motor:

Page 45: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

10. Ultra sonic sensor for Distance calculation

Requirements:1. Ultrasonic sensor2. LCD3. Arduino 4. Concept:Vcc (+5V)Trig (Trigger)EchoGND

Page 46: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

10. Ultra sonic sensor CODE:

#define trigPin1 8#define echoPin1 7long duration, distance, UltraSensor;void setup(){Serial.begin (9600);pinMode(trigPin1, OUTPUT);pinMode(echoPin1, INPUT);}void loop() {SonarSensor(trigPin1, echoPin1);UltraSensor = distance;Serial.println(UltraSensor);}

void SonarSensor(int trigPin,int echoPin){digitalWrite(trigPin, LOW);delayMicroseconds(2);digitalWrite(trigPin, HIGH);delayMicroseconds(10);digitalWrite(trigPin, LOW);duration = pulseIn(echoPin, HIGH);distance = (duration/2) / 29.1;delay(100);}

Page 47: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

[email protected] 47

10. Ultra sonic sensor for Distance calculation cont..

Page 48: Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal

THANK YOU

[email protected]