Arduino UNO 加 感測器
程式下載 https://www.arduino.cc/en/Main/Software
UNO 板子介紹 http://coopermaa2nd.blogspot.tw/2011/05/arduino.html
https://www.arduino.cc/en/Main/ArduinoBoardUno
感測器擴充版 V4.0 https://arduino-info.wikispaces.com/SensorShield
感測器擴充版 V5.0 http://elesson.tc.edu.tw/md221/course/view.php?id=253
上課新網址 https://sites.google.com/site/mydearobotics/
37合一 感測模組 https://tkkrlab.nl/wiki/Arduino_37_sensors
光控制 LED
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(9, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
if (sensorValue > 265){digitalWrite(9, HIGH);
} else {
digitalWrite(9, LOW);
}
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
延伸創作:
1. 光遮住亮紅燈,放開亮 綠燈。
2. 光遮住的時候,讓 藍色燈慢慢亮,慢慢熄滅。
蜂鳴器:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://www.arduino.cc
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(10, LOW);
tone(8, 2000, 500);
delay(500); // wait for a second
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
digitalWrite(10, HIGH);
tone(8, 1000, 500);
delay(500); // wait for a second
}
小蜜蜂
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_G5, NOTE_E5, NOTE_E5, 0, NOTE_F5, NOTE_D5, NOTE_D5, 0, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_G5, NOTE_G5
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
2, 2, 2, 2, 2, 2, 2, 2,2, 2, 2, 2, 2, 2, 2, 2
};
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 15; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void loop() {
// no need to repeat the melody.
}
溫濕度計模組:程式
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。