Atmega32 delay function doubles it value seldom,probably due to noise

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

Dear all,
I have a code that control ice maker machine. Most of the time it works fine and randomly(I think I noticed faut is triggered by defrost solenoid operation) it just double all of delays:- the freezing , defrost and hinge movement but still it keeps the sequence of operation. In another project I faced noise problem and guys told me to add snubber and it solved the problem. But here I want to exercise defensive programming. I want to know how delay doubled due to noise or discussion of noise effect on the code. To solve the problem I creat safeDelay function which takes three identical arguments and using two timer and loop delay to make accurate delay but it doesn't work. I have attached the codes please help

Attachment(s): 

Last Edited: Wed. Feb 19, 2020 - 05:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Tinsae wrote:

But here I want to exercise defensive programming.

 

Wrong approach. You need to get your hardware right before you start thinking about the software. A hardware design with 'issues' will come back and haunt you days/weeks/months/years down the line.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Tinsae wrote:
I think I noticed fault is triggered by defrost solenoid operation

Ha!

 

I once had a project where 50 or so coffee machines were installed across the country, and we were getting "random" failures after a few weeks operation.

 

It eventually turned out that there was a clean cycle run every week or so, and that could cause some "glitch" which messed stuff up.

 

Tinsae wrote:
I want to know how delay doubled due to noise or

Sounds like the delay did something which caused the code to run at half speed? Or maybe just the timers to run at half speed.

 

eg, I think it's possible for a crystal to get "knocked" into working on a different harmonic ...

 

Tinsae wrote:
noise effect on the code

It's unlikely that noise affects the code - it's a hardware thing!

 

But it could corrupt memory, or corrupt comms, or give false readings to the code, or false triggering of interrupts, or ...

 

Tinsae wrote:
I creat safeDelay function which takes three identical arguments and using two timer and loop delay

You need to beware of "single points of failure"

 

eg, if the 2 timers and CPU clock share a common source, then any error on that source will cause them all to change together - so your "safeDelay" function will never notice!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tinsae wrote:
Most of the time it works fine and randomly

Can you post a picture of your board, or your a PDF of your CAD drawing?

Some one may spot where it can be improved.

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Welcome to the Forum.

 

Is your board a retro-fit for a commercial ice maker, or a new design?

 

Likely the solenoid is either generating a back-EMF spike, that can be coupled into the circuit either by RF or directly through its wiring; or it is putting a high current demand on a weak power supply, and the power supply voltage is dipping low when the solenoid fires.

 

So it would be reasonable to put a snubber on the solenoid, and put an O'scope on the power bus and on the solenoid wiring and see what they look like.

 

Know that the water control valve and any other electromechanical components can also generate problems as above and may also need attention.

 

JC 

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

Dear Brian, I believe putting snubber across the coil will solve the problem because I did it before for another project and believe me I will put snubber. But I want to know before putting the snubber what is going on, like the suggested hypothesis-cpu running at half or something else because after the hardware I believe it is good to make the code also robust so I want to learn defensive programing

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

Tinsae wrote:
I want to know before putting the snubber what is going on

Then instrument your system so that you can see what's going on!

 

Set up a few examples with "non-snubbered" coils and watch what's happening

 

If you can't then get them to fail, that suggests that you haven't really found the root cause yet ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
Likely the solenoid is either generating a back-EMF spike, that can be coupled into the circuit either by RF or directly through its wiring; or it is putting a high current demand on a weak power supply, and the power supply voltage is dipping low when the solenoid fires.

Indeed.

 

All of which should be fairly easy to see on an oscilloscope scope ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes awneil, I am trying to find the common source of error, like cpu running at half speed. Btw I am using the internal clock not external crystal.

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

I have attached the pic

Attachment(s): 

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

Thank you DocJC, both my board and ice maker are new design.

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

So that's very much a prototype, then?

 

Not a PCB; no ground planes, etc, etc.

 

Such a construction would be expected to be rather susceptible to interference!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Feb 11, 2020 - 08:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Can you confirm the following...

 

 

I *think* that the blue highlighted wiring is your 0V net, and the red is +5V.

 

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Please also post the full schematic

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes you are correct

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


Consider the following...

 

 

Point A is where your power enters, point D is where your relays return their current to the 0V rail, and point C is the 0V reference to your micro.

 

Now we need to remember that in the real world wires, PCB tracks, solder joints, and even chip pins have a resistance.

 

So, what happens when one or more of your relays operates? A current will flow between points A and D and because there is resistance between those points a voltage will develop between those points.

 

Bonus question...what happens to the voltage at point C?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Unfortunately, that board has ‘death’ written all over it. Don’t ever have mains voltages on dot board like that. Scrap that board for your own safety and rethink how you can build your prototype in a much safer form. Use relays like the omron g2r series so it is easy to maintain adequate separation between mains and elv circuits. Remove the copper dots where there is mains present.

Last Edited: Tue. Feb 11, 2020 - 11:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all, my trouble is not why my circuit affected by noise since it has no ground plane, opto isolator and etc. But let me take this as an opportunity such that it is prone to noise and try as much as possible with the code. For example I included a code that put the current position to memory which in case of reset the mcu will continue and also included reduendent reading. These two codes saved me from two noise related issues. Now came delay doubling is it possible to know how and why it doubles to make the case more easy once delay double ocurs it continues untill reset it doubles every following delays

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

I understand that hardware comes first but what I am doing is make the harware prone to noise and try as much possible to make code defensive and come back to harware as recommended. If I make the hardware bulletproof then how could I make a test for defensive code?

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

Tinsae wrote:
is it possible to know how and why it doubles

As previously noted, you are going to have to investigate that on your board.

 

It is almost certainly not any "normal" operating mode - but some result of all the noise & interference that you are bound to be getting on such a board.

 

For a start, as suggested back in #8, have you used an oscilloscope to actually see the effects that Brian described?

 

Any system is going to do weird things if you abuse it sufficiently - there has to be a tradeoff between getting the design right so that the abuse can't happen, and just tolerating the abuse ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've built a few boards like that over the years...

 

Please be very careful having 220V Mains on your board along with the other circuitry.

 

Put some hot glue over all of the 220 V Mains connections to help keep you from accidentally touching them.

 

Your Mega32 NEEDS two by-pass capacitors for reliable operation.

These are 0.1 uF caps.

One goes from Vcc to Ground.

One goes from AVcc to Ground.

Put these as close to the pins on the micro as you can get them.

 

The large electrolytic caps do NOT serve the same purpose as the by-pass caps.

 

Next:

You need to add the snubber circuits to all of the relays, water control valves, and perhaps to the heater coil.

You need them for reliable operation of the circuit, or the reverse EMF spikes can damage the circuitry.

Adding them will also improve other aspects of your circuit.

 

You can work on making your software reliable and fault tolerant, but start with good hardware.

Otherwise you are wasting your time.

 

You obviously do not want a fault where the water valve turns on and stays on, flooding the building.

You obviously do not want a fault where the heater coil turns on and stays on, overheating the system, and causing a fire.

There are likely other faults that you will not want, also, and you need to make a list of all of them.

 

For your fault protection you can only do so much with software within the micro that is controlling the device.

 

You might well consider adding a second micro as a fault detection and mitigation supervisor micro.

It can monitor the state of the system and watch for any states that should never occur, and if they do occur it can shut off power to the system.

It might time how long the water valve is on and know that it should only ever be on for X minutes.

If it is on for ___ minutes longer then there is a problem and it turns on an alarm and resets the system.

It might have a thermistor to measure the temperature of the ice maker frame.

If it ever reaches > X degrees, then the system is overheating...

 

Obviously, adding a supervisor circuit adds additional complexity, and code, and possible failure points to the project.

So engineering is based on trade-offs.

 

Your next steps should be:

1)  Add the by-pass caps to the micro.

2)  Add the snubber circuits, you need them for a reliable board that will work long term without a hardware failure.

3)  Get an O'scope to look at the power rails, and the signal lines in/out of the micro, as the circuit operates.

4)  Write a test program that simulates normal operation, but much faster, (i.e. not waiting for ice to be made, or the defroster to work, etc.)

It should cycle through turning everything on and off every few seconds, so you can see hardware induced faults much faster, and so you can watch the circuitry with your O'scope for many, many operations, (turning no/off relays, valves, heaters, etc.).

5)  Post a schematic diagram of your circuit.

 

JC  

 

 

 

 

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

What's going on here?  Is that wire supposed to connect to the copper?  If yes, it should be soldered otherwise you may have an intermittent connection.  If no, you should route it through a different hole.

 

Letting the smoke out since 1978

 

 

 

 

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

Sorry Tinsae if I'm sounding harsh - unfortunately you've broken many rules of electrical safety and embedded software. We all make mistakes but we should learn from them.

 

1. Understand creepage/clearance distance between 220VAC and elv circuits This serves two purposes - electrical safety and coupling of transients.

2. Understand wire 'ampacity' and fusing. Don't feed 10 Amps into a circuit with wiring that can only cope with 2Amps - fire risk.

3. Your relays probably aren't safety rated for 220VAC and most likely not mounted on your dot board.

 

Now we get onto your code.

You've got delays, timers, interrupts and many flags and values sprinkled through your code. You call functions with shared variable from timer isrs with no atomic protection. Basically it is near impossible to predict the output in all conditions.

How do we fix that?

 

1. You only need one timer - usually 10ms. All your timing is derived from that.

2. The usual control loop consists of:

  read the inputs

 validate the inputs

 process the control logic

 update the outputs

 

this control loop runs every 10ms.

 

Technically, you don't even need an interrupt for the timer - you can poll the compare flag. Use the CTC mode for the timer.

 

 

Here's an example of how you might implement your alarm flashing:


#define TICK_TIME 10        //in milliseconds
#define ALARM_TIME (1000 / TICK_TIME)   //1 second on,1 second off
bool alarmFlash(bool active)
{
    static uint16_t alarmTimer = 0;
    static bool output = false;
    
    if (active == true)
        {
            if (alarmTimer)
                {
                    alarmTimer--;
                }
            else
                {
                    alarmTimer = ALARM_TIME;    //load up the timer
                    output != output;           //flip the output state
                }
        }
    else        //turn alarm off
        {
            output = false;
            alarmTimer = 0;
        }
    
    return output;
}

Note how it does not manipulate the port bit directly - this means you can test this code on your PC or online using online C compiler tools. You should be able to write your whole control code in a similar way so you can simulate it. Also note how the function does not rely on anything outside of itself.

 

If you have a zillion flags and conditionla tests, this suggests you need to look at using a 'finite state machine' - you sort of have this already but it could be implemented better.

 

with a little bit of thought and some work you should be able to restructure your code so it is a lot simpler and easier to understand. When something goes wrong it will be easier to pinpoint the problem.

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

The main is electrically isolated using relay. What kind of safety danger can come beside malfunction?

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

Unfortunately I don't have oscilloscope and in cercuit debugger. The only trouble shooting I use is flashing led when the code enter somewhere.

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

Well, if you want to do a thorough analysis of this - those are the tools you're going to need.

 

Otherwise, as already suggested, just design the hardware properly so that you don't have this stuff to contend with!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Inadequate clearance. The mains is full of transients which far exceed 220vac. Given the right conditions a spark will form and transfer dangerous voltages to your extra low voltage circuitry, potentially electrocuting someone or form an arc and cause a fire. If you look at any properley designed board using that style of relay, there will be slots in the pcb to ensure adequate clearance and creepage distances.

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

Okay thank you I understood.

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

Kartman wrote:
Your relays probably aren't safety rated for 220VAC and most likely not mounted on your dot board.

The relay spec is for 220vac why it is not safe? And I dont get you what you mean by not mounted on your board. I have also issue on english language not only c language lol. Execuse me if I dont understand some sentence.

Kartman wrote:
You call functions with shared variable from timer isrs with no atomic protection.

I made every variables that is used in interrupt volatile. Is this acceptable?

Kartman wrote:
You only need one timer

Initially I was using one timer untill the problem appear. Then to correct the problem I used more timers assuming if one failed the other two may not. But as noted above the root cause is where all timers share that is probably the cpu clock.
Kartman wrote:
this means you can test this code on your PC

The codes run many cycle before it doubles the timer. If I test it, it run without error because no noise here or is there any means to inject noise in the simulation?

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

The relay spec is only one part of the puzzle. Different countries have different laws and requirements. What is acceptable in China may not be acceptable in Korea, USA, Europe etc.

Once you put that relay (or any other part) onto your board you are affecting the part's operation. Because your board does not have adequate insulation, you have compromised the relay specifications - the relay is no longer good for use at 220V.

 

 

'volatile' only forces the compiler to read/write the variable - it does not ensure atomicity. Remember - the timer isr can hit anywhere in your code. Whilst I have not looked extensively at your code, I see enough potential for problems.

 

You cannot simulate noise problems on a PC. You can simulate noise problems with with the actual hardware and instruments that generate ESD and fast transients.

 

Noise causes random faults with your AVR. As was suggested in #2, solve your hardware problems. There's a number of problems with your code. Get the basics correct first, then move forward. Trying to find the problems(s) in your existing code is a waste of time.

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

A few questions...

 

1) You appear to feed your incoming 5V to a pair of electrolytic capacitors and then to pin 10 (VCC) of the M32 via a diode?

 

2) You don't appear to have a connection to pin 31 (GND)?

 

I *could* sit here and try to draw a schematic of your board but that's really your job if you want help.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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


On the subject of safety...

 

 

I think that the yellow highlight is your 12V rail and the red your mains.

 

There's not much gap between the two when you take into account the islands of copper.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

The thing is a death trap........

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


To give the OP some idea of what a safe design looks like, here is a board I did a coupe of months ago. It too has mains relays on it. I've measured the clearance from the pads at mains potential to my 0V ground plane...

 

 

...and here's the whole of one side of the board. Note the 0V ground plane to keep ground currents where they should be.

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Dear Brian Fairchild and all I am so sorry and ashamed of myself for being late for my owm help. But I have reason 1. Me and my device are not fast on social media eg I was not able to use TAG and most importantly weak internet netwok. Anyways I have attached hand made schematics I dont have cad or pdf

Attachment(s): 

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

Answer for question#
1. The first big cap is intended for stablizing voltage dip that will be create by heavy dc hinge motor. The second 0.1uf is for filtering. The diode is to make sure the voltage is below 5v since 5v is the max for the mcu.
2. May be it is not vissible but the gnd of the mcu is connected to the supply and caps

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

So the copper dot spacing is not enough to separate main from low voltage?

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

Thank you

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

Kartman wrote:
volatile' only forces the compiler to read/write the variable - it does not ensure atomicity.

Can please give furthe explanation?

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

It is amazing I will chake it physically

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

This thread worries me deeply. No one should be messing with mains design without formal training in the safety requirements. Googling around I see IEC-60950-1 mentioned a lot for example. 

 

While the IEC standards are charged for documents (which seems counter intuitive as common sense says they should be free for all who need their guidance) you can find interesting documents that summarise some aspects of safe design such as:

 

https://www.infineon.com/dgdl/Infineon-ApplicationNote_MOSFET_CoolMOS_Electrical_safety_and_Isolation-AN-v01_00-EN.pdf?fileId=db3a30433d1d0bbe013d20e0cbf017fe

 

While that is talking about how the safety standards impact the use of one manufactures specific devices I imagine there are many other application notes like this.

 

No one should be allowed near a design/implementation until they have at least a cursory understanding of such things. What you should never do is have an open sea of copper with mains connected to even a small part of it without it at least being encapsulated in a clear plastic enclosure. Suppose a colleague (or worse a child) happened to touch the "hot" parts of that while it was live !

 

This isn't a subject where you can have a cavalier attitude of "oh, it'll be all right - I know what I'm doing" (when you clearly don't).

 

In previous days there were organisations such as BEAB who would not allow a product to be sold without certification to show that the design adhered to all such mandated safety standards. These days there is CE testing/marking for the same kind of thing which harmonizes the safety concerns of all European regulatory authorities.

 

 

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

clawson wrote:
These days there is CE testing/marking

trouble is, there is no requirement for testing these days.

 

sad surprise

 

Counterfeit electrical goods which clearly have never been anywhere near a test lab - or even a competent design review - are a big problem nowadays.

Especially on places like Amazon, ebay, Ali Express, etc ...

 

sad

 

eg, just the very first of a huge list on google:  https://www.electricalsafetyfirst.org.uk/media-centre/press-releases/2018/06/conline-18-million-brits-fall-victim-to-counterfeit-electrical-goods-online/

 

https://www.theguardian.com/technology/2018/jun/06/dangerous-fake-electrical-goods-sold-amazon-ebay-investigation

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

...Googling around I see IEC-60950-1 mentioned a lot for example. 

 

And if you search for "60950 pdf" who knows what you might find. wink

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

 

Kartman wrote:

volatile' only forces the compiler to read/write the variable - it does not ensure atomicity.

Indeed.

 

 

Tinsae wrote:
Can please give furthe explanation?

Further explanation of what, exactly?

 

Recent discussion of 'volatile': 

 

https://www.avrfreaks.net/forum/why-volatile-variable-used-interrupt-service-routine - be sure to follow the link to clawson's tutorial!

 

