Arduino - CC: Download It NOW
Arduino - CC: Download It NOW
Arduino - CC: Download It NOW
CC
FRITZING.ORG
DOWNLOAD IT
NOW
arduino - what?
OPEN SOURCE
HARDWARE HACKING
PLATFORM FOR
DESIGNERS, ARTISTS
AND HOBBYISTS
arduino - still what?
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);
}
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
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);
analogWrite(LEDPin, sensorValue);
}
Strom, Spannung, Widerstand
GND
µC-in
5V
µC-in
Spannungsteiler
sensor reading
Im der Reihenschaltung gilt:
Die gesammte angelegte Spannung fällt an den Teilwiederständen ab.
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
void setup() {
Serial.begin(9600); //Initialisiert die Seriele Kommunikation
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin1);
sensorValue = analogRead(sensorPin2);
sensorValue = analogRead(sensorPin3);
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>
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 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);
}
void setup() {
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
pinMode(potiPin, INPUT);
Basis (B)
Emitter (E)
Kollector (C)
Basis (B)
Emitter (E)
Kollector (C)
NPN PNP
N
P
N
Basis (B)
Emitter (E)
Kollector (C)
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
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
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 (G)
Source (S)
Drain (D)
Gate (G)
Source (S)
Drain (D)
R1 = 10K
R2 = 1K