Author Topic: Help with fixing a circuit!!!  (Read 1476 times)

0 Members and 1 Guest are viewing this topic.

Offline lucyssTopic starter

  • Newbie
  • Posts: 3
  • Country: ar
Help with fixing a circuit!!!
« on: February 08, 2023, 11:25:04 pm »
Hi everyone, hope you have a good day.
I tried to make a motion alarm in Tinkercad using a PIR sensor with an atMEGA328P-PU, a buzzer, a led and a button to stop the alarm. Thing is, even though the circuit works in the Tinkercad simulation also works when using the real Arduino with a protoboard, when I put it all in the board I made it just didn't work :-// 
There doesn't seem to be any physical mistake with the board and the components are connected correctly, the code worked with the Arduino so I supposed it also works with the coded atMEGA, so I just can't understand why it's doing nothing.
I attached the Tinkercad schematic, the KiCad one, the code and also the PCB because why not ^-^
Hope you can help me :-BROKE
 

Offline sarahMCML

  • Regular Contributor
  • *
  • Posts: 71
  • Country: gb
Re: Help with fixing a circuit!!!
« Reply #1 on: February 09, 2023, 01:20:16 am »
Your crystal should be connected to pins 9 and 10, not 9 and 23!
 
The following users thanked this post: MarkS

Offline MarkS

  • Supporter
  • ****
  • Posts: 825
  • Country: us
Re: Help with fixing a circuit!!!
« Reply #2 on: February 09, 2023, 01:28:44 am »
Apart from the crystal routing issue, it's generally a good idea to drive a buzzer via a transistor. The MCU may not be able to drive it directly and there's the very real possibility of reverse current damaging the chip.
 

Offline sparkydog

  • Regular Contributor
  • *
  • Posts: 234
  • Country: us
Re: Help with fixing a circuit!!!
« Reply #3 on: February 09, 2023, 03:32:58 pm »
If y'all will excuse a n00b question... why use vias here? Why not just run a couple traces entirely on the back side of the board?
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1399
  • Country: ca
Re: Help with fixing a circuit!!!
« Reply #4 on: February 09, 2023, 03:40:23 pm »
If y'all will excuse a n00b question... why use vias here? Why not just run a couple traces entirely on the back side of the board?
Indeed.  My guess is the OP is even more of a noob than you.  We all were at one time. :-DD

But maybe his intent is to do a single sided board and use jumpers for those few crossovers. :-//
« Last Edit: February 09, 2023, 03:41:59 pm by BillyO »
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11561
  • Country: ch
Re: Help with fixing a circuit!!!
« Reply #5 on: February 09, 2023, 03:44:02 pm »
Your crystal should be connected to pins 9 and 10, not 9 and 23!
Plus, the traces for the crystal and load caps should be as short as possible, not snaking around the board because the MCU is unnecessarily close to the edge of the board.
 

Offline TomKatt

  • Frequent Contributor
  • **
  • Posts: 327
  • Country: us
Re: Help with fixing a circuit!!!
« Reply #6 on: February 09, 2023, 04:39:48 pm »
If anything, the protoboard is going to add capacitance/inductance to the circuit.  Is it possible the protoboard is allowing the crystal to oscillate but the pcb isn't?

Can you tell if the AVR is running at all?  In cases like this, I code a heartbeat output to flash an led so that at least I know the processor is running - helps eliminate a variable to focus on either the processor or the peripherals.
Several Species of Small Furry Animals Gathered Together in a Cave and Grooving with a PIC
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11561
  • Country: ch
Re: Help with fixing a circuit!!!
« Reply #7 on: February 09, 2023, 04:45:11 pm »
If anything, the protoboard is going to add capacitance/inductance to the circuit.  Is it possible the protoboard is allowing the crystal to oscillate but the pcb isn't?
The protoboard version used an Arduino board, not the bare Atmega.

Can you tell if the AVR is running at all?  In cases like this, I code a heartbeat output to flash an led so that at least I know the processor is running - helps eliminate a variable to focus on either the processor or the peripherals.
It certainly isn’t going to be running while one leg of the crystal is connected to entirely the wrong GPIO! ;)
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11561
  • Country: ch
Re: Help with fixing a circuit!!!
« Reply #8 on: February 09, 2023, 04:49:30 pm »
Also, the reset pin is floating. I would give it a pull-up resistor to the 5V supply.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11561
  • Country: ch
