Feedback on diagram - people counter

Go To Last Post
29 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In another thread on this forum, where people were helping me iron out some issues, I was asked to post the schematic once finished.

I'll gladly oblige, hoping for some general feedback on my - first ever - schematic and electronics project.

 

More specifically, I notice on the breadboard that, just sometimes:

  • one of the IR LEDs is blinking, whether LM393 is giving a LOW or HIGH signal, and disconnecting the HC-05 Bluetooth module seems to fix that.
  • the HC-05 Bluetooth module doesn't power ON.

 

It is unclear if this is because I have too many components on a small area, flimsy wiring, ... or a fault in the design.

 

The schematic and a picture of my breadboard set-up are attached.
You'll see an extra red and orange LED for testing; they can be ignored.

 

Please keep in mind that whilst using EAGLE I couldn't seem to find:

  • the TSOP31236 and settled for a different TSOP with the same amount of pins but in a different order (see name of nets).
  • how to add VCC and GND for the LM393.
  • a way to connect PIN34 of the HC-05.

 

EXPLANATION SET-UP

 

The ATTINY45 pulses the IR LEDs at 36kHz with intervals.

 

The ATTINY841 keeps track of the amount of people going in and out of a room, based on the LM393's output, in turn connected to the two TSOP receivers. Two beams are used to determine direction. 

 

Accross the doorway, there is a retroreflector to send back the IR light, so I only need one device with one set of batteries for both the transmitter and receiver.

 

EXPLANATION ATTINY841 PINS

 

  • If one or more people are in a room, pin 13 lights up a LED and pins 11 and 12 communicate with an app on my phone.
  • Pin 4 is a forced reset.
  • Pin 5 and 6 get a HIGH signal for a bream break from the LM393.
  • Pin 7 and 8 allow the user to check if the device is installed correctly by pressing a button. If the IR LEDs and the reflector are mounted at the same height, the install LED blinks.
  • Pins 9 and 10 allow the ATTINY841 to enter HC-05's AT mode to change the name and password of the device by using a HIGH/LOW sequence.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


You do know this site allows images to be posted inline? They don't have to be attachments. For the benefit of others:

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dont you think if you build a PCB it would much easier for you ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Absolutely. Hence my drawing of the schematic. I'm trying to get there!;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

U2 and U3 are not wired up properly.

 

 

Moe123 wrote:

Dont you think if you build a PCB it would much easier for you ?

 

I myself like breadboards for initial "experimentation" on low frequency stuff.  Nothing wrong with them as long as you are neat about it.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure? I wired it according to the TSOP31236 datasheet. On EAGLE I couldn't find the part, so I used a different TSOP with a different pin order (see original post).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

NilsDeschrijver wrote:
Are you sure? I

 

Last time I looked you do not connect your output to GND, GND to VCC and Vs to the input of your signal conditioning IC's.

 

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Jim is right. I know nothing about electronics but even to me this looks extremely suspicious:

 

 

The external net you call "GND" connects to "OUT" and the chip's own GND connects elsewhere??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post #6 explains that the OP has used a different device's TSOP definition in his schematic to match his actual device because Eagle did not have the required part in its libraries. Yes the labels appear incorrect, but the final pcb will be correct when loaded.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Exactly. And the labels are merely incorrect because I can't seem to modify them.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:
Yes the labels appear incorrect, but the final pcb will be correct when loaded.

 

Fair enough, but should the OP present this schematic to a total stranger not aware of this.........

 

EAGLE is a Pain in the ass to use, I know, but it's not impossibly difficult to make the symbol in the library editor and save it as a custom part.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Googling how to do it as we speak.

Thanks! 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Fair enough, but should the OP present this schematic to a total stranger not aware of this.........
Jim, the OP has very clearly stated this switcheroo in his first post.

Please keep in mind that whilst using EAGLE I couldn't seem to find:

  • the TSOP31236 and settled for a different TSOP with the same amount of pins but in a different order (see name of nets).

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some more points of interest:

 

ATmode should be connected directly to the AVR as it is a status monitoring pin.

 

Pin 1 of the HC-05 is not connected and should be connected to the AVR in case you need to jump between modes.  If you want to leave it in Data mode tie it to VCC through a 4k7 resistor.

 

Pins 4 and 5 should be connected directly yo the AVR not through resistor networks

 

The reset pin of the AVR should have a 10K pullup resistor  Don't rely on the internal one as false resets have happened.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

Jim, the OP has very clearly stated this switcheroo in his first post.

