Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arduino & its hardware interfacing

Similar presentations


Presentation on theme: "Arduino & its hardware interfacing"— Presentation transcript:

1 Arduino & its hardware interfacing

2 What is an Arduino ? Arduino.
A microcontroller board, contains on-board power supply, USB port to communicate with PC, and an Atmel microcontroller chip. It simplify the process of creating any control system by providing the standard board that can be programmed and connected to the system without the need to any sophisticated PCB design and implementation. It is an open source hardware, any one can get the details of its design and modify it or make his own one himself. Arduino.

3 Arduino boards: UNO Mega LilyPad Arduino BT Arduino Nano Arduino Mini

4 Atmel MicroController
Arduino UNO: Digital output ~: PWM. 0,1: Serial port. In circuit Serial programming Atmel MicroController USB port Power input Analog input. Power Supply

5 Arduino is a platform Also including an Integrated Development Environment (IDE) for programming. The language itself is based in C but is largely modeled upon the language.

6 Advantages of Aurdino Open source
Simplified and user-friendly programming language No additional programmer/burner hardware required for programming board Portable Low power consumption

7 Arduino vs other environments
Support for analog input Limited Computing power Comparatively cheap Limited memory PWM output available Open source

8 Arduino Coding 2

9 Data Types and operators
Integer: used with integer variables with value between and Ex: int x=1200; Character: used with single character, represent value from -127 to 128. Ex. char c=‘r’; Long: Long variables are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647. Ex. long u=199203; Floating-point numbers can be as large as E+38 and as low as E+38. They are stored as 32 bits (4 bytes) of information. Ex. float num=1.291; [The same as double type]

10 Statement and operators:
Statement represents a command, it ends with ; Ex: int x; x=13; Operators are symbols that used to indicate a specific function: - Math operators: [+,-,*,/,%,^] - Logic operators: [==, !=, &&, ||] - Comparison operators: [==, >, <, !=, <=, >=] Syntax: ; Semicolon, {} curly braces, //single line comment, /*Multi-line comments*/

11 Statement and operators:
Compound Operators: ++ (increment) -- (decrement) += (compound addition) -= (compound subtraction) *= (compound multiplication) /= (compound division)

12 Control statements: If Conditioning: if(condition) { statements-1; …
Statement-N; } else if(condition2) Statements; Else{statements;}

13 Control statements: Switch case: switch (var) { case 1:
//do something when var equals 1 break; case 2: //do something when var equals 2 default: // if nothing else matches, do the default // default is optional }

14 Loop statements: Do… while: do { Statements; }
while(condition); // the statements are run at least once. While: While(condition) {statements;} for for (int i=0; i <= val; i++){ statements; Use break statement to stop the loop whenever needed.

15 Code structure: Void setup(){}
Used to indicate the initial values of system on starting. Void loop(){} Contains the statements that will run whenever the system is powered after setup.

16 Input and output: pinMode(); digitalRead(); digitalWrite();
delay(time_ms); other functions: analogRead(); analogWrite();//PWM.

17 Hardware interfacing A hardware interface specifies the plugs, sockets, cables and electrical signals that pass through each line between the CPU and a peripheral device or communications network.  Next slide Example of hardware interfacing project home automation by android

18 Project Components

19 Relay Test

20 Relay testing code #define relay 2 //attaches the relay to pin 2
void setup() { pinMode(relay, OUTPUT); //sets the relay as an output } void loop() { digitalWrite(relay, HIGH); //relay open delay(2000); //wait 2 seconds digitalWrite(relay, LOW); //relay closed delay(2000); //wait 2 seconds }

21 Bluetooth Test

22

23 Final hardware code part 1
String voice; #define relay1 2 #define relay2 3 void setup() { Serial.begin(9600); pinMode(relay1, OUTPUT); pinMode(relay2, OUTPUT); digitalWrite(relay1, LOW); digitalWrite(relay2, LOW); } void loop() { if(Serial.readString() && voice.length() >0){ if(voice == "*switch on"){ switchon(); } else if(voice == "*switch off"){ switchoff(); }

24 Final hardware code part 1
else if(voice == "*lamp on"){ digitalWrite(relay1, HIGH); } else if(voice == "*lamp off"){digitalWrite(relay1, LOW); } else if(voice == "*kettle on"){ digitalWrite(relay2, HIGH); } else if(voice == "*kettle off"){ digitalWrite(relay2, LOW); } } } void switchon() { digitalWrite(relay1, HIGH); digitalWrite(relay2, HIGH); } void switchoff() { digitalWrite(relay1, LOW); digitalWrite(relay2, LOW);

25 Final hardware code part 2
String voice; #define relay1 2 //Connect relay1 to pin 2 #define relay2 3 //Connect relay2 to pin 3 void setup() { Serial.begin(9600); //Set rate for communicating with phone pinMode(relay1, OUTPUT); //Set relay1 as an output pinMode(relay2, OUTPUT); //Set relay2 as an output digitalWrite(relay1, LOW); //Switch relay1 off digitalWrite(relay2, LOW); //Swtich relay2 off } void loop() { while(Serial.available()) //Check if there are available bytes to read { delay(10); //Delay to make it stable char c = Serial.read(); //Conduct a serial read if (c == '#'){ break; //Stop the loop once # is detected after a word } voice += c; //Means voice = voice + c }

26 Final hardware code part 2
if (voice.length() >0) { Serial.println(voice); if(voice == "*switch on") { switchon(); } //Initiate function switchon if voice is switch on else if(voice == "*switch off"){ switchoff(); } //Initiate function switchoff if voice is switch off else if(voice == "*lamp on"){ //You can replace 'lamp on' with anything you want...same applies to others digitalWrite(relay1, HIGH); } else if(voice == "*lamp off"){ digitalWrite(relay1, LOW); }

27 Final hardware code part 2
else if(voice == "*kettle on"){ digitalWrite(relay2, HIGH); } else if(voice == "*kettle off"){ digitalWrite(relay2, LOW); } voice=""; } } void switchon() //Function for turning on relays { digitalWrite(relay1, HIGH); digitalWrite(relay2, HIGH); } void switchoff() //Function for turning on relays { digitalWrite(relay1, LOW); digitalWrite(relay2, LOW); } /* You can add any function you want depending on how many devices you have hooked up. For example you could have a function called 'cinema' which would dim the lights and turn the TV on. You can have as many as you have pins on your arduino. For my relay 'LOW' turns off and 'HIGH' turns on The outline to follow is this: void () { digitalWrite(...., LOW/HIGH); }

28 Application for the code
you can use those two final code part 1 or part 2 for this application.

29 This was the simple basic project home automation with help of this presentation you can make voice home automation project … Thanks. Regard Mirza taimoor.


Download ppt "Arduino & its hardware interfacing"

Similar presentations


Ads by Google