If commands sending signal to the wrong LED

Hi,
I'm trying to make a sound level monitor with an arduino uno, with the 433MHz RF Tx-Rx Modules sending input from a mic in one place to the arduino board and lighting the LED up.
But, if one of the mics at the ardunio side send a signal, then the LED that has the mic elsewhere lights up and doesn't turn off unless it gets a signal
I don't know how to fix it so some help would be appreciated (The code is below)

const int leftPin = 13;
const int rightPin = 12;
const int monoPin = 11;
const int onPin = 10;
const int leftsoundPin = 9;
const int rightsoundPin = 8;
const int monosoundPin = 7;
const int laserPin = 6;
 
int leftsoundVal = 0;
int rightsoundVal = 0;
int monosoundVal = 0;


void setup ()
{
  pinMode (leftPin, OUTPUT);
  pinMode (rightPin, OUTPUT);
  pinMode (monoPin, OUTPUT);
  pinMode (onPin, OUTPUT);
  pinMode (leftsoundPin, INPUT);
  pinMode (rightsoundPin, INPUT);
  pinMode (monosoundPin, INPUT);
  pinMode (laserPin, OUTPUT);

  digitalWrite(laserPin, HIGH);
  digitalWrite(onPin, HIGH);
  delay(500);
  digitalWrite(onPin, LOW);
  delay(500);
  digitalWrite(onPin, HIGH);
  delay(500);
  digitalWrite(onPin, LOW);
  delay(500);
  digitalWrite(onPin, HIGH);
  delay(500); 
  }
void loop ()
{

  leftsoundVal = digitalRead(leftsoundPin);
  rightsoundVal = digitalRead(rightsoundPin);
  monosoundVal = digitalRead(monosoundPin);

 if (monosoundVal == HIGH)
   {
    
    digitalWrite(monoPin, HIGH);
  }
  else {
   digitalWrite(monoPin, LOW);
  }
  
  if (leftsoundVal == HIGH)
  {
    digitalWrite(leftPin, LOW);

  }

  else {
   digitalWrite(leftPin, HIGH);
  }
    if (rightsoundVal == HIGH)
  {
    digitalWrite(rightPin, LOW);
   
    
  }
  else {
   digitalWrite(rightPin, HIGH);
  }
  
  
  }


  

I can't troubleshoot code very well but I would add a serial output (to be printed to the IDE monitor). Add print statements in you code to see what is happening.

Your code appears to be looking for the analog read values to be 0 or 1 for some reason. Are you sure an analog read works that way?
Paul

Hi,
Can you please post a copy of your circuit?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

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