Meaning of 'atomic':

 

https://preshing.com/20130618/atomic-vs-non-atomic-operations/

 

Importance of atomic operations:

 

https://en.wikipedia.org/wiki/Linearizability

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Feb 14, 2020 - 03:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That board was out of its cover to take pic. So it will be safe

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

You haven't been paying attention, then!

 

Many of the concerns raised sill apply when it's in the box.

 

And it's going to have to come out of the box for programming, testing, debugging, etc - so it should still have a safety cover for those situations.

 

Again, if you look inside properly designed mains gear, you will see such "secondary" protection ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To re-iterate Andy - your board is not safe. Putting it in a box makes no difference. Stop and recognise the danger signs.

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

Concerning relays. I though them an isolation device but depending on their quality, okay they may not provide the intended isolation. Most of the time I check with mega ohms range if there is reading. So far I didnt found. I am not defending bad design but i want to know and feel the reasons if there is some one who can tell me what kind of relay failure/bad quality brings lethal electric shock to some one touching the DRIVE CIRCUIT(I dont mean shock like the one you receive when you touch tv antena or pc usb) which is supposed to be isolated.

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

Tinsae wrote:
Concerning relays. I though them an isolation device

In themselves, they can be.

 

The concern here is not the relays themselves - it's how you've designed your PCB around them.

 

 

Most of the time I check with mega ohms range if there is reading. So far I didnt found.

Google the terms "creepage" and "clearance".

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want to see a good quality design then look back at post #34 where I showed an example of one.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

I just replaced the control board in my stove, since the old control board had no core value, I took it apart to see if I could identify the root cause.  The control mpu was a pic 18f(something)!

What I found were several burnt bodyies (ants) between the two hot phases near the relays, and more between the relay contact points (HV 220v ac) and one of the relay coil pins (5vdc), this most likely was the cause of the LED display failures leading to the need for the replacement.  I wish I had known this before I replaced the module so I could have sprayed the board with some conformal coating to provide some insulation between the HV points and the LV coils.  I'll know next time it happens.   The clearance was enough to prevent flash over but not a short via ant body(s) as they tend to march in a line, the pcb had no solder mask or conformal coating.

 

Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Which is apparently why malfunctions in software are known as "bugs" ;-)

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

Your stove should have good immunity now that it's built up all those anty bodies ...

laugh

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

crying Nice Andy, nice! 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Boom! Fresh from the Avrfreaks comedy store...........

 

 

Back to the issue at hand:

 

The safety issue is that there is not enough insulation clearance. The mains supply is well known to have high voltage transients from various sources. These transients may cause an arc which may couple the mains over the the low voltage parts of the circuit and may cause burning or a fire. To avoid this, there are electrical safety standards that tell us what acceptable clearance and creepage distances are. In many countries this is a legal requirement and will have implications with the insurance companies. 

 

Whilst your relay says 200VAC/10A - that is not the whole story. Different rules apply to different countries. In the U.S.A, the 220VAC is actually two 110VAC sources in series with neutral in the middle. So the peak rms voltage is only +/- 110Vrms around neutral. Compare this with Europe where the 230VAC is +/- 230Vrms around neutral.  

 

In terms of insulation, once you put the relay on a pcb, the insulation performance of the pcb may not be as good as air. Also there is contaminants like condensation etc that further degrade the performance. Therefore you need greater distance. Your board has little copper rings that make it very bad.

 

We need insulation for a much higher voltage than the mains voltage because of transients. Transients are high voltage pulses that can be many 1000's of volts. What happens if you get a high voltage pulse, it causes a spark which then causes current to flow  - lots of it. The only thing that stops it is a fuse, circuit breaker or the whole thing melts down. If you've used an Arc welder, you know that once you have struck an arc, the metal melts. The arc welder uses a high voltage pulse to start the arc, but the arc is maintained by a much lower, but high current supply.

 

So, when you get a transient, the spark starts a small arc welder in your circuit. This can cause fire and electrocution.

 

Here is what can happen:

 

http://epicbeardquest.blogspot.c...

 

https://en.wikipedia.org/wiki/El...

 

 

So for your ice maker, you have many sources for transients - the  refrigeration compressor, contactors, solenoids, fan motors. Then there are outside sources like other motors, lightning etc. So, electrical safety is #1. For the reasons of human safety, fire and that your ice maker continues to operate.

 

