0
\$\begingroup\$

I am interfacing a PIC16F877 with a 5V DC relay. I hooked up the relay to the same 5v that power up my PIC with the appropriate transistor, diode, voltage to power up an LED to NC and LED to NO, I hooked up an LM35(Tempreature sensor) to my PIC and an LCD to check what is going on, i wrote my code and everything is working perfectly.

However, when i try to switch the relay with my pic the reading on the LCD changes dramatically, so if Room tempreature is about 20C it will show 2C or 3C.

EDIT: I tried to hook up the LCD to a different voltage source and same behavior happened, then i tried to make a current buffer with an UA741 and 2n2222 and same behavior.

following is the schematic: enter image description here

When i run the simulation everything is working fine, but in real hardware its outputting a different Temperature on the LCD than when i remove the relay.

IDEAS?

\$\endgroup\$
10
  • 2
    \$\begingroup\$ It probably has to do with all the current the relay is consuming. Are you driving it directly from the PIC or using a transistor? Maybe the PIC is malfunctioning for this reason. \$\endgroup\$
    – Iaka Noe
    Commented Dec 29, 2018 at 16:41
  • \$\begingroup\$ yes i am using a 2n2222 transistor and i connecting the 5v and gnd from the same breadboard as the pic but they are connected in parralell so i dont think thats the problem \$\endgroup\$
    – forthelulx
    Commented Dec 30, 2018 at 13:16
  • \$\begingroup\$ Turn off the grid, man! Turn off the grid before taking screengrabs. The text is illegible. \$\endgroup\$
    – Transistor
    Commented Dec 30, 2018 at 13:58
  • \$\begingroup\$ @Transistor please clarify what you mean. \$\endgroup\$
    – forthelulx
    Commented Dec 30, 2018 at 14:06
  • \$\begingroup\$ @KARAMJABER As I can see now, you are trying to switch between two LEDs. A relay is a bit overkill for that use. You can use both LEDs in antiparallel. You select the LED that is turned on via giving 5V to the upper side and 0V on the lower side or vice-versa. \$\endgroup\$
    – Iaka Noe
    Commented Dec 30, 2018 at 14:19

2 Answers 2

1
\$\begingroup\$

There are no decoupling capacitors on the PIC, but then again, there are no power-supply connections either. If you omit the decoupling capacitors you can expect trouble.

A few suggestions to improve legibility of your schematic:

  • Use GND symbols at the component wherever possible. It eliminates a load of wiring and clearly shows the potential at each of those points without having to trace the wires.
  • Do the same for the V+.
  • Avoid unnecessary kinks and corners. Look at R2! What's it doing down there when it should be up beside the LCD.
  • Put D2 and D3 beside each other above the relay. Their anodes are both connected to V+ but it's not clear from the schematic. Positioning them side by side and with V+ symbols on their anodes would make this instantly clear.
  • Orient C1 vertically so the + plate is on top and the grounded plate is at the bottom. This follows the generally accepted standard that voltage decreases as we read from top to bottom.

Share the result when you're done. Meanwhile, check the decoupling capacitors.

\$\endgroup\$
1
\$\begingroup\$

Try using a separate DC source for either LCD or Relay or You can use a DC source which can output more Ampere(typically milliampere).

Also,try figuring out the approx current consumed by each devices and choose the optimum source.

\$\endgroup\$
2
  • \$\begingroup\$ check the edited question please. \$\endgroup\$
    – forthelulx
    Commented Dec 30, 2018 at 13:15
  • \$\begingroup\$ Sorry for the late response, Try adjusting the delay in program after passing write command to the LCD. LCD registers need some to store before next character is passed. \$\endgroup\$ Commented Jan 12, 2019 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.