简体   繁体   English

使用Arduino串口打开LED。 我怎么了

[英]Using Arduino Serial to turn on LED. What is my error?

void setup(){
    Serial.begin(9600);
    pinMode(13, OUTPUT);
}

void loop() {
    if (Serial.available() > 0){
       int inChar = Serial.read();
       if (inChar == 'H'){
           digitalWrite(13, HIGH);
       }
       if (inChar == 'L'){
        digitalWrite(13, LOW); 
       }
    }
}

I have seen very similar programs. 我看过非常相似的程序。 I don't get any compile errors, but the led light won't turn on. 我没有任何编译错误,但led灯无法打开。 Is there an error in my code? 我的代码中有错误吗? Thanks 谢谢

Sounds like a hardware issue. 听起来像是硬件问题。 Double check that first. 首先仔细检查。

Use a digital multimeter (DMM) to read the voltage between pin 13 and Arduino ground. 使用数字万用表(DMM)读取引脚13和Arduino接地之间的电压。 It should output 5V when you send the 'H'. 发送“ H”时,它应输出5V。 If it does, then your problem is the LED. 如果是这样,那么您的问题就是LED。 If it does not output 5V when you send the 'H' then you have a software or serial communication issue. 如果在发送“ H”时它不输出5V,则说明软件或串行通讯有问题。

Double check that you have the correct BAUD rate and COM port settings in whatever program is talking to the Arduino. 仔细检查与Arduino通讯的程序中的波特率和COM端口设置是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM