Isnin, 30 Disember 2019

Arduino Untuk Kawalan Umum

Litar serta kod ini boleh digunakan untuk mengawal apa2 sahaja berdasarkan condition base yang diberikan oleh digital input daripada sensor.

Boleh menggunakan apa2 sensor seperti Flame Sensor, Infrared Sensor, Ultrasonic Sensor, Hall Sensor, malah suis mekanikal seperti Roller Micro Switch juga boleh.

Output boleh digunakan untuk menyalakan LED, membunyikan Buzzer atau memandu Relay untuk mengawal fungsi lain yang lebih besar seperti pam, spotlight, solenoid dan sebagainya.

Kod diubahsuai daripada "Pushbutton"

Sesuai digunakan untuk pengenalan dan mempelajari fungsi asas kawalan menggunakan Arduino.



Sila copy dan paste kod di bawah pada Arduino IDE.

//
//  Digital Input Trigger & Output Drives

//  Turns on and off a light emitting diode(LED, buzzer, relay, etc connected to digital pin 13,
//  when digital signal is present at pin 2.

//  The circuit:
// - Output connected to  pin 13 and GND return Input from any sensor signal connected to pin 2 for auto trigger
// - pushbutton attached to pin 2 from +5V and 10K resistor attached to pin 2 from ground for manual trigger

//- Note: on most Arduinos there is already an LED on the board
//    attached to pin 13.

//  Button program was created in 2005
//  by DojoDave <http://www.0j0.org>
//  modified 30 Aug 2011
//  by Tom Igoe
//  modified 29 Dec 2020
//  by Rosedi
//  for general control using any sensors

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton or input pin
const int ledPin =  13;      // the number of the LED pin or output pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    delay (0); // waiting time before activate output
    digitalWrite(ledPin, LOW);
  } else {
    // turn LED off:
    digitalWrite(ledPin, HIGH);
  
  }
}


Dapatkan Arduino Uno ori dari Italy di sini ;





Arduino R3 China





KURSUS - BASIC ARDUINO

Untuk artikel kali ini saya menggunakan bahasa rojak ya. Utamanya bahasa melayu dengan istilah2 teknikal dalam bahasa Inggeris sekiranya leb...