Hi, I've been working on a count to track cars entering a carpark, and I'm having some monir trouble.

What I need, is for ir beam 1 to be triggered, then IR beam 2 to be triggered, whilst the first is still active, before I get a counter+1 event.and the opposite for exiting the carpark, IR 2, then IR 1 whilst the first is active, before I get a counter-1 event.i have 3 LEDs to light one to replicate IR 1, one to replicate IR2 and one to indicate that the counter has changed.

I thought I had it figured out, as the sketch compiled, but I'm not getting any results or not what I am expecting,anyway.Sorry if its a bit messy, I have been chopping and changing it to try and get it to work. it was a lot neater than this to begin with Eventually I will be relaying the output to a web page, but first I need to get the data acquisition right.

There is no point testing IRTrigger1 or IRTrigger2 as they are both defined as constants.

You should be testing IRState1 and IRState2.

You don't seem to have any code to figure out which IR was triggered first.

I think your logic needs to be something like this

wait until both sensors are off ... then if sensor1 is on and sensor 2 is off there is an incoming car but don't count it until sensor 2 goes on if sensor2 is on and sensor 1 is off there is an outgoing car but don't count it until sensor 1 goes on

Hi again, I have sorted the Logic part of the code, and cleaned it up a bit, but now that I have inserted the websever side of it, I am getting weird results(web server worked by itself, but as a function, not so much

what i get in the serial monitor is:"New clientGclient Disconnected"

Now I cannot for the life of me, figure out where this "G" is coming from, nor why I am getting no "Digital Input pin is: x" data on the web page.

I realise it is probably not syntax that is the issue, as it compiles. I have been staring at theis for hours, and just can't see it.

Simple trap to fall into. I did something similar with a little project. I wanted to toggle a light for diagnostics. I happened to have some small 0.1" lead spacing 5V LEDs (integrated resistor for running directly on 5V). Since there is a GND connection right next to D13, I dropped it in and added code to toggle that LED for my diagnostics. Scratched my head for a bit wondering why the LED was constantly on at a low level... (I couldn't easily see the on-board LED because I had the Ethernet shield plugged in...) Felt kinda silly after I discovered the error. What I ended up doing (so I could keep using the same LED plugged directly into the shield pass-through header) was putting it between A0 and A1. Set A0 as digital output LOW, and toggled A1 digitally as my diagnostics. That worked.

But to the OP... By your description, it looks much like you are using the two IR beams just like how a rotary encoder works. (Only you are trying to ignore single IR beam trips because that would be a person, not a car...) Check some of the rotary encoder examples for counting forward and backwards and get your code working counting cars in and out. Then add the code to ignore isolated single beam interruptions.

I've moved the diag LED to pin 10, or do you suggest moving it to analog pins?

it hasn't made any difference at D10

, still can't see where this "G" is coming from in the serial monitor.

and nothing shows on the web page, just a blank screenthe UNO derivative I'm using is the EtherTen, from freetronics

RegardsJason

Check the documentation for that board. I know when using my UNO r3 D10 is tied up when doing anything with ISP, so often boards use it as a CS. It might be the same with your board, I don't know but likely. In my "solution" I chose the analog pins just because they were available and I didn't have any wires to that side of my Arduino so the LED wasn't occluded by anything. Mostly an arbitrary choice. You can treat the analog pins like digital pins though. Reference them with A0-A5 when using the digital functions. (You could reference them as 14-19. Best to use the "A" numbers to make it easier to remember what they are called because the board silkscreen likely doesn't have the 14-19 indicators on it.)

thanks people!, I now have this working(as far as code is concerned)now, I have a hardware issue

ok, i have a tactile switch with 2k2, pulldown resistor attached to D2, and another wired the same on D3,there is a yellow led indicator attached to pin D5, red to pin D7, and green to D9.now when i press switch 1, pin 5 lights the yellow LEDwhen i press switch two, pin 7 lights the red LEDwhen i hold one switch, and press the other, the code deciphers which was the first to trigger, modifies the counter(for total entries/exits) and pin 9 lights the green LEDthese result are mirrored to the web server which can be viewed from a browser. until......

THE PROBLEMwhen i press both buttons at once, the ethernet portion of the board drops out.code is as follows:::

client.println("<br />"); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply // if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connnection: close"); client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); // add a meta refresh tag, so the browser pulls again every 5 seconds: client.println("<meta http-equiv=\"refresh\" content=\"5\">"); // output the value of each Digital input pin

Am I correct to assume that the tactile switches are a substitute for your IR sensors? If not what are they for?

I haven't used the ethernet shield but I wonder should you be creating a new instance of client in every iteration of the loop? I would be inclined to create the instance once in setup.

Am I correct to think that there is no problem when both switches are pressed provided one is pressed first and the problem only arises if both are pressed at the same time? Have you tried pressing them one after the other but with as short an interval as possible?

If your switches are each drawing 5v / 2200ohms = 2.3 mA then I can't see how they are overloading the 5v supply unless they are the last straw and the root of the problem is elsewhere.

Is it possible that when you press the two switches you move something else that has a poor connection?

Am I correct to assume that the tactile switches are a substitute for your IR sensors?

Correct

Quote

I haven't used the ethernet shield but I wonder should you be creating a new instance of client in every iteration of the loop? I would be inclined to create the instance once in setup.

hahaha, God I'm daft sometimes.

Quote

Am I correct to think that there is no problem when both switches are pressed provided one is pressed first and the problem only arises if both are pressed at the same time? Have you tried pressing them one after the other but with as short an interval as possible?

No, as soon as the second one is pressed(regardless of which is pressed first) it dies/freezes/becomes unresponsive/etc.

Quote

Is it possible that when you press the two switches you move something else that has a poor connection?

I'm, beginning to think so, as after a PC reboot, an Arduino reload, a board reset, and trying my best not to scream like a madman and rip it all to pieces then set it on fire.....it's stopped doing it.

Now, i just need to add time stamping and SD card save, and i think its about ready!