I am trying to communication between Arduino and Nodejs. But problem is when I communicate between I got correct reading as well as some garbage reading in between correct reading. Still cant understand how to resolve this problem ?
Here is the Nodejs part which is used to read data from COM port
var SerialPort = require("serialport").SerialPort;
var serialport = new SerialPort("COM23",{baudrate:9600});
serialport.on('open', function(){
serialport.on('data', function(data){
console.log(data[0]);
});
});
Here is my simple Arduino code
int led = 13;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
Serial.write(1);
delay(1000);
digitalWrite(led, LOW);
Serial.write(0);
delay(1000);
}