To us.  What If he hands it to his professor and 'forgets' to say anything?  Or to someone he's working with? 

 

Also, while I am being skootchy about details, COMM1 and COMM2 mean what?  I had to look it up[ on the datasheet for the HC-05.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fixed it! 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good Job!!

 

Now what about the other "stuff" I brought up(spit up)?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What are the lm393’s doing? Apart from inverting the signal, why the 4.75V reference?
Why the extra Tiny to generate the ir tx?

If you’re struggling with Eagle, try easypcb. I’ve done a couple of pcbs recently with it without muchdrama.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The gnd's are ridiculous...try to find the gnd symbol and use it.  gnd points DOWNWARD, not upward, not to the left, not to the right, downward, unless there is some extreme circumstance.

Vcc should also have an arrow/other symbol used

 

What is going on with TSOP1/2..????.. I was looking at the transistors and wondering what these signal are...only to find they are just some connectors about 6 inches away.  Now why didn't you draw the connectors right at the transistors so the connections can be readily seen to understand what is going on?  It might be excusable if the signals were buried deep in other circuits needing to go elsewhere, but this appears the only place they do go.

 

gnd should not be drawn going "in" to the comparators, your signal should go into the comparator & get divided by a resistor going to gnd.

 

You easily can move the pin locations on the AVR definition so your switches are more properly on the left,  heading into the left side of the AVR.   That makes it much more viewable.  

 

Make the page layout less tall and wider---it will draw up much cleaner!!

 

Don't forget to add hysterysis resistors on your comparators.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Wed. Sep 4, 2019 - 12:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your feedback, JIm.

I will attach a 10K pull-up resistor for the reset switch on pin 4 of the ATTINY841.

 

I'm entering and exiting AT mode via sketch by pulling pin 34 HIGH, VCC HIGH, executing the commands, then pin 34 LOW and rebooting the module.

Pin 1 doesn't seem to be needed for that.

HC-05 RX and pin 34 are connected through voltage dividers, because they can only handle 3.3V. 

 

All of this information, I got from here (see last section):

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The LM393 is doing nothing at all, you are right.

It was initially there to light up a LED, after comparing with a reference voltage.

Something the digitalRead() function already does, now that I connected it with an ATTINY.

 

I will remove it from the sketch and change the software to fit the non-inverted signal.

 

However, I am using another ATTINY45 to drive the IR LEDs because I need to pulse them.

According to the TSOP datasheet they need to be ON during x time and then off, for the receiver to function properly.

I could introduce it in the loop() of the ATTINY841 but the delay() function will hold up the code.

This will mess up my many if() statements that are needed to 'clean up the signal' (someone blocking the beam but not entering, to give one example).

It will likely also not play well with the attachInterrupt() functions I have.

 

Would you agree?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll clean it up, thank you.

 

I think forgetting the hysteresis resistors was probably the reason that the lights were chattering, when the HC-05 was drawing current.

I'm not sure, but after taking out the LM393 it has not happened again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

NilsDeschrijver wrote:
I'm entering and exiting AT mode via sketch by pulling pin 34 HIGH, VCC HIGH, executing the commands, then pin 34 LOW and rebooting the module.

 

I may be being a bit crabby, but the sequence is supposed to be VCC stable, THEN pull pin34 high.......

 

 

From my past experiences with optical turnstiles that have this exact sort of thing I think you might be making it a little too complicated.  Do you have a part number for the IR detectors?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Nope! You have timer hardware that can generate the carrier frequency for the ir leds without processor intervention. Then all you need todo is modulate at a slower rate. To read the ir detector inputs you can poll the inputs at a regular interval. A common timer isr at a regular rate of say 10ms would achieve both tasks with low overhead. Then your serial comms via usart uses an interrupt for circular buffer driven rx and tx. Your main code only has to pull a few levers and the job is done.
A person will interrupt the beam for probably 100’s of milliseconds. The AVR could calculate pi to a hundred places in that time! Maybe not, but the point is that a lot of useful work can be done - using delays is wasteful - count timer ticks and do other things in the meantime.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems that you are right.

The PDF file mentions this in the title of option 4.

 

Bit strange that it worked the other way around also.

 

I changed it accordingly:

  pinMode(AT_Mode, OUTPUT);
  pinMode(POWER_On, OUTPUT);
  
  digitalWrite(POWER_On, HIGH);

  delay(1000);
  
  digitalWrite(AT_Mode, HIGH);
  
  delay(1000);
  
  Serial.println("AT+NAME=PRODUCT");

  delay(250);

  Serial.println("AT+PSWD=\"7418\"");
  
  delay(250);
  
  digitalWrite(AT_Mode, LOW);

  delay(1000);
  
  digitalWrite(POWER_On, LOW);
  
  delay(1000);
  
  digitalWrite(POWER_On, HIGH);

This is the datasheet of my TSOP31236:  https://www.vishay.com/docs/82492/tsop312.pdf

Last Edited: Fri. Sep 6, 2019 - 02:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your comment went a bit over my head, I'm afraid.

However, I hope I got the gist of it.

 

Currently, it is:

void loop(){ //cycle = 1/36 = 28μs
  TCCR0A |=(1<<COM0A0); //burst on for 10+ cycles
  delayMicroseconds(500); 

  TCCR0A &=~(1<<COM0A1); //off for 14+ cycles
  delayMicroseconds(1000);
}

Would introducing this code for my ATTINY841, and removing the ATTINY45, do the trick?

It turns the IR LED one once, and when it reaches 500ms turns it off, until another 1000ms passes when it resets.

unsigned long prevMillis = 0;
unsigned long currMillis = 0;

int flagged = 0; 

void setup(){
  DDRB |= (1<<PA0); //Set pin PA0 as output

  TCNT0 = 0;
  TCCR0A = 0;
  TCCR0B = 0;

  TCCR0A |=(1<<COM0A0); //Timer in toggle mode Table 11-2 - PB0

  TCCR0A &=~(1<<COM0A1); 

  TCCR0A |=(1<<WGM01); //Start timer in CTC mode Table 11.5
  TCCR0B |= (1 << CS00); //Prescaler Table 11.6

  OCR0A = 12; //CTC compare value, 36kHz
}

void loop(){ //cycle = 1/36 = 28μs

  currMillis = millis();

  if (currMillis - prevMillis <= 500 && flagged == 0) {

    prevMillis = currMillis;
    flagged = 1; 

    TCCR0A |=(1<<COM0A0); //burst on for 10+ cycles
  }
  else if ((currMillis - prevMillis)/500 >= 1) {

    prevMillis = currMillis;
    TCCR0A &=~(1<<COM0A1); //off for 14+ cycles

  }
  else if ((currMillis - prevMillis)/500 >= 2) {

    prevMillis = 0;
    currMillis = 0;

  }
}

It gives an error on PA0 not being declared, but the datasheet says that is pin 13, the only pin I have left to use.

Last Edited: Fri. Sep 6, 2019 - 03:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You’re using DDRB for PA0?

Yes, you’ve got the gist of the concept. You might want to read up on ‘finite state machines’ moving forward.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I spent some more time reworking the code.

This should pulse the IR LEDs via physical pin 9 / 841 pin PA4 (the OCOA pin); 500ms on then 1000ms off.

Using that timer in this way, I think, also shouldn't affect delay() or millis() where used in the rest of the code which I trimmed.

 

#include <avr/io.h>

unsigned long prevMillis = 0;
unsigned long currMillis = 0;

int toggle = 0; 

void setup() {

  DDRA |= (1<<PA4);

  TCNT0 = 0;
  TCCR0A = 0;
  TCCR0B = 0;

  TCCR0A |=(1<<COM0A0); //Timer in toggle mode Table 11-2
  TCCR0A &=~(1<<COM0A1); 

  TCCR0A |=(1<<WGM01); //Start timer in CTC mode Table 11.5
  TCCR0B |= (1 << CS00); //Prescaler Table 11.6
  OCR0A = 12; //CTC compare value, 36kHz 

}

void loop() {

  currMillis = millis();

  if ((currMillis - prevMillis) >= 500 && toggle == 1) {

    prevMillis = currMillis;
    toggle = 0;
    TCCR0A &=~(1<<COM0A1); //off for 14+ cycles
  }
  else if (currMillis - prevMillis >= 1000) {

    prevMillis = currMillis;
    toggle = 1;
    TCCR0A |=(1<<COM0A0); //burst on for 10+ cycles
  }
}

This kind of code is not something I am very familiar with, so any feedback on where to improve or what to Google is welcome.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


NilsDeschrijver wrote:
I think, also shouldn't affect delay() or millis()
Just reading this:

 

https://www.robotshop.com/community/forum/t/arduino-101-timers-and-interrupts/13072

 

Specifically:

 

Last Edited: Tue. Sep 10, 2019 - 09:24 AM