Sie sind auf Seite 1von 14

Arduino

Begin(1)
Why ?
1. You Can Make Lots of Cool Stuff ex: Automation

2. It’s a Great Intro to Programming

3. It’s a Great Intro to Electronics, Too

4. It’s a Cheap Hobby to Get Into

http://www.makeuseof.com/tag/4-reasons-everyone-learn-arduino-now/
What ?
Arduino is an open source computer
hardware and software company,
project, and user community that
designs and manufactures single-
board microcontrollers and
microcontroller kits for building
digital devices and interactive
objects that can sense and control
objects in the physical world.
HOW ?
Input Input
/Output /Output
start 1. Install arduino
software on
computer
2. Plug Arduino into
usb port
https://www.arduino.cc/en/Main/Software
Choose board
After you installed the
Arduino software, run it.

From the menu, choose


Tools  Board:
“Arduino/Genuino Uno” 
Arduino/Genuino Uno
The Software
“Upload” code to arduino

Place Your Code Here


Examples !
First Program - Hello Led !
// 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(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage
LOW
delay(1000); // wait for a second
}
2nd Program - Slower LED (variables)
int _delay = 1000;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN 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(_delay); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(_delay); // wait for a second
_delay = _delay + 100;
}
3rd Program - Faster LED (conditional)
int _delay = 1000;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN 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(_delay); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(_delay); // wait for a second
_delay = _delay - 100;

//if we not use this there will be a problem, what is it ?


if(_delay<0)
{
_delay= 1000;
}
}
4th Program - Many leds (for loops)
int timer = 100; // The higher the number, the slower the timing.
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 8; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}

// loop from the highest pin to the lowest:


for (int thisPin = 7; thisPin >= 2; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
4th Program - Many leds (for loops)
Challenge:
1. Make the LEDs turn-On in a sequential manner
from LEDs 1 to 6 and then turn-Off from 6 to 1.
2. Do step 1 above in an increasing and then
decreasing manner

Make a report that consists of:


1. Description of the challenge, what your
program does.
2. The program script
3. The schematic, you can copy, modify and paste
the picture on this slide

Das könnte Ihnen auch gefallen