Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arduino Part 1 Topics: Microcontrollers Programming Basics

Similar presentations


Presentation on theme: "Arduino Part 1 Topics: Microcontrollers Programming Basics"— Presentation transcript:

1 Arduino Part 1 Topics: Microcontrollers Programming Basics
Digital Output Serial Communication

2 Workshop Overview Introduction to microcontroller and Arduino
The Hardware: Arduino UNO The Software: The Arduino IDE The Language : Arduino-C language Hands-on Project 1: Talking to arduino Hands-on Project 2: LED blinking Hands-on Project 3: Serial Controlled LED

3 What is an Arduino? An open-source platform used for building electronics projects A complete controller with CPU, RAM, Flash memory, and input/output pins, all on a single chip

4 The Hardware : Arduino UNO
USB(Power) Barrel jack(Power) Ground 5V supply 3.3V supply Analog input Digital input PWM output Analog Ref input Reset Button Power indicator RX, TX indicator Main IC Voltage Regulator Built in test LED connected to pin13

5 Getting Started Check out: http://arduino.cc/en/Guide/HomePage
Download & install the Arduino environment (IDE) Connect the board to your computer via the USB cable If needed, install the drivers Launch the Arduino IDE Select your board Select your serial port

6 The Software : Arduino IDE
3 4 1 5 Verify button Upload button New file button Open file button Safe file button Program area Status bar Notification area 2 } 6 } 7 } 8

7 Select Serial Port and Board

8 Opening sample program

9 Our First program/sketch
What’s Next?? Press verify button to check for errors Press upload button to load the program into the arduino Observe the on-board LED

10 Status Messages todbot.com/blog/bionicarduino

11 The Language : Arduino - C
Basic program structure : setup( ): A function present in every Arduino. Run once before the loop( ) function. Often used to set pinmode to input or output. loop( ): A function present in every single Arduino sketch. This code happens over and over again. The loop( ) is where (almost) everything happens. The one exception to this is setup( ) and variable declaration.

12 The Language : Arduino - C
The setup: To assign a port to read signal use: pinMode(pinNumber,INPUT); To assign a port to send signal use: pinMode(pinNumber,OUTPUT) To initialize serial communication at 9600 bits per second : Serial.begin(9600);

13 The Language : Arduino - C
Digital I/O: • Digital Input/Output uses the Digital pins, but Analog In pins can be used as Digital • To receive a Digital signal use: digitalRead(pinNumber); • To send a Digital signal use: digitalWrite(pinNumber, value); • Digital Input and Output are always either HIGH or LOW Analog I/O: • Analog Input uses the Analog In pins, Analog Output uses the PWM pins • To receive an Analog signal use: analogRead(pinNumber); • To send a PWM signal use: analogWrite(pinNumber, value); • Analog Input values range from 0 to 1023 (1024 values because it uses 10 bits, 210) • PWM Output values range from 0 to 255 (256 values because it uses 8 bits, 28).

14 The Language : Arduino - C
Time/delay functions: delay(ms) : eg. To wait for 1sec, use delay(1000) delayMicroseconds(us) : eg. To wait for 0.001sec, use delayMicroseconds(1000) millis() : once this function is called, it will update the variable every miliseconds micros() : once this function is called, it will update the variable every microseconds More commands: arduino.cc/en/Reference/HomePage

15 The Language : Arduino - C
Serial communication functions: Used for communication between the Arduino board and a computer or other devices. Serial.begin(9600) : to opens serial port, sets data rate to 9600 bps Serial.print() : Prints data to the serial port as human-readable ASCII text. Serial.println() : Prints data at the following line Serial.available() : Get the number of bytes (characters) available for reading from the serial port. Serial.read() : read the incoming data byte Serial.write() : Writes binary data to the serial port. This data is sent as a byte or series of bytes; to view serial output, click on the serial monitor at the arduino IDE: Serial monitor More commands: arduino.cc/en/Reference/HomePage

16 Hands-on Project 1: Talking to arduino
2 The hardware setup: Write the code/sketch: Int Data = 0;    void setup() {         Serial.begin(9600);      } void loop() {         if (Serial.available() > 0) {       Data = Serial.read();                  Serial.print("you have entered: "); Serial.write(Data); Serial.println();          } }

17 Hands-on Project 1: Talking to arduino
3 4 Load the program into arduino Open serial monitor and observe the output Press verify button to check for errors Press upload button to load the program into the arduino Serial monitor

18 Hands-on Project 2: LED Blinking
1 2 The hardware setup: Write the code/sketch: void setup() { serial.begin(9600); pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); serial.println(“ LED ON”); delay(1000); digitalWrite(13, LOW); serial.println(“ LED OFF”);

19 Hands-on Project 2 : LED Blinking
3 4 Load the program into arduino Observe the output on the board and open serial monitor Press verify button to check for errors Press upload button to load the program into the arduino Serial monitor

20 Hands-on Project 3: Serial controlled LED
1 2 The code/sketch: The hardware setup: void setup() { Serial.begin(9600); pinMode(13, OUTPUT); } void loop() { if (Serial.available() > 0) { int inByte = Serial.read(); switch (inByte) { case 'a': digitalWrite(13, HIGH); break; case 'b': digitalWrite(13, LOW);

21 Hands-on Project 3 : Serial controlled LED
4 Press the letter ‘a’ or ‘b’ from your keyboard and observe your led Load the program into arduino Press verify button to check for errors Press upload button to load the program into the arduino

22 References www.arduino.cc www.ladyada.net/learn/arduino


Download ppt "Arduino Part 1 Topics: Microcontrollers Programming Basics"

Similar presentations


Ads by Google