arduino mega2560 ไฟdigital output ไม่พอครับ เช็คอุปกรณ์ดูแล้วปกติทุกอย่าง ครับ
อุปกรณ์ตามนี้ครับ
พอใส่โค๊ตัวนี้ไป
#include
#include
#include
#include <LiquidCrystal_I2C.h>
Password password = Password( "1234" ); // Set the Password
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
const int status_lock = A0; // LED Status Pin
const int status_unlock = A1; // LED Status Pin
int led = 14; // Buzzer Module Pin
int pir = 9;
int fl = 0, state = 0, state1 = 0, state2 = 0; // Flag
int dir = 8, dir1 = 0;
String test = " ";
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(22,INPUT);
Serial.begin(9600); // Define Serial for Debug Sensor & Keyped
lcd.begin(); //Define LCD
lcd.backlight();//lcd.backlight();
pinMode(status_lock, OUTPUT); // Sets the digital pin as output
pinMode(status_unlock, OUTPUT); // Sets the digital pin as output
pinMode(pir,INPUT);
keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
// Sets First Screen LCD
lcd.print("* Hello Pirun *");
lcd.setCursor(0, 1);
lcd.print("** Home Lock **");
}
void loop()
{
keypad.getKey(); // Check the Keyped
motion_on(); // Open PIR Motion Sens
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
//Serial.print("Pressed: ");
//Serial.println(eKey);
lcd.setCursor(dir1, 1);
lcd.print(test);
test = "*";
lcd.setCursor(dir, 3);
lcd.print(test);
dir1 = dir;
switch (eKey)
{
case '*':
if(fl == 1)
{
state2 = 1;
lcd.setCursor(0, 1);
lcd.print("** Home Lock **");
dir = 8;
dir1 = 0;
test = " ";
}
break;
case '#':
state2 = 0;
checkPassword(); // Call the function CheckPassword
password.reset(); //Reset Key
dir = 8;
dir1 = 0;
test = " ";
lcd.setCursor(0, 1);
lcd.print(test);
break;
default: password.append(eKey);
dir++;
}
}
}
void checkPassword() // Function check the password
{
if (password.evaluate()){
//Add code to run if it works
while(state2 == 0)
{
//Serial.println("Success");
fl = 1;
digitalWrite(status_lock, LOW);
digitalWrite(status_unlock, HIGH);
lcd.setCursor(0,1);
lcd.print("**Un Lock**");
keypad.getKey();
Alarm_off();
password.reset();
}
}
else{
Serial.println("Wrong");
//add code to run if it did not work
lcd.setCursor(0,1);
digitalWrite(led,HIGH);
lcd.print("**Password Wrong**");
delay(1000);
}
}
void Alarm() // Function Alarm.
{
digitalWrite(led,HIGH);
}
void Alarm_off() // Function Alarm off.
{
digitalWrite(led,LOW); //Set buzzer pin is HIGH for stop alarm
}
void motion_on() // Function Open PIR Motion Sensor.
{
if(pir ==HIGH) // Check the value
{
digitalWrite(led,HIGH);
}
if(pir ==LOW)
{
digitalWrite(led,LOW);
}
}
ไฟที่ขา 14 วัดได้ 0.22V. ครับ
แต่พอใส่โค๊ตตัวไนี้ไป
const int buttonPin = 9; // the number of the pushbutton pin
const int ledPin = 14; // the number of the LED 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:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
วัดไฟที่ขา 14 ได้ 4.5-4.8 V.ครับ
โดยทั้งสองโค๊ตใส่อุปกรณ์เหมือนกัน
ช่วยแนะนำทีครับว่าอาการนี้จะแก้ไขยังไงครับ ขอบคูณครับ
จากข้อมูลที่ให้มา ขาที่บอร์ดใช้งานได้ปกติ อาจเป็นกับโคดโปรแกรม เพราะขาสามารถจ่ายไฟได้0-5โวลต์หรือกระแสไม่พออาจจะลองต่อแหล่งจ่ายไฟภายนอกครับ