Re: Help with fixing a circuit!!!
« Reply #9 on: February 09, 2023, 05:02:05 pm »
What is the extra diode in series with the LED for?
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19536
  • Country: gb
  • 0999
Re: Help with fixing a circuit!!!
« Reply #10 on: February 09, 2023, 07:02:49 pm »
Apart from the crystal routing issue, it's generally a good idea to drive a buzzer via a transistor. The MCU may not be able to drive it directly and there's the very real possibility of reverse current damaging the chip.
Many small piezo buzzers have a low current requirement and can be driven directly from an MCU output, with no problem.

How could reverse current damage the chip?

It's true it could be damaged if the buzzer's current draw exceeds the output port's rating, but reverse current shouldn't happen and even if it did, it wouldn't be a problem, since the port can pass current in both directions.

« Last Edit: February 09, 2023, 07:04:22 pm by Zero999 »
 
The following users thanked this post: MarkS

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7014
  • Country: ca
Re: Help with fixing a circuit!!!
« Reply #11 on: February 09, 2023, 07:11:20 pm »
There are inductive buzzers as well as piezo buzzers. Some piezo buzzers incorporate an inductor (with their internal one-transistor oscillator) for higher SPL.
OP should confirm what they have. Put a small back-EMF diode across it.
That Brymen has a problem with their buzzer creating EMI and had to shield it- something is used that is electrically noisy.
 
The following users thanked this post: MarkS

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19536
  • Country: gb
  • 0999
Re: Help with fixing a circuit!!!
« Reply #12 on: February 09, 2023, 07:48:11 pm »
There are inductive buzzers as well as piezo buzzers. Some piezo buzzers incorporate an inductor (with their internal one-transistor oscillator) for higher SPL.
OP should confirm what they have. Put a small back-EMF diode across it.
That Brymen has a problem with their buzzer creating EMI and had to shield it- something is used that is electrically noisy.
There is no need for a back-EMF diode.

They don't make small DC inductive buzzers any more. Magnetic buzzers have a built-in blocking oscillator, which drives the coil and the piezo type with a built-in inductor channel the voltage spikes to the piezo transducer, not the power supply and the MCU has a pair of ESD protection diodes, which will clamp and spikes due to parasitic inductances in the wiring.
 
The following users thanked this post: MarkS

Offline lucyssTopic starter

  • Newbie
  • Posts: 3
  • Country: ar
Re: Help with fixing a circuit!!!
« Reply #13 on: February 09, 2023, 08:53:20 pm »
Alright, I'm using a single sided board for skipped reasons, that's why I used vias.
I changed the crystal pin to 9 and 10 and still didn't work, I didn't really check if the AVR is alive though.
Also I heard the reset doesn't necessarily need not to be floating. ??? But even if it did, I don't see how it not being connected would make the entire circuit die.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7014
  • Country: ca
Re: Help with fixing a circuit!!!
« Reply #14 on: February 09, 2023, 09:01:31 pm »
OP must have a decoupling capacitor like 0.1uF across power for the '328. Where is your capacitor between +5V and GND?
Why don't your splurge and add an LED+resistor to a spare MCU output to blink and show signs of life.

Magnetic buzzers are alive and well unfortunately, and can look just like piezo ones, and Brymen seems OK using them but need a shield  :palm:
Mystery buzzers example https://www.aliexpress.com/item/32914327679.html or https://www.aliexpress.com/item/1005004005677478.html have terrible descriptions so noobs can get confused.
Also here you can see them: CUI Devices lineup

I see at least 4 different types out in the wild and we don't know which type OP has. But it could be part of the problem if silent.

Driving a piezo transducer with a transistor is not ideal, you need a way to discharge its capacitance which is typically adding a (reset) parallel resistor, or push-pull drive or even better a bridge if you want high volume. A bit more here How to Increase the Audio Output of a Piezoelectric Transducer Buzzer

 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19536
  • Country: gb
  • 0999
Re: Help with fixing a circuit!!!
« Reply #15 on: February 09, 2023, 09:50:59 pm »
OP must have a decoupling capacitor like 0.1uF across power for the '328. Where is your capacitor between +5V and GND?
Why don't your splurge and add an LED+resistor to a spare MCU output to blink and show signs of life.

Magnetic buzzers are alive and well unfortunately, and can look just like piezo ones,
And they use a blocking oscillator, except for the metal can type which aren't very common nowadays.

https://patentimages.storage.googleapis.com/a1/71/c7/8fd46e3faba21d/US3950744.pdf
https://www.sancobuzzer.com/aboutus/26534.html

Quote
and Brymen seems OK using them but need a shield  :palm:
Mystery buzzers example https://www.aliexpress.com/item/32914327679.html or https://www.aliexpress.com/item/1005004005677478.html have terrible descriptions so noobs can get confused.
Also here you can see them: CUI Devices lineup

I see at least 4 different types out in the wild and we don't know which type OP has. But it could be part of the problem if silent.

Driving a piezo transducer with a transistor is not ideal, you need a way to discharge its capacitance which is typically adding a (reset) parallel resistor, or push-pull drive or even better a bridge if you want high volume. A bit more here How to Increase the Audio Output of a Piezoelectric Transducer Buzzer
That's a point. It's possible the original poster is driving it like a DC buzzer, when it's really a transducer, which requires a square wave. Adding a 10mH inductor across a piezo transducer, when driving it with a transistor, is a good way to boost the voltage and increase the volume.
Alright, I'm using a single sided board for skipped reasons, that's why I used vias.
I changed the crystal pin to 9 and 10 and still didn't work, I didn't really check if the AVR is alive though.
Also I heard the reset doesn't necessarily need not to be floating. ??? But even if it did, I don't see how it not being connected would make the entire circuit die.
In what respect does it just not work?

Have you tried loading a blinking LED program?

If the buzzer doesn't work, have you tested it by connecting it across the power supply? If not it might require a square wave to work.

It's generally a bad idea to leave pins floating. They should be connected to either rail, either via internal pull-up resistors, or an external connection to +V or 0V. If you really want to play it safe, use a resistor rather than a wire, so it doesn't get damaged if you accidentally set the pin to an output with the opposite level. The resistor can be a high value, say 100k. It doesn't matter.
« Last Edit: February 09, 2023, 10:20:28 pm by Zero999 »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11561
  • Country: ch
Re: Help with fixing a circuit!!!
« Reply #16 on: February 09, 2023, 10:54:46 pm »
Alright, I'm using a single sided board for skipped reasons, that's why I used vias.
That is valid. But you could simplify it a lot by routing things differently. For example, rather than making two traces jump under another one, just leave the two on top and make the one jump underneath. (Like how, near the battery connector, GND and the now unneeded trace to pin 23 both dive below 5V, rather than 5V diving beneath them.)

I changed the crystal pin to 9 and 10 and still didn't work, I didn't really check if the AVR is alive though.
Well, you should check for life to be sure!

If it’s not running, try cutting the traces from C1 to Y1 and C1 to C2, then connect Y1 directly to pins 9 and 10 (as in, solder the leads directly to the IC socket pins on the bottom), and connect a new C2 between ground (pin 8) and pin 10 using the shortest wires possible. Don’t leave the unused segments of track connected. See the attached image “modifications to current PCB”; red is where to cut traces and remove components. Blue is where to add them. (In the image “layout suggestion for next PCB”, I also show how I would route some of the traces to simplify it.)

Also I heard the reset doesn't necessarily need not to be floating. ??? But even if it did, I don't see how it not being connected would make the entire circuit die.
Using an external pull-up is not mandatory, but recommended. Given that a 10k resistor costs basically nothing and increases the reliability of the circuit, I think it’s dumb not to use it.

See http://ww1.microchip.com/downloads/en/appnotes/atmel-2521-avr-hardware-design-considerations_applicationnote_avr042.pdf

As for how it could make “the entire circuit die”, well, if the MCU is held in reset, how would the circuit be able to do anything at all? (What happens on your Arduino if you keep the reset button held down?)
 

Offline lucyssTopic starter

  • Newbie
  • Posts: 3
  • Country: ar
Re: Help with fixing a circuit!!!
« Reply #17 on: February 12, 2023, 05:38:05 pm »
I didn't see the new reply and already changed and printer a new PCB. Although it still doesn't work  :palm:
Edit: It works now, I am so dumb that I straight up completely forgot to put some resistors and mixed others and just did a weird mess |O .But now it works just fine.
Thanks for the help everyone, probably couldn't have done it without y'all.  :-+  :clap:
« Last Edit: February 12, 2023, 10:05:06 pm by lucyss »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf