Sunteți pe pagina 1din 44

ARDUINO.

CC
FRITZING.ORG

DOWNLOAD IT
NOW
arduino - what?

OPEN SOURCE
HARDWARE HACKING
PLATFORM FOR
DESIGNERS, ARTISTS
AND HOBBYISTS
arduino - still what?

A CHEAP AND EASY


WAY TO LEARN AND
EXPERIMENT WITH
ELECTRONICS
arduino - that!
so what
can I do
with it?
Laser Harp

stephenhobley.com/build/
tedullrich.com/laboratory.php
vrurban.org/smslingshot
daniel beispiel
Looks quite
complicated.
How can I
learn it ?
arduino.cc
arduinofun.com
arduinoprojects.com
fritzing.org
freeduino.org
youtube.com
makezine.com
hacknmod.com
tinker.it/now
strg

strg
OK, LETS GO
blink
int ledPin = 13; // LED connected to digital pin 13

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
blink I/0 int buttonPin = 2; // the number of the pushbutton pin
int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
blink / control
int sensorPin = 0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the
sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
// start reading serial input at 9600:
Serial.begin(9600);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
// show serial input value in the gui:
Serial.println(sensorValue);
Serial.println();
}
PWM / control int fadeValue;
int Poti = 1;
// fading wert
// analoger steckplatz 1
int potiwert; // poti wert
int LED = 9; // digitaler steckplatz 9

void setup() {

pinMode(LED, OUTPUT);
pinMode(Poti, INPUT);

void loop() {
potiwert = analogRead(Poti) /100;
// fade in from min to max in increments of the poti value/100:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue += potiwert) {
// sets the value (range from 0 to 255):
analogWrite(LED, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(0);
}

// fade out from max to min in increments of of the poti value/100:


for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -= potiwert) {
// sets the value (range from 0 to 255):
analogWrite(LED, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(0);
}
}
“hello world“
void setup() {
//Initialisiert die Seriele Kommunikation
Serial.begin(9600);
}

void loop(){
// schreibt „hello world“ in den serielen Port
Serial.print(„hello world“);
}
SerialDebugging
#define sensorPin 0 // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
Serial.begin(9600); //configure the serial port for 9600bps
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);

„ „
// schriebt den String Wert: in den Serielen Port
„ „
Serial.print( Wert: );

// schriebt den SensorWert in den Serielen Port und macht einen Umbruch
Serial.println(sensorValue);
}
value mapping
#define sensorPin 0 // select the input pin for the potentiometer
#define LEDPin 9 // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
map (variable, value_von, value_bis, map_von, map_bis)

void setup() {
Serial.begin(9600); //Initialisiert die Seriele Kommunikation

pinMode(LEDPin, OUTPUT); //put LEDpin to an Output


}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);

// schriebt den SensorWert in den Serielen Port und macht einen Umbruch
Serial.print(„Sensor: „);
// schriebt den SensorWert in den Serielen Port und macht einen Umbruch
Serial.println(sensorValue);

//map den sensorWert auf einen bestimmten Wertebereich


sensorValue = map(sensorValue, 26, 360, 0, 255);
Serial.print(„gemapped: „);
Serial.println(sensorValue);

analogWrite(LEDPin, sensorValue);
}
Strom, Spannung, Widerstand

Wasserdruck = Spannung = Volt = V V = R * I

Wasserfluss = Strom = Ampere = I I = V / R

Wasserhahn = Widerstand = Ohm = R R = V / I


Strom, Spannung, Widerstand

Wasserdruck = Spannung = Volt = V V = R * I

Wasserfluss = Strom = Ampere = I I = V / R

Wasserhahn = Widerstand = Ohm = R R = V / I


Sensor Reading
Was können wir am Arduino Analog Input Pin bei gezeigten Schaltun- 5V
gen messen?
µC-in

GND
µC-in

5V
µC-in
Spannungsteiler
sensor reading
Im der Reihenschaltung gilt:
Die gesammte angelegte Spannung fällt an den Teilwiederständen ab.

Die Summe aller Teilspannungen ist gleich der GesamtSpannung.

Uges = U1 + U2
Tauschen wir einen der Wiederstand (R1 oder R2) in einen verän-
derbaren Wiederstand um, können wir über den Spannungsteiler die
veränderte Spannung im Knotenpunkt messen.
U1

Uges=U1+U2 µC-in

U2
RGB mapping
task
- SensorPins für Analalog_IN 0, 1, 2 definieren

- PWM Pins_OUT 9, 10, 11 deklarieren (gute Namen finden)

- 3 Sensor Variablen deklarieren

- alle 3 Sensoren einlesen, mappen und auf die 3 LED‘s ausgeben


RGB mapping #define sensorPin1 0
#define sensorPin2 1
#define sensorPin3 2
#define LEDrot 9
// select the input pin for the potentiometer
// select the input pin for the potentiometer
// select the input pin for the potentiometer
// select the input pin for the potentiometer

solution #define LEDgruen 10


#define LEDblau 11
int sensorValue1 = 0; // variable to store the value coming from the
sensor
int sensorValue2 = 0; // variable to store the value coming from the
sensor
int sensorValue3 = 0; // variable to store the value coming from the
sensor

void setup() {
Serial.begin(9600); //Initialisiert die Seriele Kommunikation

pinMode(LEDrot, OUTPUT); //put LEDpin to an Output


pinMode(LEDgruen, OUTPUT); //put LEDpin to an Output
pinMode(LEDblau, OUTPUT); //put LEDpin to an Output
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin1);
sensorValue = analogRead(sensorPin2);
sensorValue = analogRead(sensorPin3);

//map den sensorWert auf einen bestimmten Wertebereich


sensorValue1 = map(sensorValue, 26, 360, 255, 0);
sensorValue2 = map(sensorValue, 26, 360, 255, 0);
sensorValue3 = map(sensorValue, 26, 360, 255, 0);

if(sensorValue1>255){
sensorValue1 = 255;
}
if(sensorValue1<0){
sensorValue1 = 0;
}
if(sensorValue2>255){
sensorValue2 = 255;
}
if(sensorValue2<0){
sensorValue2 = 0;
}
if(sensorValue3>255){
sensorValue3 = 255;
}
....
SERVO MOTORS
kinetic outputs
#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer


int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo ob-
ject
Serial.begin(9600); //configure the serial port for 9600bps

void loop()
{
val = analogRead(potpin); // reads the value of the po-
tentiometer (value between 0 and 1023)
val = map(val, 0, 0, 0, 0); // scale it to use it with the ser-
vo (value between 0 and 180)
myservo.write(val); // sets the servo position ac-
cording to the scaled value
delay(15); // waits for the servo to get
there
Serial.println(val);
}
MELODIES int speakerPin = 9;
sonic outputs with piezos int length = 15; // the number of notes
char notes[] = „ccggaagffeeddc „; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) {


for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}

void playNote(char note, int duration) {


char names[] = { ‚c‘, ‚d‘, ‚e‘, ‚f‘, ‚g‘, ‚a‘, ‚b‘, ‚C‘ };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name


for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}

void setup() {
pinMode(speakerPin, OUTPUT);
}

void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ‚ ‚) {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo);
}

// pause between notes


delay(tempo / 2);
}
}
MELODIES + void playNote(char note, int duration) {
char names[] = {
sonic outputs with piezos ‚c‘, ‚d‘, ‚e‘, ‚f‘, ‚g‘, ‚a‘, ‚b‘, ‚C‘
int tones[] = {
};

1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name


for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}

void setup() {
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
pinMode(potiPin, INPUT);

int speakerPin = 9; void loop() {


int potiPin = 1; for (int i = 0; i < length; i++) {
int potiwert = 0; if (notes[i] == ‚ ‚) {
int potiwert2 = 0; delay(beats[i] * tempo); // rest
}
int length = 15; // the number of notes else {
char notes[] = „ccggaagffeeddc „; // a space represents a playNote(notes[i], beats[i] * tempo);
rest }
int beats[] = {
1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; // pause between notes
int tempo = 500; delay(tempo / 2);
}
void playTone(int tone, int duration) { {
for (long i = 0; i < duration * 1000L; i += tone * 2) { potiwert = analogRead(potiPin);
digitalWrite(speakerPin, HIGH); potiwert2 = map(potiwert, 0, 1023, 0, 500
delayMicroseconds(tone); );
digitalWrite(speakerPin, LOW); Serial.println(potiwert);
delayMicroseconds(tone); tempo = potiwert2;
}
}
}
}
große Ströme
schalten
mechanische
Schalter
Symbol

- mechanische Trennung der Ladungen


- manuelles schalten von hohen Strömen möglich
(z.B. Lichtschalter)
- nicht dimmbar
elektrische
Schalter
Transistor MosFET

- Ladungstrennung durch Materialschichtung


- verstärkt den Strom der an der Basis/Gate anliegt
- ist ein Signalverstärker und dadurch dimmbar

SOT-23 SOT-223 TO-92 TO-220


Transistor
Bipolartransistoren

Basis (B)

Emitter (E)

Kollector (C)

Basis: verstärkt den Strom zwischen Emitter und


Kollektor - Steuerstrom
Transistor
Bipolartransistoren

Basis (B)

Emitter (E)

Kollector (C)

Basis: verstärkt den Strom zwischen Emitter und


Kollektor - Steuerstrom
NPN / PNP
Bipolartransistoren

NPN PNP
N
P
N

Basis (B)
Emitter (E)
Kollector (C)

- verschiedene positiv oder negativ geladenen Schichten.

- je nach Dotierungsfolge im Aufbau unterscheidet man zwischen


npn- (negativ-positiv-negativ) und pnp-Transistoren (positiv-
negativ-positiv).
Transistor NPN
Schalten

TIP122

µC-out

R1 = 1K
R2 = 1K
Transistor NPN
Schalten
int ledPin = 9; // LED connected to digital pin 9

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
PWM / control
Transistor NPN #define sensorPin 0 // select the input pin for the potentiometer
#define LEDPin 9 // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the
sensor

void setup() {
Serial.begin(9600); //Initialisiert die Seriele Kommunikation

pinMode(LEDPin, OUTPUT); //put LEDpin to an Output


}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);

//map den sensorWert auf einen bestimmten Wertebereich


sensorValue = map(sensorValue, 26, 360, 0, 255);

analogWrite(LEDPin, sensorValue);
}
2 Stromkreise
Transistor NPN
4,5V extern

5V Arduino
4,5V

µC-out

R2 = 1K
R3 = 1K
2 Stromkreise
Transistor NPN

24V

LED Streifen
Mosfet
Metall-Oxid-Halbleiter-Feldeffekttransistor

Gate (G)

Source (S)

Drain (D)

Gate: eine anliegende Spannung verstärkt den Strom zwischen


Source und Drain
Mosfet
Metall-Oxid-Halbleiter-Feldeffekttransistor

Gate (G)

Source (S)

Drain (D)

Gate: eine anliegende Spannung verstärkt den Strom zwischen


Source und Drain
Mosfet
Metall-Oxid-Halbleiter-Feldeffekttransistor

Gate (G)
Source (S)
Drain (D)

- verschiedene positiv oder negativ geladenen Schichten.

- je nach Dotierungsfolge im Aufbau unterscheidet man zwischen


n-Chanel- (negativ-positiv-negativ) und p-Chanel-Mosfets
(positiv-negativ-positiv).
RGB strip
Plus Pol Schalten

R1 = 10K
R2 = 1K

S-ar putea să vă placă și