28/04/2568

Arduino C++ (ไฟวิ่ง) ครูเต้ง เทคโนฯ


📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้คำสั่งเขียน 

int led1 = 2; // กำหนดขาใช้งาน 

int led2 = 3; 

int led3 = 4; 

int led4 = 5; 

void setup() 

pinMode(led1, OUTPUT); // กำหนดขาทำหน้าที่ OUTPUT 

pinMode(led2, OUTPUT); 

pinMode(led3, OUTPUT); 

pinMode(led4, OUTPUT); 

void loop() 

digitalWrite(led1,HIGH); // ไฟ LED 1 ติด 500 ms 

delay(500); 

digitalWrite(led1,LOW); // ไฟ LED 1 ดับ500 ms 

delay(500); 

digitalWrite(led2,HIGH); 

delay(500); 

digitalWrite(led2,LOW); 

delay(500); 

digitalWrite(led3,HIGH); 

delay(500); 

digitalWrite(led3,LOW); 

delay(500); 

digitalWrite(led4,HIGH); 

delay(500); 

digitalWrite(led4,LOW); 

delay(500); 

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้วงจร






12/04/2568

Theme 6 วงจรพัฒนาประยุกต์การทำงานของระบบ Capteur Gaz

 

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้   คำสั่งเขียน 