if you are only making one ice maker, then think about using DIN rail mounted relays. These are more expensive, but easier and safer for you to use.

 

Like these:

 

http://www.omron.com.au/products...

 

The design is such that it is easy to keep the low voltage and mains circuits separate. You can get pcb mount versions of these relays as well. 

 

 

Once you've got the electrical safety done, then you can look at ensuring your solenoids, motors etc don't create transients. For that we use 'snubbers'.

 

https://en.wikipedia.org/wiki/Sn...

 

Once you have done this, then we have talk about your electronics and software.

 

Hopefully all these words translate into your language. Otherwise I suggest you find help in a university or technical college where you can talk with someone knowledgable in your own language. 

 

I hope you now realise why your circuit is VERY dangerous.

 

 

 

 

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

awneil wrote:
Google the terms "creepage" and "clearance".

I googled it and also read the link given by clawson,
kartman also noted that the mains transient can form spark to the low voltage and electrocute someone touching the drive side. But as far as I know transient occurs shortly, then can they make serious harm? Remember thousands of volt can flow through me but only nasty pain without killing me when I touch my door. Also do ants body resistance will be sufficient low to conduct and kill someone? Please dont hate me, this is because I dont understand it( the googled one and the pdf) and I dont want to accept it as religion. The real understanding I have the more I respect safety. It is also said due to inadequate clearance, a conducting path may be created along the insulator. So this conductive path resistance will be low enough again to harm someone ( I know it is enough to damage the board)

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

Kartman wrote:

Transients are high voltage pulses that can be many 1000's of volts. What happens if you get a high voltage pulse, it causes a spark which then causes current to flow  - lots of it. The only thing that stops it is a fuse, circuit breaker or the whole thing melts down. If you've used an Arc welder, you know that once you have struck an arc, the metal melts. The arc welder uses a high voltage pulse to start the arc, but the arc is maintained by a much lower, but high current supply.

 

So, when you get a transient, the spark starts a small arc welder in your circuit. This can cause fire and electrocution.


Wow!! Well explained untill it penetrate deep inside me. Now I know why a transient is dangerous I taught they form and terminate instantly. But as you told me like welder they can sustain, now I see the real dangour. Wonderfull explanation thankyou kartman! Now safety issue is not a religion, I accept with understanding.

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

One more thing kartman, do removing the copper ring and cover the relay pins with enough hot glue help?

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

Tinsae wrote:
One more thing kartman, do removing the copper ring and cover the relay pins with enough hot glue help?

I mean let scrap my board and if I design it properly including groumd plane as shown in the thread. Can I use these relay with hot glue because they are the most available (but I dont want to compromis safety)

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

Post synchronisation problem

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

Hot melt glue is usually not known as a good insulator or for its fire properties.  If you want to persist with your cheapy relays, then you need to ensure that the copper rings are removed and to cut 3mm wide slots between the coil pins and the relay common pin. This will ensure you have better creepage distance.

 

You also need to make sure your wiring is adequate for the expected current as well as having a fuse or circuit breaker to make sure the current is not exceeded. Here's an example of a commercial wifi switch. You can see many slots cut into the pcb.

 

 

Last Edited: Wed. Feb 19, 2020 - 12:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Kartman, I have seen the slots on the picture and also accept the recommendation. Thank you man you helped a lot!

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

I read that you are using a PC power supply for 5V and 12V - be aware of the dangers! A PC power supply can deliver many Amps of current and melt your thin wiring. I would suggest you get a power supply that can only deliver 1A - much safer.

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

Yeah but unfortunately my machine uses automobile wiper motor for moving the water bath, this motor needs large amps that is why I need high amp power supply. Can I use thick wiring instead?

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

Do PC power supplies actually give much current at 12V ?

 

Or are you just running the motor at 5V ?

 

Tinsae wrote:
Can I use thick wiring instead?

You must always use adequately sized conductors !

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The usual problem with "high amps" is actually when they get to some place you had NOT intended or designed for - that's when the lightweight stuff releases the smoke dragons! if you simply don't make high amps available the lightweight stuff that got the inadvertent "shock" may survive. But once again this is all about "isolated design". If you have large barrier areas between high voltage or high amps stuff then it simply can't cross the barrier to do the damage on the side you want to protect (which in the limit can include human life!)

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

The 12v can delivere upto 18amps(look attached pic)
I am using 12V for the motor. Okay I will use the right conductor size.

