I just make a simple circuit with uno and breadboard ,that connected 4 LED and 4 IR sensor. The arduino program is simple that makes the light on or off with the determination of IR sensors .
However my computer cannot find the USB COM when it connects the 5v and GND. Hence, I plug out the 5v and GND that connect to the breadboard .The computer can recognize COM 4 then . I successfully upload the program after this .
Now , when I connect the computer and UNO to give battery to UNO , no battery passed (because the computer cannot detect the USB COM) .The lights of IR sensor aren't on .How to tackle the problem?
It failed to give battery with external battery too unless I plug out the 5v and GND
This is my simple program:
int irPin1 = 2;
int ledPin1 = 13;
int irPin2 = 3;
int ledPin2 = 11;
int irPin3 = 4;
int ledPin3 = 9;
int irPin4 = 5;
int ledPin4 = 7;
int serialSpeed = 9600;
void setup() {
// put your setup code here, to run once:
pinMode(irPin1,INPUT);
pinMode(irPin2,INPUT);
pinMode(irPin3,INPUT);
pinMode(irPin4,INPUT);
pinMode(ledPin1,OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(ledPin3,OUTPUT);
pinMode(ledPin4,OUTPUT);
Serial.begin(serialSpeed);
}
void loop() {
// put your main code here, to run repeatedly:
int reading1 = digitalRead(irPin1);
int reading2 = digitalRead(irPin2);
int reading3 = digitalRead(irPin3);
int reading4 = digitalRead(irPin4);
digitalWrite(ledPin1,reading1);
digitalWrite(ledPin2,reading2);
digitalWrite(ledPin3,reading3);
digitalWrite(ledPin4,reading4);
String output = "{\"1\":" + (String)reading1 + ",\"2\":" + (String)reading2 + ",\"3\":" + (String)reading3 + ",\"4\":" + (String)reading4 + "}";
// String output = "{\"" + (String)reading1 + "\",\"" + (String)reading2 + "\",\"" + (String)reading3 + "\",\"" + (String)reading4 + "\"}";
Serial.println(output);
delay(100);
}
My Arduino circuit:
UNO 5v to breadboard 5v
UNO GND to breadboard GND
1st set: IR :5v GND from breadboard , pin from UNO
2nd set: IR :5v GND from breadboard , pin from UNO
3rd set: IR :5v GND from breadboard , pin from UNO
4th set: IR :5v GND from breadboard , pin from UNO