Help with fixing a circuit!!! - Page 1
Forum section: electronics / beginners

author: lucyss
author_rank: Newbie
timestamp: February 08, 2023, 11:25:04 pm
content: 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 workThere 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 notHope you can help me

author: sarahMCML
author_rank: Regular Contributor
timestamp: February 09, 2023, 01:20:16 am
content: Your crystal should be connected to pins 9 and 10, not 9 and 23!

author: MarkS
author_rank: Unknown
timestamp: February 09, 2023, 01:28:44 am
content: 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.

author: sparkydog
author_rank: Regular Contributor
timestamp: February 09, 2023, 03:32:58 pm
content: 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?

author: BillyO
author_rank: Super Contributor
timestamp: February 09, 2023, 03:40:23 pm
content: Quote from: sparkydog on February 09, 2023, 03:32:58 pmIndeed. My guess is the OP is even more of a noob than you. We all were at one time.But maybe his intent is to do a single sided board and use jumpers for those few crossovers.

author: tooki
author_rank: Super Contributor
timestamp: February 09, 2023, 03:44:02 pm
content: Quote from: sarahMCML on February 09, 2023, 01:20:16 amPlus, 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.

author: TomKatt
author_rank: Frequent Contributor
timestamp: February 09, 2023, 04:39:48 pm
content: 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.

author: tooki
author_rank: Super Contributor
timestamp: February 09, 2023, 04:45:11 pm
content: Quote from: TomKatt on February 09, 2023, 04:39:48 pmThe protoboard version used an Arduino board, not the bare Atmega.Quote from: TomKatt on February 09, 2023, 04:39:48 pmIt certainly isn’t going to be running while one leg of the crystal is connected to entirely the wrong GPIO!

author: tooki
author_rank: Super Contributor
timestamp: February 09, 2023, 04:49:30 pm
content: Also, the reset pin is floating. I would give it a pull-up resistor to the 5V supply.

author: tooki
author_rank: Super Contributor
timestamp: February 09, 2023, 05:02:05 pm
content: What is the extra diode in series with the LED for?

author: Zero999
author_rank: Super Contributor
timestamp: February 09, 2023, 07:02:49 pm
content: Quote from: MarkS on February 09, 2023, 01:28:44 amMany 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.

author: floobydust
author_rank: Super Contributor
timestamp: February 09, 2023, 07:11:20 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: February 09, 2023, 07:48:11 pm
content: Quote from: floobydust on February 09, 2023, 07:11:20 pmThere 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.

author: lucyss
author_rank: Newbie
timestamp: February 09, 2023, 08:53:20 pm
content: 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.

author: floobydust
author_rank: Super Contributor
timestamp: February 09, 2023, 09:01:31 pm
content: 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 butneed a shieldMystery buzzers examplehttps://www.aliexpress.com/item/32914327679.htmlorhttps://www.aliexpress.com/item/1005004005677478.htmlhave terrible descriptions so noobs can get confused.Also here you can see them:CUI Devices lineupI 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 hereHow to Increase the Audio Output of a Piezoelectric Transducer Buzzer

author: Zero999
author_rank: Super Contributor
timestamp: February 09, 2023, 09:50:59 pm
content: Quote from: floobydust on February 09, 2023, 09:01:31 pmAnd 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.pdfhttps://www.sancobuzzer.com/aboutus/26534.htmlQuoteThat'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.Quote from: lucyss on February 09, 2023, 08:53:20 pmIn 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.

author: tooki
author_rank: Super Contributor
timestamp: February 09, 2023, 10:54:46 pm
content: Quote from: lucyss on February 09, 2023, 08:53:20 pmThat 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.)Quote from: lucyss on February 09, 2023, 08:53:20 pmWell, 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 (pinand 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.)Quote from: lucyss on February 09, 2023, 08:53:20 pmUsing 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.Seehttp://ww1.microchip.com/downloads/en/appnotes/atmel-2521-avr-hardware-design-considerations_applicationnote_avr042.pdfAs 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?)

author: lucyss
author_rank: Newbie
timestamp: February 12, 2023, 05:38:05 pm
content: I didn't see the new reply and already changed and printer a new PCB. Although it still doesn't workEdit: 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.But now it works just fine.Thanks for the help everyone, probably couldn't have done it without y'all.