0% found this document useful (0 votes)
7 views3 pages

Arduino Cheat Sheet Full 20 Muc

This document is an Arduino cheat sheet that summarizes basic programming structures, control commands, data types, and sensor integration. It includes examples for setting up pins, reading sensors, controlling motors, and using libraries for communication protocols like I2C and SPI. Additionally, it covers topics such as debouncing buttons, using interrupts, and defining custom functions.

Uploaded by

mailan0399
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Arduino Cheat Sheet Full 20 Muc

This document is an Arduino cheat sheet that summarizes basic programming structures, control commands, data types, and sensor integration. It includes examples for setting up pins, reading sensors, controlling motors, and using libraries for communication protocols like I2C and SPI. Additionally, it covers topics such as debouncing buttons, using interrupts, and defining custom functions.

Uploaded by

mailan0399
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Arduino Cheat Sheet - Tong hop lenh co ban

1. Cau truc chuong trinh


void setup() {
// chay 1 lan khi khoi dong
}

void loop() {
// chay lap lai lien tuc
}

2. Lenh dieu khien co ban


pinMode(pin, INPUT/OUTPUT);
digitalWrite(pin, HIGH/LOW);
digitalRead(pin);
analogRead(pin);
analogWrite(pin, value);

3. Bien & kieu du lieu


int led = 13;
float nhiet_do = 25.6;
bool den = true;
char ky_tu = 'A';

4. Cau lenh dieu kien - vong lap


if (digitalRead(2) == HIGH) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}

for (int i = 0; i < 10; i++) {}


while (true) {}

5. Serial - Giao tiep voi may tinh


Serial.begin(9600);
Serial.print("Gia tri: ");
Serial.println(sensorValue);

6. Thu vien va cam bien pho bien


#include <Servo.h>
Servo myservo;
myservo.attach(9);
myservo.write(90);
7. Doc cam bien nhiet do LM35
int val = analogRead(A0);
float c = (val * 5.0 * 100.0) / 1024;
Serial.println(c);

8. Dieu khien Dong co DC (PWM)


analogWrite(9, 128);
digitalWrite(9, HIGH);
digitalWrite(9, LOW);

9. Cam bien sieu am HC-SR04


digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0344 / 2;

10. Man hinh LCD 16x2 (I2C)


#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
lcd.begin();
lcd.print("Hello");
lcd.setCursor(0, 1);
lcd.print("Arduino");

11. Dieu khien Servo


#include <Servo.h>
Servo myservo;
myservo.attach(9);
myservo.write(0);
myservo.write(90);
myservo.write(180);

12. Cam bien anh sang LDR


int val = analogRead(A0);
Serial.println(val);

13. Tao nhac voi Buzzer


tone(3, 1000);
delay(1000);
noTone(3);

14. Giao tiep I2C


#include <Wire.h>
Wire.begin();
Wire.beginTransmission(8);
Wire.write("Xin chao!");
Wire.endTransmission();

15. Giao tiep SPI


#include <SPI.h>
SPI.begin();
digitalWrite(SS, LOW);
SPI.transfer(0x53);
digitalWrite(SS, HIGH);

16. EEPROM
#include <EEPROM.h>
EEPROM.write(0, 123);
int val = EEPROM.read(0);

17. millis() thay delay()


if (millis() - t_truoc >= 1000) {
t_truoc = millis();
Serial.println("1s qua");
}

18. Ngat ngoai


attachInterrupt(digitalPinToInterrupt(2), xuLyNgat, RISING);
void xuLyNgat() {
// Xu ly ngat
}

19. Ham tu dinh nghia


int tinhTong(int a, int b) {
return a + b;
}

20. Nut nhan co chong doi


if (digitalRead(nut) != trangThaiCu) {
thoiGian = millis();
}
if (millis() - thoiGian > debounce) {
if (digitalRead(nut) == HIGH) Serial.println("Nhan nut");
}
trangThaiCu = digitalRead(nut);

You might also like