Documente Academic
Documente Profesional
Documente Cultură
This guide is in process. If you have any suggestions, please contact us: info@funduino.de
Content
Programming..............................................................................................................3
1. Sketch No.1: A flashing LED..................................................................................3
2. Sketch No.2: Two flashing LEDs............................................................................5
3. Sketch No.3: sound and light.................................................................................6
4. Sketch No.4: A pulsating LED................................................................................7
5. Sketch No.5: Switch a LED on by pressing a pushbutton.....................................8
6. Sketch No.6: measure light intensity......................................................................9
7. Sketch No.7: Use a potentiometer to choose the flashing-speed of a LED.........11
8. Sketch No.8: Movement detection.......................................................................12
9. Sketch No.9: Temperature measurement............................................................14
10. Sketch No.10: Measurement of distance...........................................................17
11. Sketch No.11: Usage of a infrared remote.........................................................21
12. Sketch No.12: control a servo............................................................................25
13. Sketch No.13: Show a text on a LCD display....................................................27
Programming
void setup()
{
pinMode(13, OUTPUT);
Pin 13 is a output.
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
Now the loop starts again.
void setup()
{
pinMode(7, OUTPUT);
Pin 7 is a output.
pinMode(8,OUTPUT);
Pin 8 is a output.
}
void loop()
{
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
}
Now the loop starts again.
int LED=4;
int beep=5;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(beep,OUTPUT);
}
void loop()
{
digitalWrite(LED, HIGH);
digitalWrite(beep, HIGH);
delay(1000);
digitalWrite(LED, LOW);
digitalWrite(beep, LOW);
delay(1000);
}
4. Sketch No.4: A pulsating LED
int LED=9;
int brightness= 0;
int fadesteps= 5;
void setup()
{
pinMode(LED, OUTPUT);
}
void loop()
{
analogWrite(LED, brightness);
{
fadesteps = - fadesteps ;
}
}
int LEDblue=6;
int pushbutton=7;
int buttonstate=0;
void setup()
{
pinMode(LEDblue, OUTPUT);
8
pinMode(pushbutton, INPUT);
void loop()
{
buttonstate =digitalRead(pushbutton);
if (tasterstatus == HIGH)
{
digitalWrite(LEDblue, HIGH);
delay (5000);
digitalWrite(LEDblue, LOW);
}
else
{
digitalWrite(LEDblue, LOW);
}
}
}
void loop()
{
sensorvalue =analogRead(intensity);
Serial.print("sensorvalue = " );
Serial.println(sensorvalue);
to 5 volt)
Serial.print sends informations to the serial monitor.
10
delay (sensorvalue);
That value gets used by the delay. The number is now the
delay-time in milliseconds.
delay (sensorvalue);
}
11
12
int piezo=5;
int movement=7;
int movestatus=0;
void setup()
{
pinMode(piezo, OUTPUT);
pinMode(movement, INPUT);
}
void loop()
{
movestatus =digitalRead(movement);
if (movestatus == HIGH)
digitalWrite(piezo, HIGH);
delay(5000);
digitalWrite(piezo, LOW);
13
}
else
{
digitalWrite(piezo, LOW);
}
}
int temperature = 0;
int temp[10];
void setup() {
14
Serial.begin(9600);
send the informations from the ArduinoBoard to the computer to show it there in
the serial monitor.
You can start the serial monitor in the
arduino-software with a click on settings
and serial monitor.
void loop() {
temp[1] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
delay(time);
map.
delay(time);
temp[4] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[5] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[6] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[7] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[8] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[9] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[10] = map(analogRead(TMP36), 0, 410, -50, 150);
temperature=(temp[1]+temp[2]+temp[3]+temp[4]+te
mp[5]
+temp[6]+temp[7]+temp[8]+temp[9]+temp[10])/10; // temperature.
everything in one line!!!!
Serial.print(temperatur);
Serial.println(" degree");
monitor.
15
Piezo-speaker on pin5.
void setup() {
Serial.begin(9600);
pinMode (piezo, OUTPUT);
Pin5 is a output.
}
void loop() {
temp[1] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[2] = map(analogRead(TMP36), 0, 410, -50, 150);
.
temp[9] = map(analogRead(TMP36), 0, 410, -50, 150);
delay(time);
temp[10] = map(analogRead(TMP36), 0, 410, -50, 150);
temperature=(temp[1]+temp[2]+temp[3]+temp[4]+temp[
5]
+temp[6]+temp[7]+temp[8]+temp[9]+temp[10])/10; // all
in one line
If the temperature is above 30C
Serial.print(temperatur);
Serial.println(" Grad Celsius");
if (temperatur>=30)
or...
{
digitalWrite(piezo,HIGH);
...it is quiet.
}
16
else
{
digitalWrite(piezo,LOW);
}
}
17
int trigger=7;
trigger on pin7.
int echo=6;
echo on pin 6.
long time=0;
long dist=0;
The value dist will save the calculated distance. It will start
with 0. Instead of int we use long for this value, to save
a bigger number
void setup()
{
Serial.begin (9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
}
void loop()
{
digitalWrite(trigger, LOW);
delay(5);
...for 5 milliseconds.
digitalWrite(trigger, HIGH);
delay(10);
...for 10 milliseconds.
digitalWrite(trigger, LOW);
With the command pulseIn " (with a big i next to the last
n) the Arduino-board counts the time between sending and
receiving the soundwave.
Serial.println("No
No measurement
measurement");
}
else
otherwise...
{
Serial.print(dist);
Serial.println(" cm");
}
delay(1000);
measurements.
19
int trigger=12;
int echo=13;
long dauer=0;
long entfernung=0;
int piezo=5;
Piezo-speaker on pin5
void setup()
{
Serial.begin (9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
pinMode(piezo, OUTPUT);
}
void loop()
{
digitalWrite(trigger, LOW);
delay(5);
digitalWrite(trigger, HIGH);
delay(10);
digitalWrite(trigger, LOW);
dauer = pulseIn(echo, HIGH);
entfernung = (dauer/2) / 29.1;
if (entfernung >= 500 ||
entfernung <= 0)
{
Serial.println("Kein Messwert");
}
else
{
20
Serial.print(entfernung);
Serial.println(" cm");
}
if (entfernung <= 80)
{
digitalWrite(piezo,HIGH);
}
else
Otherwise...
{
digitalWrite(piezo,LOW);
it is quiet.
}
delay(1000);
}
21
22
The sketch is a variation of the sketch IRrecvDemo, an can be downloaded on the following link.
https://github.com/shirriff/Arduino-IRremote
You can download the zip-package and copy the files into your libraries directory in the arduinosoftware. Rename the downloaded directory to "Irremote".
Now you can open the sketch in the sample-files in the arduino-software:
File -> Examples -> IRremote -> IRrecvDemo
Now we edit the Sketch to this Sketch:
/*
* IRremote: IRrecvDemo - demonstrates
receiving IR codes with IRrecv
* An IR detector/demodulator must be
connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
connected to pin 11
decode_results results;
void setup()
{
Serial.begin(9600);
pinMode (13, OUTPUT);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
irrecv.resume();
23
}
}
Pressing the "1" key on the infrared remote control causes (in my case) the serial-monitor writes the
number "16724175". This is the decrypted number code behind this button.
When you hold the button permanently pressed, the number "4294967295" appears. This is the code
that indicates that a key is pressed continuously. This number does not depend on which key is
pressed.
There can also appear other numbers if a key is pressed only very short or pulsating. In the case the
sensor may not read unique value.
Extension of the sketch:
Switch on a LED by pressing button1 and switch it off with button2.
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
pinMode (13, OUTPUT);
digitalWrite(13, LOW);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
if (results.value == 16724175)
if (results.value == 16718055)
}
}
#include <Servo.h>
Servo servoblue;
void setup()
{
servoblue.attach(8);
}
25
void loop()
{
servoblue.write(0);
delay(3000);
servoblue.write(90);
delay(3000);
servoblue.write(180);
delay(3000);
servoblue.write(20);
delay(3000);
}
26
#include <LiquidCrystal.h>
void setup() {
lcd.begin(16, 2);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("www.funduino.de");
lcd.setCursor(0, 1);
lcd.print("good luck!!!");
}
28