บทความ

กำลังแสดงโพสต์จาก กันยายน, 2018

งานที่18

รูปภาพ
Code #include <SoftwareSerial.h> #include <DHT11.h> //============================================= #include <Wire.h>  #include <LiquidCrystal_I2C.h> //LiquidCrystal_I2C lcd(0x27, 16, 2); LiquidCrystal_I2C lcd(0x3F, 16, 2); SoftwareSerial ArduinoSerial(3, 2); // RX, TX //============================================= int SW_ON = 4,SW_OFF = 5,pin=6;//กำหนดขา INPUT  int Sun = 9,CSun = 0,Relay1 = 12, Relay2 = 11; //กำหนดขา OUTPUT    int ATL = A0,ATH = A1;//กำหนดขา Analog int VTL1 = 0,VTH1 = 0,TL = 0,TH =0,VRHL = 50,VRHH = 80;  DHT11 dht11(pin); //=============================================  void setup() {   lcd.begin();   Serial.begin(115200);   ArduinoSerial.begin(4800);   while (!Serial){     ;     }   //=====================================================    lcd.setCursor(0, 0);lcd.print("Elec Pattayatech");   lcd.setCursor(0, 1);lcd.print("Smart Farm 2016 ");   delay(5000);  

งานที่17

รูปภาพ
Code #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int aVal=0,tempaVal=0; const int SW_ON = 2; const int led_ON =  13; int CSW_ON = 0; int C_CSW_ON =0; int Relay1=12,Relay2=11,Relay3=10,Relay4=9; int sensorPin = A0; int sensorValue = 0; void setup() {   lcd.backlight();   lcd.begin();   Serial.begin(9600);   pinMode(led_ON, OUTPUT);pinMode(SW_ON, INPUT);   pinMode(Relay1,OUTPUT);pinMode(Relay2,OUTPUT);   pinMode(Relay3,OUTPUT);pinMode(Relay4,OUTPUT); //   digitalWrite(Relay1,HIGH);digitalWrite(Relay2,HIGH);   digitalWrite(Relay3,HIGH);digitalWrite(Relay4,HIGH);   lcd.setCursor(0,0);   lcd.print("Project2017");   lcd.setCursor(0,1);   lcd.print("standby"); } //END Setup void loop() {   CSW_ON = digitalRead(SW_ON);   sensorValue = analogRead(sensorPin);//Serial.println(sensorValue);   //=======================================================================   int c_sensorValue1 = map(sensorValue,0,1023,0,255);

งานที่16

รูปภาพ
Code #include <Stepper.h> #include "Keypad.h" #define STEP_ANGLE_4STEP 32 //360/11.25 degree #define STEP_OUT_WITH_GEAR 2048 //32*64 Stepper stepper(STEP_ANGLE_4STEP,8,10,9,11); char keys[4][4]={   {'7','8','9','A'},   {'4','5','6','B'},   {'1','2','3','C'},   {'*','0','#','D'}}; byte rowPins[] = {7,6,5,4}; byte colPins[] = {3,2,1,0}; int speedmotor = 400; int dirmotor = 1; Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4); void setup() { } void loop() {   char key = keypad.getKey();   if (key != NO_KEY)   {         if (key == '1')             speedmotor = 400;         if (key == '2')             speedmotor = 700;         if (key == '3')             speedmotor = 1000;          if (key == 'A')             dirmotor = 1;         if (key == 'B')             dir

งานที่15

รูปภาพ
Code #include <LedControl.h> #include <DHT11.h> int pin=4; DHT11 dht11(pin); LedControl lc=LedControl(8,10,9,1);  // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void show2digit(int h,int t) {   int seg1,seg2,seg3,seg4;   seg1 = h%10;   seg2 = h/10;   lc.setDigit(0,4,seg1,false);    lc.setDigit(0,5,seg2,false);   seg3 = t%10;   seg4 = t/10;   lc.setDigit(0,0,seg3,false);    lc.setDigit(0,1,seg4,false);   delay(300); } void setup() {   Serial.begin(9600);   while (!Serial) {       ; // wait for serial port to connect. Needed for Leonardo only     }   lc.shutdown(0,false);     lc.setIntensity(0,5);    lc.clearDisplay(0); } void loop() {   int err;   float temp, humi;   if((err=dht11.read(humi, temp))==0)   {     Serial.print("temperature:");     Serial.print(temp);     Serial.print(" humidity:");     Serial.print(humi);     Serial.println();        }