#include<LiquidCrystal.h>
LiquidCrystal lcd(13, 7, 6, 5, 4, 3);
int capteurGaz = A0;
int capteurTemp = A1;
int buzzer = 2;
int photoresistance = A2;
int del = 8;
int del_manuel = 9;
int btn_gaz_pin = 10;
int btn_lumi_pin = 11;
int manuel_pin = 12;
int molette = A3;
int manuel;
int btn_gaz;
int btn_lumi;
int btn_manuel;
void setup() {
  pinMode(13, OUTPUT);
  for (int i = 3; i < 7; i++){ // l'écran LCD
  pinMode(i, OUTPUT);
  }
  for (int y = 10; y < 12; y++){ // les boutons
    pinMode(y, INPUT);
  }
  pinMode(8, OUTPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  // PARTIE CAPTEUR GAZ
  int seuilGaz = 150;
  float gaz = analogRead(capteurGaz); // récupère le taux de gaz
  if(gaz >= seuilGaz){tone(buzzer, 900, 750);}
  // PARTIE CAPTEUR TEMPÉRATURE
  float temp = analogRead(capteurTemp);
  float volt = (temp/1024.0)*5.0;
  float temperature= (volt-0.5)*100;
  // vérifie la température et allume le buzzer si elle dépasse un seuil
  if(temperature >31)
  {tone(buzzer, 500, 500);}
  else if(temperature >30)
    {tone(buzzer, 400, 500);}
  else if(temperature >29.5)
  {tone(buzzer, 300, 500);}
  else if(temperature >29)
  {tone(buzzer, 250, 500);}
  else if(temperature >28.5)
    {tone(buzzer, 200, 500);}
  else if(temperature >28)
    {tone(buzzer, 150, 500);}
  
  if (temperature < -11)
  {tone(buzzer, 500, 500);}
  else if(temperature <-10)
    {tone(buzzer, 400, 500);}
  else if(temperature <-9.5)
  {tone(buzzer, 300, 500);}
  else if(temperature <-9)
  {tone(buzzer, 250, 500);}
  else if(temperature <-8.5)
    {tone(buzzer, 200, 500);}
  else if(temperature <-8)
    {tone(buzzer, 150, 500);}
  // PARTIE PHOTORESISTANCE
  int luminosite = analogRead(photoresistance); //capture la luminosité
  int val = map(luminosite, 100, 997, 0, 255);
  if(manuel==1){val = map(analogRead(molette), 0, 1023, 0, 255);}
  analogWrite(del, val); // allume les leds
  int luminosite_del = map(val, 0, 255, 0, 100); //TODO
  // PARTIE ECRAN LCD
  btn_gaz = digitalRead(btn_gaz_pin);
  btn_lumi = digitalRead(btn_lumi_pin);
  manuel = digitalRead(manuel_pin);
  lcd.clear();
  lcd.setCursor(0,0); //reset l'écran
  if(manuel==1){
    lcd.print("manuel: = "); lcd.print(luminosite_del); //affiche la luminosité.
    delay(500);
  }
  else if(btn_gaz == LOW){
    lcd.print("GAZ = "); lcd.print(gaz); //affiche la quantité de gaz.
    delay(500);
  }
  else if(btn_lumi == LOW){
    lcd.print("lumi% = "); lcd.print(luminosite_del); //affiche la luminosité.
    delay(500);
  }
  else {
    lcd.print("temp = "); lcd.print(temperature); //affiche la quantité de gaz.
    lcd.print("°C");
    delay(500);
  }
  //MONITEUR SÉRIE
  Serial.println(manuel);
  Serial.print("temperature: ");
  Serial.println(temperature);
  Serial.print("gaz: ");
  Serial.println(gaz);
  Serial.print("luminosite DEL: ");
  Serial.print(luminosite_del);Serial.println("%");
  Serial.println(""); //saut de ligne
}


📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ วงจร




Theme 6 วงจรพัฒนาเซ็นเซอร์ตรวจจับแก๊สพร้อมไฟ LED 3 ดวงและสัญญาณเตือน

 

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้  คำสั่งเขียน 


int const PIN_SGAS = A1;
int LED_green = 6;
int LED_yellow = 5;
int LED_red = 4;
int buzzer = 3;
void setup(){
    pinMode(LED_green, OUTPUT);
    pinMode(LED_yellow, OUTPUT);
    pinMode(LED_red, OUTPUT);
pinMode(buzzer, OUTPUT);
    Serial.begin(9600);
}
void loop(){
    int value = analogRead(PIN_SGAS);
    value = map(value, 300, 750, 0, 100);
  if(value < 30){
    digitalWrite(LED_green, HIGH);
    digitalWrite(LED_yellow, LOW );
    digitalWrite(LED_red, LOW );
    digitalWrite(buzzer, LOW ); 
  }
  else if(value >= 30 & value < 50){
    digitalWrite(LED_yellow, HIGH );
    digitalWrite(LED_red, LOW );
    digitalWrite(LED_green, LOW );
    digitalWrite(buzzer, LOW ); 
  }
   else {
   digitalWrite(LED_red, HIGH );
     digitalWrite(LED_yellow, LOW );
     digitalWrite(LED_green, LOW );
    tone(buzzer, 500); // Send 1KHz sound signal...
  delay(300);   // ...for 1 sec
  noTone(buzzer);     // Stop sound...
  delay(50);  // ...for 1sec
  }
  delay(250);
}

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ วงจร 






Theme 6 วงจรจำลองการทำงานของระบบ BELAJAR LCD 16X2

 

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้  คำสั่งเขียน 

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int adc;
void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);
  pinMode(A0, INPUT);
}
void loop()
{
  adc = analogRead(A0);
  lcd.setCursor(0, 0);
  lcd.print("NILAI ADC = ");
  lcd.setCursor(12, 0);
  lcd.print(adc);
  Serial.println(adc);
  delay(1000);
  lcd.setCursor(12, 0);
  lcd.print("    ");
  if (adc<=102){
  lcd.setCursor(0,1);
  lcd.print("[          ]= 0%");
  }
  if (adc>=103 && adc<=204){
  lcd.setCursor(0,1);
  lcd.print("[=         ]=10%");
  }
  if (adc>=205 && adc<=306){
  lcd.setCursor(0,1);
  lcd.print("[==        ]=20%");
  }
  if (adc>=307 && adc<=408){
  lcd.setCursor(0,1);
  lcd.print("[===       ]=30%");
  }
  
  if (adc>=309 && adc<=510){
  lcd.setCursor(0,1);
  lcd.print("[====      ]=40%");
  }
  if (adc>=511 && adc<=612){
  lcd.setCursor(0,1);
  lcd.print("[=====     ]=50%");
  }
  if (adc>=613 && adc<=714){
  lcd.setCursor(0,1);
  lcd.print("[======    ]=60%");
  }
  
  if (adc>=715 && adc<=816){
  lcd.setCursor(0,1);
  lcd.print("[=======   ]=70%");
  }
  if (adc>=817 && adc<=918){
  lcd.setCursor(0,1);
  lcd.print("[=======   ]=80%");
  } 
  if (adc>=919 && adc<=1020){
  lcd.setCursor(0,1);
  lcd.print("[========= ]=90%");
  }
  if (adc>=1021 && adc<=1023){
  lcd.setCursor(0,1);
  lcd.print("[==========]100%");
  }

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ วงจร 




Theme 6 โครงงานประยุกต์ New Gas Sensor with piezo and led and lcd Display

 

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ คำสั่งเขียน 

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buzzer = 10;
void setup() {
  Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  pinMode(13,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(6,OUTPUT);
}
void loop() {
  int gas_data;
  gas_data = analogRead(A0);
  lcd.setCursor(00,00);
  lcd.print("Gas :");
  lcd.setCursor(6,00);
  lcd.print(gas_data);
  if(gas_data > 800){
  digitalWrite(13,HIGH);
    delay(100);
    digitalWrite(13,LOW);
    lcd.setCursor(00,1);
    lcd.print("DANGER");
    tone(buzzer, 1000, 200);
  }else if(gas_data > 700){
    digitalWrite(6,HIGH);
  delay(100);
    digitalWrite(6,LOW);
    lcd.setCursor(00,1);
    lcd.print("WARNING");
    tone(buzzer, 250, 50);
  }else {
    digitalWrite(7,HIGH);
    delay(100);
    digitalWrite(7,LOW);
    lcd.setCursor(00,1);
    lcd.print("SAFE");
    noTone(buzzer);
  }
  Serial.println(gas_data);
  delay(100);
  lcd.clear();
}


📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ วงจร 




Theme 6 วงจรจำลองระบบการทำงาน Projeto LCD 16x2 และโพเทนซิโอเมโทร

 

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ คำสั่ง 

// inclusao da biblioteca 'LiquidCrystal'
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
// lcd 16 colunas x 2 linhas
void setup() {
lcd.begin(16, 2);
}
void loop() {
  lcd.clear();
  lcd.setCursor(0,0); // coluna x linha
  lcd.print("CURSO DE ARDUINO:"); // mensagem que aparecerá na linha 1
  lcd.setCursor(2,1);
  lcd.print("DISPLAY LCD!"); // mensagem que aparecerá na linha 2
  delay(3000); // tempo em que a mensagem ficará 'fixa'
  // move o texto do lcd para a esquerda
  for(int posicao = 0; posicao < 16; posicao++) {
    lcd.scrollDisplayLeft();
    delay(100);
  }
  // move o texto do lcd para a direita
  for(int posicao = 0; posicao < 16; posicao++) {
    lcd.scrollDisplayRight();
    delay(100);
  }
}

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ วงจร 




Theme 5 วงจรพัฒนาโครงงานจำลอง IMU Simulation ( Inertial Measurement Unit )

 

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ คำสั่งเขียน 

#include <Servo.h>
Servo myservo1; //create servo object
Servo myservo2; //create servo object
Servo myservo3; //create servo object
//EMA stands for (Exponential moving average)
//Used pins
//accelerometer
const int x_pin = A0;
const int y_pin = A1;
const int z_pin = A2;
//Potentiometer
const int gx_pin = A3;
const int gy_pin = A4;
const int gz_pin = A5;
//Servo
const int servoPin1 = 3;
const int servoPin2 = 5;
const int servoPin3 = 11;
//variables
//initialization of sensor variable, equibalaent 
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
//EMA 
float EMA_a = 0.02; //initialization of EMA alpha
int EMA_S1 = 0; //initialization of EMA S1
int EMA_S1_map = 0; //initialization of variable for servo control
int EMA_S2 = 0; //initialization of EMA S2
int EMA_S2_map = 0; //initialization of variable for servo control
int EMA_S3 = 0; //initialization of EMA S3
int EMA_S3_map = 0; //initialization of variable for servo control
int angleX = 0;
int angleY = 0;
int angleZ = 0;
// time
unsigned long startTime = 0;
unsigned long currentTime = 0;
unsigned long elapsedTime = 0;

// Volts per G-Force
const float sensitivity = 0.206;
void setup() {
  Serial.begin(115200);
  analogReference(EXTERNAL);
  EMA_S1 = analogRead(x_pin); //set EMA S for t = 1
  EMA_S2 = analogRead(y_pin); //set EMA S for t = 1
  EMA_S3 = analogRead(z_pin); //set EMA S for t = 1
  myservo1.attach(servoPin1);
  myservo2.attach(servoPin2);
  myservo3.attach(servoPin3);
}
void loop() {
  currentTime = millis();
  elapsedTime = currentTime - startTime;
  // Read pins and convert to G
  // accelerometer rate
  float ax = (analogRead(x_pin) - 512) * 3.3 / (sensitivity * 1023);
  float ay = (analogRead(y_pin) - 512) * 3.3 / (sensitivity * 1023);
  float az = (analogRead(z_pin) - 512) * 3.3 / (sensitivity * 1023);
  // gyroscope rate
  float gx = (analogRead(gx_pin) - 512) * 3.3 / (sensitivity * 1023);
  float gy = (analogRead(gy_pin) - 512) * 3.3 / (sensitivity * 1023);
  float gz = (analogRead(gz_pin) - 512) * 3.3 / (sensitivity * 1023);
  // serva 1
  move_motor(x_pin, EMA_S1, EMA_S1_map, sensorValue1, gx);
  angleX = complementaryFilter(angleX, gx, elapsedTime, EMA_S1);
  myservo1.write(angleX);//send the latest value to the servo
//  myservo1.write(EMA_S1_map);//send the latest value to the servo
  // serva 2
  move_motor(y_pin, EMA_S2, EMA_S2_map, sensorValue2, gy);
  angleY = complementaryFilter(angleY, gy, elapsedTime, EMA_S2);
  myservo2.write(angleX);//send the latest value to the servo
  //myservo2.write(EMA_S2_map);//send the latest value to the servo
  // serva 3
  move_motor(z_pin, EMA_S3, EMA_S3_map, sensorValue3, gz);
  angleZ = complementaryFilter(angleZ,gz, elapsedTime, EMA_S3);
  myservo3.write(angleZ);//send the latest value to the servo
 // myservo3.write(EMA_S3_map);//send the latest value to the servo
  delay(100);
  startTime = currentTime;
}
void move_motor(int input_pin, int &EMA_S, int &EMA_S_map, int &sensorValue, float gyroVar){
  sensorValue = analogRead(input_pin); //read the sensor
  EMA_S = (EMA_a*sensorValue) + ((1-EMA_a)*EMA_S);//run the EMA
  Serial.print("pin ");
  Serial.print(input_pin);
  Serial.print(": ");
  Serial.print(sensorValue);//the first variable for plotting
  Serial.print(",");//seperator
  Serial.println(EMA_S);//the second variable for plotting including line break 
  EMA_S_map = map(EMA_S, 0, 1023, 0, 180);//map ADC values to servo values (0-180)
};
//Complementary Filter, similar to exponential, this example is for an accelerometer
// The 0.98 and 0.02 are the same as the weights in the exponential filter 
//angle = 0.98 *(angle+gyro*dt) + 0.02*acc

float complementaryFilter(float angle, float gyro, float dt, float acc)
{
float totalAngle = .5 * (angle + gyro * dt) + .5 * acc;
    return totalAngle;
}

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้ วงจร