Go Down

Topic: Multiple LDRs detection erratic (Read 3785 times) previous topic - next topic

tip2tail

Hello all,

This is my first Arduino project, I'm a software developer at heart! :)

I discussed my project initially on this board on another thread http://forum.arduino.cc/index.php?topic=207878.0... basically controlling 8x relays with the digital out pins, while monitoring the signals in from 4x LDRs on the analog pins.  This is all controlled from a PC application.  To be frank, I have been amazed at how easy it has been so far: all the relays are now being controlled, messages are flowing back and forward from the Uno to my app on the PC and I can get signal sent back from the LDRs.  However the LDRs are giving me a bit of an issue.

I have modified a sample program for using one LDR to light a single LED when the sensor is in low light to try and monitor 4 - as that is what I will need to be doing on my app.  The sensors themselves will located one per groove of the track, sharing a constant light source above.  When the car passes I need to detect it and send the signal back to the PC.

The problems I'm getting are that the sensors seem - well - flaky! I have tried various sensors, so I think its to do with my config or circuit.  Is there something I'm missing?  Has anyone got any advice?

I have included my test program code below, as well as a schematic of the test build project as it stands.

Hope someone can assist.

Mark

Code: [Select]

int iLightPins[4] = {0,1,2,3};
int iLEDPins[4] = {13,12,11,10};

void setup() {
  Serial.begin(9600);
  Serial.println("SETUP");
  for (int i=0; i<4; i++) {
    pinMode(iLEDPins[i], OUTPUT);
  }
}

void loop() {
  int iLightPin = -1;
  int iLEDPin = -1;
  int iRead = -1;
  int iWrite =  -1;
  for (int i=0; i<4; i++) {
    iLightPin = iLightPins[i];
    iLEDPin = iLEDPins[i];
    iRead = analogRead(iLightPin);
    Serial.println(iLightPin + " - " + iRead);
    iWrite = iRead / 4;
    analogWrite(iLEDPin, iWrite);
  }
  delay(100);
}

MarkT

You are sharing ground and supply wiring between sensors and relays?

You mustn't do that, you'll superimpose IR voltage losses in the high current
wiring onto your sensor voltages.

Run separate sets of wiring to the sensors, direct from the Arduino, ditto for the
ground/power to the output relays.

Ideally the relays are separately powered so the only the ground has to be commoned,
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

tip2tail

Ah ha!

So I need to get a separate supply for the relays then!

Do you think that might explain the erratic nature of the LDR detection?

Would you be able to show me by modifying the Fritzing I attached to the original post?

Many thanks for helping so far!

Mark

tip2tail


You are sharing ground and supply wiring between sensors and relays?

You mustn't do that, you'll superimpose IR voltage losses in the high current
wiring onto your sensor voltages.

Run separate sets of wiring to the sensors, direct from the Arduino, ditto for the
ground/power to the output relays.

Ideally the relays are separately powered so the only the ground has to be commoned,


Hi I have attached a modified schematic.  Does this look better now?


Grumpy_Mike

#4
Aug 19, 2014, 12:17 am Last Edit: Aug 19, 2014, 12:23 am by Grumpy_Mike Reason: 1
Quote
Does this look better now?

Hard to tell. Stupidly large pictures are very difficult to see.
Have you read the how to use the forum sticky?

And don't go thinking that is a schematic, it is a physical layout diagram and normally next to useless for discussing circuits. But in your case when we are talking about poor physical layout it will do.

Edit
No your grounds are not connected together.

Paul__B


Hard to tell. Stupidly large pictures are very difficult to see.

Well, inconvenient and tedious, but - right click on enlarged version, "View image"

tip2tail

All,

I apologise for the large images.  I hadn't realised they were quite so large!

And just so you know - I DID read the how to use sticky, but as I said previously I hadn't realised the images were so large.

And just for you Grumpy_Mike, sorry for using the incorrect terminology.  I am a new user here, and new to working with Arduino/electronics in general.  But hey, now I'm suitably informed!

I will change some of the layout on my "physical layout diagram" and post it at lunch today.  The forum is proving very helpful, so I hope it continues to be!

Thanks,
Mark

Grumpy_Mike



Hard to tell. Stupidly large pictures are very difficult to see.

Well, inconvenient and tedious, but - right click on enlarged version, "View image"

Hard to right click on an iPad!

Paul__B


Hard to right click on an iPad!

I don't think iPads were intended for use by engineers.

Boardburner2

Dunno about that, keep mine next to pc , really useful for datasheet lookup.
Safari seems not to suffer from google or internet delays.

tip2tail


Quote
Does this look better now?

Edit
No your grounds are not connected together.


Right, I have amended the layout diagram and attached a new, suitibly resized, image.  Im pretty sure the grounds are connected now.

As for the power source for the LDRs, I show a 9v battery on here - but I will need something more permanent that I can plug in to the wall, any suggestions on what component(s) I should buy?

Thanks again for all your help! It IS appreciated!

Mark

Grumpy_Mike

Thanks for that, it is a whole lot easier to see.

You still have the same layout problem though.

The bit where the 9V battery negative lead joins all the resistors, and then is bridged to the negative line on the bread board is wrong. Take that point and do not connect it to the breadboard ground but connect it to the ground on the arduino next to the 5V line.

This stops the current from your relays making the "ground bounce" for your sensors.

Paul__B

Having said that about the grounds, why are the LDRs connected to Vcc?

Why not connect them to ground - back on the Arduino module - and use pull-ups to Vcc.  This makes for safer wiring when you have them connected at a distance, trivial difference in the code.  Also I believe (needs verification) you can still use the internal pull-ups on the Analog pins instead of 10k resistors, which they approximate.  Linearity of response will be different but hey - that is hardly of relevance when using LDRs!

Grumpy_Mike

Quote
Also I believe (needs verification) you can still use the internal pull-ups on the Analog pins instead of 10k resistors

Verified, yes you can.

However using the higher internal pull ups will make it more prone to picking up interference which is what the problem is here.

tip2tail


Having said that about the grounds, why are the LDRs connected to Vcc?

Why not connect them to ground - back on the Arduino module - and use pull-ups to Vcc.  This makes for safer wiring when you have them connected at a distance, trivial difference in the code.  Also I believe (needs verification) you can still use the internal pull-ups on the Analog pins instead of 10k resistors, which they approximate.  Linearity of response will be different but hey - that is hardly of relevance when using LDRs!



OK.... I'm a bit lost here! :(

What's the best way to proceed here?  I need this to be consistent.  It is going to be installed in my fathers Slot Car race track, where they currently have a working (Parallel port -> Win95) solution.

I am not sure what you mean Paul?  Mike, I get the bit you mentioned about the grounds, and I have amended as shown in the image attached.

I am looking to build this fully over the weekend, but will be wanting to have all the bits I need.  So if I need a new power supply (the 9v on here is just for demonstration) for the LDRs and advise on what I am needing to do would be appreciated! :)

Or is there a better way to connect these LDRs?

Thanks,
Mark

Go Up