Code confirms Pin is High but how do I know for sure! Need another way to test!

Hi everyone,

I wrote the code below to confirm that my pin 6 output is going high when the sound sensor reaches over a threshold. In the serial monitor it's showing me that everything is working. Is there any other way I can check? It's not triggering another device that requires the 5V to be switched.

Any suggestions?

int LedOutput = 6;
int SoundSensor = A0;

void setup() {

  pinMode(LedOutput, OUTPUT); //make sure you have set your pins as inputs or outputs
  pinMode(SoundSensor, INPUT); // setup input
  Serial.begin(9600); // setup serial
}

void loop() {

Serial.println(analogRead(A0));
delay(100);
  
  if(analogRead(SoundSensor) > 9) { //if the analog value of SoundSensor/Input A0 is greater than 9 then
    digitalWrite(LedOutput, HIGH); //write digital pin LedOutput high
  }
  else {
    digitalWrite(LedOutput, LOW); //if it isn't higher than 9, make pin LedOutput low
  }

  if (digitalRead(LedOutput) == HIGH){

  Serial.println("The line went high");
  delay(1000);
  }
}

You can read the level on pins with digitalRead(), what are we missing ?

example:

if (digitalRead(LedOutput) == HIGH)
{
. . .
}

Yes, but it's like playing the game, "what number am I thinking of", with yourself... the output never changes or doesn't change without a command that you gave it. So it's definitely possible to find in the code itself. If it's not triggering something external, look at that something and your connections to it.

Put only an LED and resistor on the output and see if it follows.

Or you could check the output pin with a voltmeter.

Disconnect everything else from the pin in either case. If you see the pin going high and low then it’s the external circuitry you have that is not operating as you think it should, so

draw us a picture of that or at least tell us what you’ve hooked up and what you think it’s supposed to do.

a7

If you have the arduino and another device this is a system with multiple places where the error could be.

So to narrow down the rpoblem you have to narrow down your system in smaller parts.
As long as you have Arduino------wire----device there are four subsystems
program, Arduino-hardware, wire, device

If you disconnect the wire from your IO-pin 6 and connect it directly to 5V the device should react
5V----wire----device

if it does not the error might be in the wire or the device
so change the wire and check again
5V----other wire----device

still not working then it is very likely that the error is inside the device
otherwise you found the error: wire broken
checking the potential broken wire with an Ohm-Meter or a very simple circuit with a current-limiting-resistor and an LED

If all this works the error might be on the arduino-board.
Pre-check: of current-limiting-resistor and LED itself by connecting them directly to ground and +5V

Check IO-pin with current-limiting-resistor and LED does the LED light up if your program sets output-pin HIGH?
If you think there is something weird go back to the most simpel code the classical blink and check with this
If the simple blink works it is very likely that the error is inside your code

best regards Stefan

Forgot to common the grounds perhaps?

MarkT --- You are the winner! LOL! That was the simple solution!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.