This program is supposed to act as a Decimal To Binary Converter, the LeD's acting as output. The problem is that this function returns Garbage Value
const int LED1 =1, LED2 =3, LED3 =5; void setup() { Serial.begin(9600); pinMode (LED1, OUTPUT); pinMode (LED2, OUTPUT); pinMode (LED3, OUTPUT); } void loop() { int x = 0; x = Serial.read(); x = x-48; switch(x){ case 0: digitalWrite (LED1, LOW); digitalWrite (LED2, LOW); digitalWrite (LED3, LOW); break; case 1: digitalWrite (LED1, HIGH); digitalWrite (LED2, LOW); digitalWrite (LED3, LOW); break; case 2: digitalWrite (LED1, LOW); digitalWrite (LED2, HIGH); digitalWrite (LED3, LOW); break; case 3: digitalWrite (LED1, HIGH); digitalWrite (LED2, HIGH); digitalWrite (LED3, LOW); break; case 4: digitalWrite (LED1, LOW); digitalWrite (LED2, LOW); digitalWrite (LED3, HIGH); break; case 5: digitalWrite (LED1, HIGH); digitalWrite (LED2, LOW); digitalWrite (LED3, HIGH); break; case 6: digitalWrite (LED1, LOW); digitalWrite (LED2, HIGH); digitalWrite (LED3, HIGH); break; case 7: digitalWrite (LED1, HIGH); digitalWrite (LED2, HIGH); digitalWrite (LED3, HIGH); break; } Serial.write(x); }