Attachment(s): 

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

By the way I have noticed that the power supply shutdown itself when high current demand occur. This happend at trial stage of the machine mechanical part when the motor jammed.

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

PC power supplies are not the best choice for powering motors as you've observed. 

 

In a production circuit you would have current sensing or a fuse to limit the current to the motor. Ideally, the AVR should be able to measure the motor current (with extra circuit) and turn off the motor then flash a led to indicate a failure.

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

A PC power supply might not work properly without having a load on the 5V ?

 

I expect shutting down on overload is "expected behaviour" for a PC power supply.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
A PC power supply might not work properly without having a load on the 5V ?
I used to use an old PC power supply to power a LiPo/NiMh/NICd battery charger for model batteries from the 12V line. But you are right that the PSU would shut down if the 5V rail wasn't also loaded so I'd connect an old 5V/12V HDD I had lying around to one of the power lines to give it some loading and that kept the separate 12V for the battery charger alive.

 

I can't help wondering if ebay don't have some reasonably priced bench PSUs with current limiting and so on that you could use more reliably?

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

clawson wrote:
the PSU would shut down if the 5V rail wasn't also loaded so I'd connect an old 5V/12V HDD I had lying around

When I was trying to do this, I made a little dummy-load box.  Must be still knocking about somewhere ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

But you are right that the PSU would shut down if the 5V rail wasn't also loaded so I'd connect an old 5V/12V HDD I had lying around to one of the power lines to give it some loading and that kept the separate 12V for the battery charger alive.

Infact the pc 5v is loaded with the microcontroller.

clawson wrote:
I can't help wondering if ebay don't have some reasonably priced bench PSUs with current limiting and so on that you could use more reliably?

Unfortunately in my country there is no access to ebay, Amazon or alibaba. If there had been access to these shops, I wouldn't even use car wiper for my ice maker. There are more compact geared motor out there. Unfortunately I have to adapt with available items. Even there is no company that do pcb print (I have to deal with ferric chloride by my own if I am lucky and get copper plate the next time I go to that shop where I saw it once)

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

Tinsae wrote:
pc 5v is loaded with the microcontroller

I doubt that will "load" a PC PSU's 5V at all!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tinsae wrote:
Infact the pc 5v is loaded with the microcontroller.
Err no - if the micro is pulling even 10..100mA I'd be surprised. In PC terms that is not a real "load". In PCs there are devices consuming large fractions of a whole Amp or even several Amps. That is what would be considered a "load". The PSU probably wouldn't get out of bed for 10mA !

 

(and you may need to know who Naomi Campbell is to understand that last sentence ;)

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

By the way this is good lesson. I never had taught that the pc power supply require load at the 5v line. And when I try to recall, it happens that the pc psu freezes but till now I was thinking it due to loos socket.

awneil wrote:
A PC power supply might not work properly without having a load on the 5V ?

So why the term properly here mean?
The psu will not give the right voltage? Or it shutdown after while/ or randomly?

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

Depends on the actual power supply. Some might not start up, others might regulate poorly.
Usually connecting an old hard drive is enough to keep it happy.

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

Tinsae wrote:
So why the term properly here mean?

Properly means, "as specified".

 

In other words, you are into the realms of undefined behaviour.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 

BTW there's something else some PC supplies need. If it is an "ATX" power supply then the "main" cable from it is the one intended to power the motherboard in the PC. It looks like this:

 

 

Notice green pin 16? That's actually a signal from the motherboard back to the PSU to say "switch the power supply on". If you use a PSU standalone you may find you have to loop-back one of the 5V (I think it is!) to that pin to persuade the PSU that that is a fake motherboard present and it is asking for the PSU to be kept on.

 

EDIT: as I can't remember the exact details of what I had to do to make it work (it was years ago) I googled and I think there's an explanation of what may be needed here:  https://www.physicsforums.com/threads/force-computer-atx-power-supply-to-turn-on-without-motherboard.818754/

Last Edited: Fri. Feb 21, 2020 - 09:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it is better to connect calculated resistor (if we know how amps the pc psu need to be drained ) than hard drive. Can I go this way?

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

Tinsae wrote:
Can I go this way?

Of course you can.

 

That's exactly what I was talking about in #72

 

EDIT

 

calculated resistor

as you seem to be into re-purposing car spares, a 12V bulb of suitable wattage would probably do ... 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Feb 21, 2020 - 11:09 AM