Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This tutorials are in process. If you have any suggestions, please contact us:
info@funduino.de
We know, that our english sounds very german until now ;) We will work on a better translation.
But we hope, that the tutorials are useful anyway.
Content
Programming............................................................................................................3
1. Sketch No.1: A flashing LED (blink)......................................................................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..........................................................18
11. Sketch No.11: Usage of an infrared remote......................................................22
12. Sketch No.12: Control a servo..........................................................................26
13. Sketch No.13: Show a text on a LCD display...................................................27
14. Sketch No.14: Use a relais shield.....................................................................29
Programming
void setup()
{
pinMode(13, OUTPUT);
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
Now the loop starts again.
digitalWrite(13, LOW);
delay(200);
void setup()
{
pinMode(7, OUTPUT);
Pin 7 is an output.
pinMode(8,OUTPUT);
Pin 8 is an 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);
}
Copyright 2014 Funduino UG (Haftungsbeschrnkt)
int LED=9;
int brightness= 0;
int fadesteps= 5;
void setup()
{
pinMode(LED, OUTPUT);
}
void loop()
{
analogWrite(LED, brightness);
delay(25);
webside or wikipedia.com
if (brightness == 0 || brightness ==
255)
{
Copyright 2014 Funduino UG (Haftungsbeschrnkt)
fadesteps = - fadesteps ;
}
}
int LEDblue=6;
int pushbutton=7;
int buttonstate=0;
void setup()
{
pinMode(LEDblue, OUTPUT);
pinMode(pushbutton, INPUT);
void loop()
{
buttonstate =digitalRead(pushbutton);
if (buttonstate == HIGH)
{
digitalWrite(LEDblue, HIGH);
delay (5000);
digitalWrite(LEDblue, LOW);
}
else
otherwise...
{
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.
{
digitalWrite(LED, HIGH);
}
else
...otherwise...
{
digitalWrite(LED, LOW);
}
delay (50);
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;
Piezo-speaker on pin5
int movement=7;
Movementsensor on pin7
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);
Copyright 2014 Funduino UG (Haftungsbeschrnkt)
13
}
else
.otherwise...
{
digitalWrite(piezo, LOW);
}
}
The sensor has three terminals. 5V, GND, and the pin for the temperature signal. On this pin, the
sensor puts out a voltage between 0 and 2.0 volts.
0V = -50 C and 2.0V = 150 C.
The voltage on this pin must be read by the microcontroller board and then it hast to be converted
into a temperature value.
- CAUTION: If the sensor is connected incorrectly it gets destroyed.
- Use a external power supply for more sensor accuracy (as possible 9V battery).
14
int temperature = 0;
int temp[10];
void setup() {
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);
15
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
temperature
Serial.print(temperatur);
Serial.println(" degree");
monitor
Piezo-speaker on pin5.
void setup() {
16
Serial.begin(9600);
pinMode (piezo, OUTPUT);
Pin5 is an 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
Serial.print(temperatur);
Serial.println(" Grad Celsius");
if (temperatur>=30)
{
digitalWrite(piezo,HIGH);
}
else
or...
{
digitalWrite(piezo,LOW);
...it is quiet
}
}
17
c) echo d) trigger
The connections 5V and GND are for the power supply. The Pin "trigger" gets a short signal (5V), and
creates a sound wave. As soon as the sound wave hits a wall or other objects, it will be reflected and
comes back to the ultrasonic sensor. When the sensor detects this returned sound wave, the sensor
sends a signal to the Arduino microcontroller by the "echo" pin. The Arduino-board measures the
time between the transmission and the return of the sound wave, and converts this time into a
distance.
Required equipment: microcontroller board / cable / breadboard / HC-SR04 ultrasonic sensor
18
int trigger=7;
trigger on pin7.
int echo=6;
echo on pin 6.
long time=0;
The value time will save the time between transmition and
returning of the soundwave.
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.
19
Serial.println("No
No measurement
measurement");
}
else
otherwise...
{
Serial.print(dist);
Serial.println(" cm");
}
delay(1000);
measurements.
20
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
{
21
Serial.print(entfernung);
Serial.println(" cm");
}
if (entfernung <= 80)
{
digitalWrite(piezo,HIGH);
}
else
otherwise...
{
digitalWrite(piezo,LOW);
it is quiet.
}
delay(1000);
}
22
23
The sketch is a variation of the sketch IRrecvDemo, and can be downloaded on the following link:
https://github.com/shirriff/Arduino-IRremote
You can download the zip-package and copy the folder into your libraries directory in the arduinosoftware. Rename the folder 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();
24
}
}
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 press the button permanently, 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)
25
#include <Servo.h>
Servo servoblue;
void setup()
{
servoblue.attach(8);
}
26
void loop()
{
servoblue.write(0);
delay(3000);
servoblue.write(90);
delay(3000);
servoblue.write(180);
delay(3000);
servoblue.write(20);
delay(3000);
}
27
#include <LiquidCrystal.h>
void setup() {
lcd.begin(16, 2);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("www.funduino.de");
lcd.setCursor(0, 1);
28
lcd.print("good luck!!!");
}
A relays is a switch, that can be activated with a low current from the
Arduino-board. So you can switch on and off electrical things, that need
much more power than a Arduino-board can provide.
The relays need a permanent power supply with 5V+ and (Top of the
picture). On the Signal-pin, the switch can be activated by the Arduinoboard. Dependent of the manufacturer, there has to be a LOW or HIGH
signal from the arduino output-pin.
On the terminal A, B and C you can connect the cables from the electrical
thing, you want to switch on and off.
The relays connects the terminals A and B while the relays is switched off and when it is activated, it
connects the terminals A and C.
For testing purpose, you can use the blink-sketch. Instead of the LED, you connect the output-pin
from the Arduino-board with the signal-pin from the relay. With that sketch, the relays will switch on
and off in a 1 second rhythm.
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
This tutorial is under construc7on. There will be more tutorials soon www.funduino.de.
29