Arduino Tutorial

Learn Arduino in the easiest way

Created by Zhang Tingliang using reveal.js

Hello Real World !

Arduino enables me to create beautiful interactive projects. This presentation will show you examples of what it can do and how!

Arduino tutorial

https://www.bilibili.com/video/av70012484

https://youtu.be/CwptegtP2hU

supplies

  1. Arduino UNO(made in china)
  2. Dupont Line
  3. Potentiometer
  4. LED
  5. Bluetooth module
  6. Servo motor

reveal.js settings

Here are settings of Transition Styles and Themes.

Use the Space key to navigate through all slides.


Down arrow

Transition Styles

You can select from different transitions, like:
None - Fade - Slide - Convex - Concave - Zoom

Themes

reveal.js comes with a few themes built in:
Black (default) - White - League - Sky - Beige - Simple
Serif - Blood - Night - Moon - Solarized

Basement Level 3

That's it, time to go back up.


Up arrow

Content

  1. What is an arduino?
  2. How to use arduino?
  3. Let's build some interactive stuff!

what is an arduino?

Arduino is an open-source electronics platform based on easy-to-use hardware and software.

Arduino Products

All kinds of arduino!

learning website

hardware

what makes Arduino easy-to-use

Microcontrollers

Microcontrollers are integrated circuits that are basically tiny computers. They can run small, simple software programs.

Here is an ATMEGA328P used on Arduino.

circuit boards

They are low powered enough that they can be powered by a battery for days, but they are fast enough to process data much faster than any human being can think.

USB Powered

DC/USB flexible

open-source

The company Arduino open sources all of their hardware designs, which means that you don't just have to buy from them, there are countless 3rd party companies that make their own variants of the Arduino hardware designs.

Shields

"shields", which are basically circuit boards that plug into your main Arduino circuit board, and let you do more stuff. such as adafruit shild

software

what makes Arduino good for beginners.

Arduino IDE

Online Tools and Offline IDE

Normal chips

  1. have to type out a lot of binary
  2. memorize a lot of hard to remember registers
  3. use special programming hardware

One click to go

Just a few line of easy code, and one click, your projects are ready to go!

visual editor

Not a coder? Not a problem. There's a fully-featured visual editor for Arduino there, try it out at XOD.

Libraries

Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. Also have many examples.

Arduino UNO

But today we will use Arduino UNO, cause UNO is enough for most projects.

Arduino Kit

I recommend buying one of the many Uno kits out there where you get a lot of different pieces of hardware to play with.

How to use arduino?

PCB schemetics

IDE installation

Just say yes to everything~

Tutorial: Windows or MacOSX

Connect arduino

  1. connect the Arduino to your computer with a USB cable.
  2. start up the Arduino development environment.
  3. Go to Tools, Boards, and we are going to be using an Arduino Uno.
  4. Go to Tools, Ports, and select the COM or serial port where your Arduino is connected.

troubleshooting

If there isn't an Arduino listed here:

  • Plug your Arduino into another USB port
  • Reinstall your drivers
  • Change your arduino

GETTING STARTED

The Arduino software has a ton of fantastic, easy to follow demo programs, and studying these is the best place to start learning how to code!

Arduino calls them "sketches" which is just a fancy name for a program that you upload to your Arduino.

Blink

Hello world!

Blink


							/*
							Blink
						  
							Turns an LED on for one second, then off for one second, repeatedly.
						  
							Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
							it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
							the correct LED pin independent of which board is used.
							If you want to know what pin the on-board LED is connected to on your Arduino
							model, check the Technical Specs of your board at:
							https://www.arduino.cc/en/Main/Products
						  
							modified 8 May 2014
							by Scott Fitzgerald
							modified 2 Sep 2016
							by Arturo Guadalupi
							modified 8 Sep 2016
							by Colby Newman
						  
							This example code is in the public domain.
						  
							http://www.arduino.cc/en/Tutorial/Blink
						  */
						  
						  // the setup function runs once when you press reset or power the board
						  void setup() {
							// initialize digital pin LED_BUILTIN as an output.
							pinMode(LED_BUILTIN, OUTPUT);
						  }
						  
						  // the loop function runs over and over again forever
						  void loop() {
							digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
							delay(1000);                       // wait for a second
							digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
							delay(1000);                       // wait for a second
						  }
						

Code syntax highlighting courtesy of highlight.js.

Analog Read Serial

Basic of ADC(Analog-to-digital converter)

and Serial communication

Analog Read Serial


									/*
									AnalogReadSerial
								  
									Reads an analog input on pin 0, prints the result to the Serial Monitor.
									Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
									Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
								  
									This example code is in the public domain.
								  
									http://www.arduino.cc/en/Tutorial/AnalogReadSerial
								  */
								  
								  // the setup routine runs once when you press reset:
								  void setup() {
									// initialize serial communication at 9600 bits per second:
									Serial.begin(9600);
								  }
								  
								  // the loop routine runs over and over again forever:
								  void loop() {
									// read the input on analog pin 0:
									int sensorValue = analogRead(A0);
									// print out the value you read:
									Serial.println(sensorValue);
									delay(1);        // delay in between reads for stability
								  }
								
							

Code syntax highlighting courtesy of highlight.js.

Analog In Out Serial

Analog In Out Serial


								/*
								Analog input, analog output, serial output
							  
								Reads an analog input pin, maps the result to a range from 0 to 255 and uses
								the result to set the pulse width modulation (PWM) of an output pin.
								Also prints the results to the Serial Monitor.
							  
								The circuit:
								- potentiometer connected to analog pin 0.
								  Center pin of the potentiometer goes to the analog pin.
								  side pins of the potentiometer go to +5V and ground
								- LED connected from digital pin 9 to ground
							  
								created 29 Dec. 2008
								modified 9 Apr 2012
								by Tom Igoe
							  
								This example code is in the public domain.
							  
								http://www.arduino.cc/en/Tutorial/AnalogInOutSerial
							  */
							  
							  // These constants won't change. They're used to give names to the pins used:
							  const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
							  const int analogOutPin = 9; // Analog output pin that the LED is attached to
							  
							  int sensorValue = 0;        // value read from the pot
							  int outputValue = 0;        // value output to the PWM (analog out)
							  
							  void setup() {
								// initialize serial communications at 9600 bps:
								Serial.begin(9600);
							  }
							  
							  void loop() {
								// read the analog in value:
								sensorValue = analogRead(analogInPin);
								// map it to the range of the analog out:
								outputValue = map(sensorValue, 0, 1023, 0, 255);
								// change the analog out value:
								analogWrite(analogOutPin, outputValue);
							  
								// print the results to the Serial Monitor:
								Serial.print("sensor = ");
								Serial.print(sensorValue);
								Serial.print("\t output = ");
								Serial.println(outputValue);
							  
								// wait 2 milliseconds before the next loop for the analog-to-digital
								// converter to settle after the last reading:
								delay(2);
							  }
						

PWM: Pulse Width Modulation

knob

Control the position of a servo motor with your Arduino and a potentiometer.

This example makes use of the Arduino servo library.

Projects!

Enough talk, let's do some projects!

Peoject 1

Arduino Bluetooth LED Tutorial

Arduino Bluetooth LED Tutorial


							/* 
 *  Bluetooh Basic: LED ON OFF - Avishkar
 *  Coder - Mayoogh Girish
 *  Website - http://bit.do/Avishkar
 *  Download the App : 
 *  This program lets you to control a LED on pin 13 of arduino using a bluetooth module
 */
char Incoming_value = 0;                //Variable for storing Incoming_value
void setup() 
{
  Serial.begin(9600);         //Sets the data rate in bits per second (baud) for serial data transmission
  pinMode(13, OUTPUT);        //Sets digital pin 13 as output pin
}
void loop()
{
  if(Serial.available() > 0)  
  {
    Incoming_value = Serial.read();      //Read the incoming data and store it into variable Incoming_value
    //Serial.print(Incoming_value);        //Print Value of Incoming_value in Serial monitor
    //Serial.print("\n");        //New line 
    if(Incoming_value == '1')            //Checks whether value of Incoming_value is equal to 1 
      digitalWrite(13, HIGH);  //If value is 1 then LED turns ON
    else if(Incoming_value == '0')       //Checks whether value of Incoming_value is equal to 0
      digitalWrite(13, LOW);   //If value is 0 then LED turns OFF
  }                            
 
}                 
						

Upload Arduino-Bluetooth-Basic.ino sketch to arduino NOTE : Remove Bluetooth module Tx Rx connection before uploading the program.

Project 2

Programming 8x8 LED Matrix

Programming 8x8 LED Matrix


								/*
								This is a very easy project for starters like me, the idea of it is to show you how to send bytes to an 8x8 LED matrix.
								
								I have programmed this with all the letters of the alphabet,if you wish to add something go HERE: http://robojax.com/learn/arduino/8x8LED/
								
								In that link you will be able to make more shapes.
								
								In the left hand part of the page there will be an 8x8 matrix, with all the Leds off, by clicking them they will turn on and at the bottom of the page there will be the code that represents what you are doing to the matrix, when finished change the "sprite name " and paste the code that you just made, in the code that I made.
								
								To make this project work you will need the library:
								
								FrequencyTimer2
								Which you can download from:
								
								https://github.com/rookie/FrequencyTimer2
								*/
								
								#define ROW_1 2
								#define ROW_2 3
								#define ROW_3 4
								#define ROW_4 5
								#define ROW_5 6
								#define ROW_6 7
								#define ROW_7 8
								#define ROW_8 9
								
								#define COL_1 10
								#define COL_2 11
								#define COL_3 12
								#define COL_4 13
								#define COL_5 A0
								#define COL_6 A1
								#define COL_7 A2
								#define COL_8 A3
								
								const byte rows[] = {
									ROW_1, ROW_2, ROW_3, ROW_4, ROW_5, ROW_6, ROW_7, ROW_8
								};
								const byte col[] = {
								  COL_1,COL_2, COL_3, COL_4, COL_5, COL_6, COL_7, COL_8
								};
								
								// The display buffer
								// It's prefilled with a smiling face (1 = ON, 0 = OFF)
								byte ALL[] = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
								byte EX[] = {B11111111,B11101111,B11101111,B11101111,B11101111,B11111111,B11101111,B11111111};
								byte A[] = {B11111111,B11000011,B10011001,B10011001,B10000001,B10011001,B10011001,B10011001};
								byte B[] = {B10000111,B10110111,B10110111,B10001111,B10110111,B10111011,B10111011,B10000011};
								byte C[] = {B11111111,B11100001,B11011111,B10111111,B10111111,B10111111,B11011111,B11100001};
								byte D[] = {B11111111,B11000111,B11011011,B11011101,B11011101,B11011011,B11000111,B11111111};
								byte E[] = {B11111111,B11000011,B11011111,B11000111,B11011111,B11011111,B11000011,B11111111};
								byte F[] = {B11111111,B11000011,B11011111,B11000111,B11011111,B11011111,B11011111,B11111111};
								byte G[] = {B11111111,B11000001,B11011111,B11011111,B11010001,B11011101,B11000001,B11111111};
								byte H[] = {B11111111,B11011011,B11011011,B11000011,B11011011,B11011011,B11011011,B11111111};
								byte I[] = {B11111111,B11000111,B11101111,B11101111,B11101111,B11101111,B11000111,B11111111};
								byte J[] = {B11111111,B11100011,B11110111,B11110111,B11110111,B11010111,B11000111,B11111111};
								byte K[] = {B11111111,B11011011,B11010111,B11001111,B11010111,B11011011,B11011011,B11111111};
								byte L[] = {B11111111,B11011111,B11011111,B11011111,B11011111,B11011111,B11000011,B11111111};
								byte M[] = {B11111111,B11111111,B10111011,B01010101,B01101101,B01111101,B01111101,B11111111};
								byte N[] = {B11111111,B11011101,B11001101,B11010101,B11011001,B11011101,B11111111,B11111111};
								byte O[] = {B11111111,B11000011,B10111101,B10111101,B10111101,B10111101,B11000011,B11111111};
								byte P[] = {B11111111,B11000111,B11011011,B11011011,B11000111,B11011111,B11011111,B11111111};
								byte Q[] = {B11111111,B11000011,B10111101,B10111101,B10111101,B10111001,B11000001,B11111110};
								byte R[] = {B11111111,B11000111,B11011011,B11011011,B11000111,B11011011,B11011011,B11111111};
								byte S[] = {B11111111,B11000011,B11011111,B11000011,B11111011,B11111011,B11000011,B11111111};
								byte T[] = {B11111111,B10000011,B11101111,B11101111,B11101111,B11101111,B11101111,B11111111};
								byte U[] = {B11111111,B10111101,B10111101,B10111101,B10111101,B11011011,B11100111,B11111111};
								byte V[] = {B11111111,B11011101,B11011101,B11011101,B11101011,B11101011,B11110111,B11111111};
								byte W[] = {B11111111,B01111101,B01101101,B10101011,B10101011,B11010111,B11111111,B11111111};
								byte X[] = {B11111111,B10111101,B11011011,B11100111,B11100111,B11011011,B10111101,B11111111};
								byte Y[] = {B11111111,B10111011,B11010111,B11101111,B11101111,B11101111,B11101111,B11111111};
								byte Z[] = {B11111111,B11000011,B11111011,B11110111,B11101111,B11011111,B11000011,B11111111};
								byte Heart[] =
								{
								  B10011001,
								  B00000000,
								  B00000000,
								  B00000000,
								  B10000001,
								  B11000011,
								  B11100111,
								  B11111111
								};
								
								float timeCount = 0;
								
								void setup() 
								{
									// Open serial port
									Serial.begin(9600);
									
									// Set all used pins to OUTPUT
									// This is very important! If the pins are set to input
									// the display will be very dim.
									for (byte i = 2; i <= 13; i++)
									pinMode(i, OUTPUT);
									pinMode(A0, OUTPUT);
									pinMode(A1, OUTPUT);
									pinMode(A2, OUTPUT);
									pinMode(A3, OUTPUT);
								}
								
								void loop() {
								  // This could be rewritten to not use a delay, which would make it appear brighter
								
								//drawScreen(Heart);
								
								  // This could be rewritten to not use a delay, which would make it appear brighter
								delay(5);
								timeCount += 1;
								
								if(timeCount <  20) 
								{
								drawScreen(A);
								} 
								else if (timeCount <  40) 
								{
								drawScreen(R);
								} 
								else if (timeCount <  60) 
								{
								drawScreen(D);
								} 
								else if (timeCount <  80) 
								{
								drawScreen(U);
								} 
								else if (timeCount <  100) 
								{
								drawScreen(I);
								} 
								else if (timeCount <  120) 
								{
								drawScreen(N);
								} 
								else if (timeCount <  140) {
								  drawScreen(O);
								} 
								
								else if (timeCount <  200) 
								{
								drawScreen(Heart);
								} 
								else {
								// back to the start
								timeCount = 0;
								}
								
								
								}
								 void  drawScreen(byte buffer2[])
								 { 
								   // Turn on each row in series
									for (byte i = 0; i < 8; i++)        // count next row
									 {
										digitalWrite(rows[i], HIGH);    //initiate whole row
										for (byte a = 0; a < 8; a++)    // count next row
										{
										  // if You set (~buffer2[i] >> a) then You will have positive
										  digitalWrite(col[a], (buffer2[i] >> a) & 0x01); // initiate whole column
										  
										  delayMicroseconds(100);       // uncoment deley for diferent speed of display
										  //delayMicroseconds(1000);
										  //delay(10);
										  //delay(100);
										  
										  digitalWrite(col[a], 1);      // reset whole column
										}
										digitalWrite(rows[i], LOW);     // reset whole row
										// otherwise last row will intersect with next row
									}
								}
								// 
								  /* this is siplest resemplation how for loop is working with each row.
									digitalWrite(COL_1, (~b >> 0) & 0x01); // Get the 1st bit: 10000000
									digitalWrite(COL_2, (~b >> 1) & 0x01); // Get the 2nd bit: 01000000
									digitalWrite(COL_3, (~b >> 2) & 0x01); // Get the 3rd bit: 00100000
									digitalWrite(COL_4, (~b >> 3) & 0x01); // Get the 4th bit: 00010000
									digitalWrite(COL_5, (~b >> 4) & 0x01); // Get the 5th bit: 00001000
									digitalWrite(COL_6, (~b >> 5) & 0x01); // Get the 6th bit: 00000100
									digitalWrite(COL_7, (~b >> 6) & 0x01); // Get the 7th bit: 00000010
									digitalWrite(COL_8, (~b >> 7) & 0x01); // Get the 8th bit: 00000001
								}*/
								
						

flora

Blink Blink Blink

my space

Some videos will been uploaded here.