Optocoupler, a tiny IC which is basically an LED triggered transistor can be live saving in many project situation. This is a short story about one such incident in project development and am sure it’ll help you if you face such issues in your microcontroller projects
Last week we were working on an Industrial project. It wasn’t something that I had designed but had been called upon for troubleshooting the issue which was coming in. The project was simple, it had below mentioned interfaces
- Ultrasonic Sensor
- Microcontroller(atmega328p)
- LCD
- Relay x 2
- DC Motor x 2
Primarily, the job was to turn on and off those 2 dc motors based on some sequences of distance sensed by the ultrasonic distance sensor. However these 2 DC motor were actually water pumps, and were operating on 24 volts
Now you must have known it till now that any Motor is an Inductive load and the microcontrollers are too much scared of inductive loads 😄 😄 😄
Because when they turn On, the supply Line shatters a little bit and hence the microcontroller either hangs or gets a reset.
So what was happening in that project was, whenever we turn on a Motor in program sequence, the entire system hangs. Boom, nothing else. It simply stops executing the code, the LCD displays some garbage characters.
Now there are many techniques with which these interferences may be reduced, primarily by using the Snubber Circuit.
Below is something which was present there at the time of doing this experiment
Now as you can see, there is fly back diode present, there is the RC Snubber present, additionally such snubber was also connected across the com and NO of relay. But still it didn’t helped
whenever the relay was turned On by controller signal, the controller Hang.
Now there are several reasons for such thing to happen, but primarily, the reason is NOISE. And if you can’t seem to solve such thing, then its better and much better if at the time of design itself, you incorporate optocoupler.
What is optocoupler? If you ask me, its a life saver 😎😎
Its basically a replacement to transistorized switch but this time, the switching happens just by emitting light using the atmega signal and hence, the noise induced in controller side is at minimum. You can also NOT REQUIRED TO MAKE COMMON GROUND when using optocoupler. Means the 24v ground and +5v ground need not to be made common.
Finally below is the arrangement which solved all issues with the system
as you can see, the optocoupler provides complete electrical isolation between 24v side and +5v side hence this arrangement worked perfectly for the system
The optocoupler used was MCT2E, however you can use any optocoupler you may have like PC817
If there is a base Pin to your optocoupler, simple keep it open or Not connected to anything. Its just there to give a manual trigger instead of the light trigger that comes off from LED and can keep it open while using the LED inside optocoupler.
Whether your project is based on Arduino or Atmega or PIC or STM32 or Raspberry Pi, this tip will help in every situation where ever you need to trigger relays in your system, particularly when what you’re switching is a high current device
So keep this thing in mind next time when you’re debugging your relay based microcontroller project.