งานที่14

รูปภาพ
Code #include <LedControl.h> #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 11 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); float Tfloat; long Tint; LedControl lc=LedControl(8,10,9,1); // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void show6digit(int num) {   int seg1,seg2;   seg2 = (((((num%100000)%10000)%1000)%100)/10);   seg1 = (((((num%100000)%10000)%1000)%100)%10);   lc.setDigit(0,0,seg1,false);   if (num>=10)       lc.setDigit(0,1,seg2,false);   delay(300); } void setup(void) {   sensors.begin();   lc.shutdown(0,false);    lc.setIntensity(0,5);   lc.clearDisplay(0); } void loop(void) {   sensors.requestTemperatures();   Tfloat = sensors.getTempCByIndex(0);   Tint = int(Tfloat);   lc.clearDisplay(0);   show6digit(Tint); }

งานที่13

รูปภาพ
Code #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int PIRpin = 8; void setup() {   lcd.begin();   pinMode(PIRpin,INPUT);   lcd.home();   lcd.print("Waiting for PIR");   delay(10000);        lcd.clear(); } void loop() {   int x = digitalRead(PIRpin);   lcd.home();   lcd.print("PIR = ");   lcd.print(x);   delay(100); }

งานที่12

รูปภาพ
Code #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int triggerPin = 13; int echoPin = 12; long duration,distCM,temp_distCM=0; void setup() {   lcd.begin();   lcd.setCursor(0,0);   lcd.print("Dist =      cm");   pinMode(triggerPin,OUTPUT);   pinMode(echoPin,INPUT); } void loop() {   digitalWrite(triggerPin,LOW);   delayMicroseconds(2);   digitalWrite(triggerPin,HIGH);   delayMicroseconds(10);   digitalWrite(triggerPin,LOW);   duration = pulseIn(echoPin,HIGH);   distCM = duration/58;   if (temp_distCM != distCM)   {     lcd.setCursor(7,0);     lcd.print("    ");   }   lcd.setCursor(7,0);   lcd.print(distCM);   temp_distCM = distCM;   delay(300); }

งานที่11

รูปภาพ
Code #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int aval,temp_aval=0; void setup() {   lcd.begin();   lcd.setCursor(0,0);   lcd.print("aval = "); } void loop() {    aval = analogRead(A0);    if (temp_aval != aval)    {       lcd.setCursor(7,0);       lcd.print("    ");    }    lcd.setCursor(7,0);    lcd.print(aval);    temp_aval = aval;    delay(300); }

งานที่10

รูปภาพ
Code #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int aVal=0,tempaVal=0; void setup() {   lcd.begin(); } void loop() {   aVal = analogRead(A0);   if (tempaVal != aVal)   {     lcd.clear();     lcd.setCursor(0,0);     lcd.print("LDR");     lcd.setCursor(0,1);     lcd.print(aVal);     delay(300);   }   tempaVal = aVal; }

งานที่9

รูปภาพ
Code #include <Wire.h> #include <LiquidCrystal_I2C.h>  LiquidCrystal_I2C lcd(0x27,16,2); void setup() {   lcd.backlight();   lcd.begin();//LiquidCrystal_I2C } void loop()  {   lcd.setCursor(0,0);   lcd.print("Hello LCD I2C");   lcd.setCursor(0,1);   lcd.print("Pattayatech"); }

งานที่8

