I work with an arduino nano every and I have a question about the power supply of my color sensor. If I connect the Vcc pin of my sensor to the 5V pin on my arduinoboard everything works as it should. My program gives me the different frequencies in my serial monitor, but the Vcc pin needs to be connected to the D11 pin on my board , because of the electric schematic we got from school. If I connect it to the D11 pin it gives only 0 as value in my serial monitor. I thought setting the D11 pin on HIGH with the digitalwrite command was the same as being connected to the 5V pin on my arduinoboard. Is it the same? Or am I doing something else wrong?
My code:
int PinColorSenS0 = 3;
int PinColorSenS1 = 5;
int PinColorSenS2 = 7;
int PinColorSenS3 = 9;
int PinColorSenVCC = 11;
int PinColorSenOUT = 2 ;
int PulseWidth = 0;
void setup() {
pinMode(PinColorSenS0, OUTPUT);
pinMode(PinColorSenS1, OUTPUT);
pinMode(PinColorSenS2, OUTPUT);
pinMode(PinColorSenS3, OUTPUT);
pinMode(PinColorSenVCC, OUTPUT);
pinMode(PinColorSenOUT, INPUT);
digitalWrite(PinColorSenVCC, HIGH);
digitalWrite(PinColorSenS0, LOW);
digitalWrite(PinColorSenS1,HIGH);
delay(100);
Serial.begin(9600);
delay(100);
}
void loop() {
digitalWrite(PinColorSenS2, LOW);
digitalWrite(PinColorSenS3, LOW);
PulseWidth = pulseIn(PinColorSenOUT, LOW);
Serial.print("PWRED = ");
Serial.print(PulseWidth);
Serial.print(" ");
delay(200);
}