Upload
-
View
185
Download
0
Embed Size (px)
Citation preview
PowerPoint
Arduino ()
- 1 -
- 2 -
https://www.arduino.cc
: www.arduino.ccArduino IDE ( USB ) JUST DOWNLOAD PC USB - 3 -
12345
IDE : : (baking firmware)New : Open : Save :
: Arduino/Genuino Uno : > > 01.Basics > Blnks
- 4 -
void setup() {
}
void loop() {
}
C/C++ Setup 1 Loop - 5 -
API Reference
Learning > Reference
Learning > Tutorials , ,
- 6 -
- 7 -
Tact
LED
- Arduino UNO R3 - Breadboard Mini - LED - Register 0.1k, 1k - Push Button
int led = 13;int button = 10;int prevButtonState = LOW;int ledState = LOW;void setup() { pinMode(led, OUTPUT); pinMode(button, INPUT);}void loop() { int currentButtonState = digitalRead(button); if(prevButtonState == LOW && currentButtonState == HIGH) { ledState = HIGH - ledState; } prevButtonState = currentButtonState; digitalWrite(led, ledState); delay(50);}- 8 -
Potentionmeter()
void setup(){ Serial.begin(9600);}
void loop(){ int a0 = analogRead(A0); Serial.println(a0); delay(300);}- 9 -
PWM (Pulse Width Modulation)
RGB LED
int ledRED = 9;int ledGREEN = 10;int ledBLUE = 11;
int nowR = random(0, 255);int nowG = random(0, 255);int nowB = random(0, 255);
int toR = random(0, 255);int toG = random(0, 255);int toB = random(0, 255);
void setup() { pinMode(ledRED, OUTPUT); pinMode(ledGREEN, OUTPUT); pinMode(ledBLUE, OUTPUT);}
void loop() { setColor(nowR, nowG, nowB);
if(nowR == toR) toR = random(0, 255); if(nowG == toG) toG = random(0, 255); if(nowB == toB) toB = random(0, 255);
if(nowR < toR) nowR++; else nowR--; if(nowG < toG) nowG++; else nowG--; if(nowB < toB) nowB++; else nowB--; delay(10);}
void setColor(int red, int green, int blue){ analogWrite(ledRED, red); analogWrite(ledGREEN, green); analogWrite(ledBLUE, blue); }- 10 -
void setup() {
}
void loop() {
for(int i=500; i500; i-=10) { note(i, 50); }}
void note(int pitch, int duration) { tone(8, pitch, duration); delay(duration*0.8);}- 11 -
/**************** pitches.h***************/
#define NOTE_C5 523#define NOTE_D5 587#define NOTE_E5 659#define NOTE_G5 784#define NOTE_A5 880https://www.arduino.cc/en/Tutorial/toneMelody
#include "pitches.h"
void setup() {}
void loop() { note(NOTE_G5, 500); note(NOTE_G5, 500); note(NOTE_A5, 500); note(NOTE_A5, 500); note(NOTE_G5, 500); note(NOTE_G5, 500); note(NOTE_E5, 1000); note(NOTE_G5, 500); note(NOTE_G5, 500); note(NOTE_E5, 500); note(NOTE_E5, 500); note(NOTE_D5, 1000); note(NOTE_G5, 500); note(NOTE_G5, 500); note(NOTE_A5, 500); note(NOTE_A5, 500); note(NOTE_G5, 500); note(NOTE_G5, 500); note(NOTE_E5, 1000); note(NOTE_G5, 500); note(NOTE_E5, 500); note(NOTE_D5, 500); note(NOTE_E5, 500); note(NOTE_C5, 2000); delay(4000);}
void note(int pitch, int duration) { tone(8, pitch, duration); delay(duration * 1.3); noTone(8);}- 12 -
LDR
const int LED = 9;const int LDR = A0;
void setup() { pinMode(LED, OUTPUT);}
void loop() { int a0 = analogRead(LDR); int light = max(map(a0, 0, 600, 1023, 0), 0); analogWrite(LED, light); delay(300);}- 13 -
KY-038
int sensorPin = A0;int ledPin = 13;int sensorValue = 0; void setup () { pinMode (ledPin, OUTPUT); Serial.begin (9600);} void loop () { sensorValue = analogRead (sensorPin); digitalWrite (ledPin, HIGH); delay (sensorValue); digitalWrite (ledPin, LOW); delay (sensorValue); Serial.println (sensorValue, DEC);}- 14 -
= 340 m/s=> 1 340 m => 1 340000 mm => 1 340 mm => 1 0.34 mm (1 1/1000000 )
* 0.34 = (mm) .=> ( microsecond * 0.34 ) / 2=> ( millisecond * 340 ) / 2
HC-SR04
int trig= 7;int echo= 6;int led= 13;
void setup() { // initialize serial communication: Serial.begin(9600); pinMode(trig, OUTPUT); pinMode(echo, INPUT); pinMode(led, OUTPUT);}
void loop(){ digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW);
long val= pulseIn(echo, HIGH) * 17 / 100; Serial.println(val);
if(val < 50) { //5cm LED digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); }
delay(100);}
- 15 -
DHT11https://github.com/winlinvip/SimpleDHT
#include
int pinDHT11 = 2;SimpleDHT11 dht11;
void setup() { Serial.begin(9600);}
void loop() { byte temperature = 0; byte humidity = 0; if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) { Serial.print("No Data"); delay(1000); return; } Serial.print("Temp: "); Serial.print((int)temperature); Serial.print(" *C, "); Serial.print((int)humidity); Serial.println(" %"); delay(1000);}- 16 -
LCD
LCD1602https://github.com/marcoschwartz/LiquidCrystal_I2CSDASCL
#include
LiquidCrystal_I2C lcd(0x27,16,2); //LCD address : 0x27
void setup(){ lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Hello, world!");}
void loop(){}- 17 -
- 18 -
Temp 29 *c Hum 61 % 28 28
28 28 - 19 -
5V220VRelay(KY-019)?https://github.com/iamchiwon/iot_with_arduino/tree/master/Auto_Fan
- - - LCD () -
2. 220V 5V (digitalWrite HIGH 5V )
3. 5V 220V ?- 20 -
- 22 -
Servo Motor
?https://github.com/iamchiwon/iot_with_arduino/tree/master/Auto_TrashCan
- - - LCD () -
2. ?- 23 -