รูปภาพ
Code #include "LedControl.h" #include "Keypad.h" #define C4  262 #define D4  294 #define E4  330 #define F4  349 #define G4  392 #define A4  440 #define B4  494 #define C5  523 char keys[4][4]={   {7,8,9,0},   {4,5,6,0},   {1,2,3,0},   {0,0,0,0}}; byte rowPins[] = {7,6,5,4}; byte colPins[] = {3,2,1,0}; Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4); int melody[] = {C4,D4,E4,F4,G4,A4,B4,C5}; int dl = 300; int buzzerpin = 11; LedControl lc=LedControl(8,10,9,1); // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void setup() {   lc.shutdown(0,false);    lc.setIntensity(0,5);   lc.clearDisplay(0);   pinMode(buzzerpin,OUTPUT);   digitalWrite(buzzerpin,HIGH); } void loop() {   char key = keypad.getKey();   if ((key != NO_KEY) && (key < 9))   {     lc.setDigit(0,0,key,false);     tone(buzzerpin, melody[key-1],dl);     delay(dl);     digitalWrite(buzzerpin,HIGH);   } }

งานที่7

รูปภาพ
Code #include "LedControl.h" #define C4  262 #define D4  294 #define E4  330 #define F4  349 #define G4  392 #define A4  440 #define B4  494 #define C5  523 int melody[] = {C4,D4,E4,F4,G4,A4,B4,C5}; float beats[] ={1,1,1,1,1,1,1,1}; int buzzerpin = 11; int timestop = 70; LedControl lc=LedControl(8,10,9,1); // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void setup() {   lc.shutdown(0,false);    lc.setIntensity(0,5);   lc.clearDisplay(0);   int dl = 500;   pinMode(buzzerpin,OUTPUT);   int numnote;   numnote = sizeof(melody)/2;    for (int i=0;i<numnote;i++)   {     lc.setChar(0,7-i,'-',false);     tone(buzzerpin, melody[i],dl*beats[i]);     delay(dl*beats[i]);     digitalWrite(buzzerpin,HIGH);     delay(timestop);   } } void loop() { }

งานที่6

รูปภาพ
Code #include "LedControl.h" #include "Keypad.h" char keys[4][4]={   {'7','8','9','A'},   {'4','5','6','B'},   {'1','2','3','C'},   {'E','0','F','D'}}; byte rowPins[] = {7,6,5,4}; byte colPins[] = {3,2,1,0}; Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4); LedControl lc=LedControl(8,10,9,1); // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void setup() {   lc.shutdown(0,false);    lc.setIntensity(0,5);   lc.clearDisplay(0);      } void loop() {   char key = keypad.getKey();   if (key != NO_KEY)   {     lc.setChar(0,0,key,false);   } }

งานที่5

รูปภาพ
Code int led = 13; int sw = 2; void setup() {   Serial.begin(9600);   pinMode(led,OUTPUT);   pinMode(sw,INPUT);      } void loop() {   int x;   x = digitalRead(sw);   Serial.print("x = ");Serial.println(x);   digitalWrite(led,!x); }

งานที่4

รูปภาพ
Code int led = 10; void setup() {   Serial.begin(9600);   pinMode(led,OUTPUT);    } void loop() {   int x,y;   x = analogRead(A0);   y = map(x,0,1023,0,255);   Serial.print("x = ");Serial.println(x);   Serial.print("y = ");Serial.println(y);    analogWrite(led,y); }

งานที่3

รูปภาพ
Code #include "LedControl.h" LedControl lc=LedControl(5,7,6,1);  // Pin 5->DIN, 7->CLK, 6->CS(LOAD), 1 = No.of devices void show4digit(int num) {    int seg1,seg2,seg3,seg4;   seg1 = ((num%1000)%100)%10;   seg2 = ((num%1000)%100)/10;   seg3 = (num%1000)/100;   seg4 = num/1000;     lc.setDigit(0,0,seg1,false);    if (num>=10)     lc.setDigit(0,1,seg2,false);     if (num>=100)         lc.setDigit(0,2,seg3,false);     if (num>=1000)         lc.setDigit(0,3,seg4,false);        delay(300); } void setup() {     Serial.begin(9600);     lc.shutdown(0,false);       lc.setIntensity(0,5);      lc.clearDisplay(0);       } void loop() {     int num;     num = analogRead(A0);     Serial.print("analogRead=");Serial.println(num);     lc.clearDisplay(0);     show4digit(num); }

