arduino by bishal bhattarai ioe, pashchimanchal campus pokhara, nepal

Post on 16-Aug-2015

143 Views

Category:

Engineering

8 Downloads

Preview:

Click to see full reader

TRANSCRIPT

GENERATING PROJECTS IDEA ON

bishalbtry@gmail.com1

BY:BISHAL BHATTARAIIOE, 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

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

2. Arduino Boards:

2. Arduino Boards cont…

Arduino miniFLORA

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++

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

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

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

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)*

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

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

6.Arduino Uno Description cont..

6.Arduino Uno Description cont..

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

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

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 }

1. LED BLINK Proteus circuit

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);

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); }}

2.LED FADINGProteus circuit:

3.Variable resistor controlledLED BLINK

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);}

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

LCD Introduction:

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

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);• }

7. Keyboard interface:

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

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 );

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);• }• }

8. Digital thermometer:

REQUREMENT:

16X2 LCD

Arduino uno

8. Digital thermometer:

Circuit Diagram

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}

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)

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 )}

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….

bishalbtry@gmail.com 38

9. Motor Control cont..

bishalbtry@gmail.com 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 );

bishalbtry@gmail.com 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);• }

bishalbtry@gmail.com 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();• }• • }• }

bishalbtry@gmail.com 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);• }

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

bishalbtry@gmail.com 44

10. Controlling Servo motor:

10. Ultra sonic sensor for Distance calculation

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

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);}

bishalbtry@gmail.com 47

10. Ultra sonic sensor for Distance calculation cont..

THANK YOU

bishalbtry@gmail.com

top related