Looking for an Arduino guru to help me out with something. I’ve written a small Arduino program that is supposed to drive a solid state relay on a brewing rig.
It’s got an LCD shield over the top with 4 buttons to adjust the ‘power’ of the heater. Essentially, I’m running a 2 second cycle that has an on segment for x% and an off segment with (1-x)%.
Simple enough… got it to run exactly as expected when I have the ‘driven pin’ as pin 13… the onboard LED.
at 0%, it’s always off, at 100% it’s always on, and at any % between it is correspondingly on then off.
HOWEVER…
Now that I’m ready to drive the external SSR, I’ve soldered 2 wires in, the first to Digital Pin 02, and the second to one of the three +5V pinouts.
When I initialize the program, I have it starting at 0% by a digitalwrite(Pin02, LOW)
However, my multimeter shows an output of 2.75V.
I can do the same thing and initialize it to HIGH, but it still shows the 2.75V.
NOW THE CRAZY PART:
As soon as I move it away from 100% on or off, it works just fine; the voltage briefly jumps to 5V and then 0.
When I go back to 100* or 0% it just goes back to the 2.75V
What am I missing to get the initialization to to be 0 or 5V?
Taking it back to basics, I’ve found that the HIGH and LOW have exactly the opposite effect for the +5V / Digital Pin 2.
On a sketch started from scratch, if I write Digital Pin 2 to HIGH, it gets 0 volts, and if I write it to LOW, I get +5 Volts. Still not sure of the logic here, I’ll have to go back and check my Arduino 101 again for this one
But I still haven’t figured out why on my other program it sits at 2.75 when I have it set for 100 or 0%
The back to basics sketch:
///////////////////////////////////////////////////////
int DrivenPin = 2
;
Ugh… like most programming issues, it all comes down to the placement of a single bracket…
Had an IF loop that I accidentally closed before it should have been.
But thanks for the tips on adding CONST to my constants… always like to be efficient.
As far as the revers effect of the On / Off states, I just added another pair of constants at the front called PowerON and PowerOFF and can easily switch them between HIGH and LOW as needed. Also made my code easier to read!
For pin definitions, using #define is handy. The compiler essentially does a find-and-replace on them, so no additional memory is used to store a variable that will never change during runtime.