งานที่2

รูปภาพ
Code int led1 = 7;int led2 = 6;int led3 = 5;int led4 = 4; void setup() {     pinMode(led1,OUTPUT);pinMode(led2,OUTPUT);     pinMode(led3,OUTPUT);pinMode(led4,OUTPUT); } void loop() {     digitalWrite(led1,HIGH);digitalWrite(led2,LOW);     digitalWrite(led3,LOW);digitalWrite(led4,LOW);     delay(1000);     digitalWrite(led1,LOW);digitalWrite(led2,HIGH);     digitalWrite(led3,LOW);digitalWrite(led4,LOW);     delay(1000);     digitalWrite(led1,LOW);digitalWrite(led2,LOW);     digitalWrite(led3,HIGH);digitalWrite(led4,LOW);     delay(1000);     digitalWrite(led1,LOW);digitalWrite(led2,LOW);     digitalWrite(led3,LOW);digitalWrite(led4,HIGH);     delay(1000); }

งานที่1

รูปภาพ
Code int led = 13; void setup()  {   pinMode (led,OUTPUT) } void loop()  {   digitalWrite (led,HIGH)   delay(1000);   digitalWrite (led,LOW)   delay(1000); }

มินิโปรเจ็ค

รูปภาพ
MINI Projact เครื่องกดน้ำอัตโนมัติ Code int trigger = 8; int echo = 9; int relay = 7; float time=0,distance=0;  void setup() { Serial.begin(9600);  pinMode(trigger,OUTPUT);  pinMode(echo,INPUT);   pinMode(relay,OUTPUT); }  void loop() {  GGWP();  if(distance<10)  {   digitalWrite(relay,LOW);  }  else  {   digitalWrite(relay,HIGH);  } delay(1000); } void GGWP() {  digitalWrite(trigger,LOW);  delayMicroseconds(2);  digitalWrite(trigger,HIGH);  delayMicroseconds(10);  digitalWrite(trigger,LOW);  delayMicroseconds(2);  time=pulseIn(echo,HIGH);  // อ่านสัญญาณพัลส์ HIGH จากขา echo เเล้วเก็บไว้ในตัวแปร time  distance=time*340/20000;  // ค่าของtime คูณ 340 หารด้วย 20000 เเล้วเก็บไว้ในตัวแปร distance } อุปกรณ์ที่ใช้ 1.Arduino UNO R3 2. HCSR04 – Ultrasonic Sensor 3.Relay 4.Solenoid Valve   https://www.youtube.com/watch?v=dZNFAyR6Yh4

DIY Arduino Traffic Light Pedestrian Light Push Button Control (https://thecustomizewindows.com/2016/06/diy-arduino-traffic-light-pae-push-button/)

รูปภาพ
ere is How to Create  LED DIY Arduino Traffic Light – Pedestrian Light Push Button Control . When Pedestrians Will WALK, Cars Will Stop Logic.There is actually two parts – one is building the LED DIY Traffic Lights and Second Part is the Coding. We are using push button, but it can be a sensor in real. Most commonly many websites write about Arduino Traffic Light which automatically goes OFF and ON. That is not practical, it is more towards toy. It is example of basic implementation of Finite State Machines modeling in embedded. Creating DIY Arduino Traffic Light Pedestrian Light This should be a separate chapter. Raspberry has great pre-built traffic light add-ons like PI-TRAFFIC, PI-STOP, Traffic HAT and so on. But they cost minimum $10 for a set of two. Additionally we are not getting the desired realistic Pedestrian Light. For total 5 LEDs, it is meaningless to pay $10. We are taking about this stuff : You can mount the LED on PCB to get such thing or just put them over sim