Duplicate analogue output :-\

Hi

I'm having real problems trying to work this one out, so would be very grateful for any pointers.

I've hooked up 5 LDRs to one Arduino using a breadboard, and should be getting 5 seperate readings - one for each. The first three are working perfectly, but pins 4 and 5 are showing the exact same reading, and are triggering the same sound (sounds are played when the reading drops to ambient-100, and stopped when the reading is above this figure). There is one mp3 file associated with each LDR, but where LDRs 1, 2, and 3 are each triggering the correct corresponding sound when a hand is placed over the relevant one (blocking the light), LDR 4 is triggering the sounds of both 4 and 5, and LDR 5 isn't triggering anything! (I hope I'm making sense!) =(

It's not a coding issue because I've checked it several times. I've got two boards, and one works perfectly with the same code. I would understand that if there was a hardware issue the 'faulty pin' (??) wouldn't trigger a sound because it gives a reading of zero, but I don't understand how it's seemingly pinching the reading from the next pin??!

Any ideas?

Let me know if you need any more info.

Cheers

Kate

Sounds like a coding problem. Look carefully at the code that directs LDR4 to play the LDR4 sound and LDR5 to play the LDR5 sound.

If you don't see a problem, please post your sketch and maybe someone else will spot a problem.

You are saying there is mp3, some kind of shield board? Can you verify that shield isn't using pins 4 and 5?

orange_fox:
I would understand that if there was a hardware issue the 'faulty pin' (??) wouldn't trigger a sound because it gives a reading of zero, but I don't understand how it's seemingly pinching the reading from the next pin??!

That's faulty logic. If the pin is faulty it would not necessarily read as 0.

It is possible the two pins are shorted together with a solder bridge.

Hi,

OK, there a small error with my code, but only on the "println("Pin 5 = " + photocellReading5);

  • println("Ambient5 = " + ambient5);*" lines. I stupidly put "println("Pin 5 = " + photocellReading4);
  • println("Ambient5 = " + ambient4);*" , which would explain the apparent duplicate reading. This still hasn't solved the issue of the sound problem though. In fact it has actually confused me even more, because according to the readings both pins seem to be working well .... and independently.

Do you think it could be a faulty breadboard?

I guess there is a chance there could be something wrong with my code, but I've checked it over and over, so I don't think there is. Maybe you'll spot something I've missed! Here it is:

import processing.serial.*;
import cc.arduino.*;
import ddf.minim.*;

Minim minim, minim2;
AudioPlayer player1, player2, player3, player4, player5, player6, player7, player8, player9, player10;
int ambient;
int ambient1 = ambient;
int ambient2 = ambient;
int ambient3 = ambient;
int ambient4 = ambient;
int ambient5 = ambient;
int ambient6 = ambient;
int ambient7 = ambient;
int ambient8 = ambient;
int ambient9 = ambient;
int ambient10 = ambient;

int photocellPin1 = 0;
int photocellPin2 = 1;
int photocellPin3 = 2;
int photocellPin4 = 3;
int photocellPin5 = 4;

Arduino arduino, arduino2;

void setup() {	  
  println(arduino.list()); 
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  arduino2 = new Arduino(this, Arduino.list()[1], 57600);
  size(512, 200);
  minim = new Minim(this);
 
 player1 = minim.loadFile("quiet_bass.mp3", 2048);
 player2 = minim.loadFile("3_tom.mp3", 2048);
 player3 = minim.loadFile("egg.mp3", 2048);
 player4 = minim.loadFile("fast_bongo.mp3", 2048);
 player5 = minim.loadFile("high_1.mp3", 2048);
 player6 = minim.loadFile("last_bass.mp3", 2048);
 player7 = minim.loadFile("off_bongo.mp3", 2048);
 player8 = minim.loadFile("scrape_click.mp3", 2048);
 player9 = minim.loadFile("sticks.mp3", 2048);
 player10 = minim.loadFile("bass.mp3", 2048);
}

void draw() {
  int photocellReading1 = arduino.analogRead(photocellPin1);
  int photocellReading2 = arduino.analogRead(photocellPin2);
  int photocellReading3 = arduino.analogRead(photocellPin3);
  int photocellReading4 = arduino.analogRead(photocellPin4);
  int photocellReading5 = arduino.analogRead(photocellPin5);
  int photocellReading6 = arduino2.analogRead(photocellPin1);
  int photocellReading7 = arduino2.analogRead(photocellPin2);
  int photocellReading8 = arduino2.analogRead(photocellPin3);
  int photocellReading9 = arduino2.analogRead(photocellPin4);
  int photocellReading10 = arduino2.analogRead(photocellPin5);
  
   if(ambient1 == 0) ambient1 = arduino.analogRead(photocellPin1);
  if (photocellReading1 < ambient1-100) {
    if(player1.isPlaying()) {

    }
    else {
      player1.play(0);
    }
  } 
  
  else {
    if(player1.isPlaying()) {
      player1.pause();
      player1 = minim.loadFile("quiet_bass.mp3", 2048);
    }
  } 


   if(ambient2 == 0) ambient2 = arduino.analogRead(photocellPin2);
  if (photocellReading2 < ambient2-100) {
    if(player2.isPlaying()) {

    }
    else {
      player2.play(0);
    }
  } 
  
  else {
    if(player2.isPlaying()) {
      player2.pause();
      player2 = minim.loadFile("3_tom.mp3", 2048);
    }
  } 
 
 
    if(ambient3 == 0) ambient3 = arduino.analogRead(photocellPin3);
  if (photocellReading3 < ambient3-100) {
    if(player3.isPlaying()) {

    }
    else {
      player3.play(0);
    }
  } 
  
  else {
    if(player3.isPlaying()) {
      player3.pause();
      player3 = minim.loadFile("egg.mp3", 2048);
    }
  }  


   if(ambient4 == 0) ambient4 = arduino.analogRead(photocellPin4);
  if (photocellReading4 < ambient4-100) {
    if(player4.isPlaying()) {

    }
    else {
      player4.play(0);
    }
  } 
  
  else {
    if(player4.isPlaying()) {
      player4.pause();
      player4 = minim.loadFile("fast_bongo.mp3", 2048);
    }
  } 
  
   
     if(ambient5 == 0) ambient5 = arduino.analogRead(photocellPin5);
  if (photocellReading5 < ambient5-100) {
    if(player5.isPlaying()) {

    }
    else {
      player5.play(0);
    }
  } 
  
  else {
    if(player5.isPlaying()) {
      player5.pause();
      player5 = minim.loadFile("high_1.mp3", 2048);
    }
  } 


 if(ambient6 == 0) ambient6 = arduino2.analogRead(photocellPin1);
  if (photocellReading6 < ambient6-100) {
    if(player6.isPlaying()) {

    }
    else {
      player6.play(0);
    }
  } 
  
  else {
    if(player6.isPlaying()) {
      player6.pause();
      player6 = minim.loadFile("last_base.mp3", 2048);
    }
  } 
  
  
   if(ambient7 == 0) ambient7 = arduino2.analogRead(photocellPin2);
  if (photocellReading7 < ambient7-100) {
    if(player7.isPlaying()) {

    }
    else {
      player7.play(0);
    }
  } 
  
  else {
    if(player7.isPlaying()) {
      player7.pause();
      player7 = minim.loadFile("off_bongo.mp3", 2048);
    }
  } 
  
  
   if(ambient8 == 0) ambient8 = arduino2.analogRead(photocellPin3);
  if (photocellReading8 < ambient8-100) {
    if(player8.isPlaying()) {

    }
    else {
      player8.play(0);
    }
  } 
  
  else {
    if(player8.isPlaying()) {
      player8.pause();
      player8 = minim.loadFile("scrape_click.mp3", 2048);
    }
  } 
  
  
   if(ambient9 == 0) ambient9 = arduino2.analogRead(photocellPin4);
  if (photocellReading9 < ambient9-100) {
    if(player9.isPlaying()) {

    }
    else {
      player9.play(0);
    }
  } 
  
  else {
    if(player9.isPlaying()) {
      player9.pause();
      player9 = minim.loadFile("sticks.mp3", 2048);
    }
  } 
  
  
   if(ambient10 == 0) ambient10 = arduino.analogRead(photocellPin5);
  if (photocellReading10 < ambient10-100) {
    if(player10.isPlaying()) {

    }
    else {
      player10.play(0);
    }
  } 
  
  else {
    if(player10.isPlaying()) {
      player10.pause();
      player10 = minim.loadFile("bass.mp3", 2048);
    }
  } 


  println("Pin 1 = " + photocellReading1);
  println("Ambient1 = " + ambient1);
  
  println("Pin 2 = " + photocellReading2);
  println("Ambient2 = " + ambient2);
  
  println("Pin 3 = " + photocellReading3);
  println("Ambient3 = " + ambient3);
  
  println("Pin 4 = " + photocellReading4);
  println("Ambient4 = " + ambient4);
  
  println("Pin 5 = " + photocellReading5);
  println("Ambient5 = " + ambient5);
  
  println("Pin 6 = " + photocellReading6);
  println("Ambient6 = " + ambient6);
  
  println("Pin 7 = " + photocellReading7);
  println("Ambient7 = " + ambient7);
  
  println("Pin 8 = " + photocellReading8);
  println("Ambient8 = " + ambient8);
  
  println("Pin 9 = " + photocellReading9);
  println("Ambient9 = " + ambient9);
  
  println("Pin 10 = " + photocellReading10);
  println("Ambient10 = " + ambient10);
 
  delay(10);
}

void stop()
{
  player1.close();
  player2.close();
  player3.close();
  player4.close();
  player5.close();
  player6.close();
  player7.close();
  player8.close();
  player9.close();
  player10.close();
  
  minim.stop();
  super.stop();
}

Moderator edit: code tags added

(I know I should be using arrays, but I don't know how to yet I'm afraid. And I'll probably run out of time to learn at this rate because my project's due in next week)

Thank you so much for the replies so far. Very much appreciated!

Do you think a faulty breadboard could produce the un-expected events explained above? I don't want to go out and buy a new one if it's not likely to be that!

I can't help but notice that this is processing code not arduino code.
Also pins A4 & A5 are the I2C lines, you are not using I2C on the arduino are you?
If you are running Firmatta on the arduino, what sort of arduino is it, it dosn't work so well on a Mega.