FALSE READING ON ARDUINO DIGITAL OUTPUT PIN (probably some kind of noise?)

HI all,

I have a strange problem with my arduino. I have connected digital pin with NPN transistor to control logical 5V (ON /OFF ) button on my solar controller to power it ON/OFF from arduino. Everything is grounded, everything works great until it accidently (TURN ON ) without any action in random time (it is not software error ). It accidently turns on sometimes after Refridgerator turns on, or servo is moving.. I am sure it is some kind of noise on arduino digital bus or so .. but have no Idea how can I fix it ..

Please give me tip what Can I try to avoid this strange unwanted random behaviour of turning ON my solar controller.
(it discharges my batteries when it should NOT and thats a problem :frowning: )

(I have arduino with ethernet shield together and using digital pin 6 to control my solar controller ... cable length between solar controller is about 2 meters long )

Schematic and code?

Hi, how are you powering the arduino and have you got filter and bypass capacitors fitted?

Tom.... :slight_smile:
Yes a picture and circuit diagram would be great, also what size panels and battery bank?

How far is the NPN transistor from the Arduino? Is that the 2m you mentioned? What are you doing to prevent pick up of interference? Twisted pair, coax, bypass capacitor on base of transistor?

AWOL:
Schematic and code?

very simplified schema of connection and part of code which is responsible for switching:

if(!digitalRead(9))digitalWrite(9,HIGH);
else digitalWrite(9,LOW);
uDelay(100);
if(!digitalRead(9))digitalWrite(9,HIGH);
else digitalWrite(9,LOW);

void uDelay(unsigned int length){ // T defined timer Alarm
#ifdef T
Alarm.delay(length);
#else
delay(length);
#endif
}

I am controlling it over internet using AJAX

schema.jpg

TomGeorge:
Hi, how are you powering the arduino and have you got filter and bypass capacitors fitted?

Tom.... :slight_smile:
Yes a picture and circuit diagram would be great, also what size panels and battery bank?

I am powering it with LM7805 12V -> 5V regulator
Battery bank is 12V auto battery and solar panel is only 60 Watts
Its a bigger project with auto switching to grid power when solar controller is turnded off

At first I will surely try mentioned bypas capacitor / and which kind of filter did you mean?

polymorph:
How far is the NPN transistor from the Arduino? Is that the 2m you mentioned? What are you doing to prevent pick up of interference? Twisted pair, coax, bypass capacitor on base of transistor?

no, NPN IS 0.1m far from arduino but NPN is about 2M far from solar controller

oroboss:
very simplified schema of connection and part of code which is responsible for switching:

if(!digitalRead(9))digitalWrite(9,HIGH);
else digitalWrite(9,LOW);
uDelay(100);
if(!digitalRead(9))digitalWrite(9,HIGH);
else digitalWrite(9,LOW);

}

Why are you reading and writing the same pin? Is it an input or output?

You need a resistor in the base of that transistor.
You need supply decoupling:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

ITS OUTPUT PIN

And I am finding with it if it is not in logical 1 state otherways It should always be in logical 0 state (except of that short delay), maybye its not needed but its better to check it..

I am imitating push button action with arduino / (not holding push button on solar controller by my thump but with arduino for 0.1 sec . (its stateless action) but I can find it by current meter if solar controlerr is turned ON or NO. Its acting correctly switching it ON When I push the button in web browser and off when I push it again . (if there is no network problem )

Hmm but yes, It should be simplified I need to test it and will write you back

oroboss:
maybye its not needed but its better to check it..

digitalRead() may take more than 100us, I can't remember. You'd be far better off to define a state variable and simply write the value of the state variable to the pin. Then your logic only manipulates the state variable.

boolean state = false;
while(1) { 
  digitalWrite(x, state);
  if (state == true)  state=false;
}

digitalRead() may take more than 100us, I can't remember

It'd be worrying if it did, wouldn't it?

Hi, looking at the circuit, can you be a bit more detailed, do you have any other connection between the arduino and the controller?

Where is the gnd return from the transistor to the arduino to giver your transistor correct base current?

If you cannot provide a gnd connection from the arduino to the controller, and still have control, then you should be using an opto coupler instead of a transistor, in fact I'd say you should be using an opto coupler no matter what the case.
If the switch that you are bypassing is not connected to gnd at one end then your control could quite easily be as erratic as you describe.
Have you reverse engineered the controller to be absolutely sure that the switch is not part of a multiplexed keypad/display.
Also bypassing have you done any, a solar system being primarily DC can have all sorts of switching noises and these have to be dealt with.
Please a bit of this and a bit of that is not helping us to well, a full connection diagram, power supply and input output circuits, and full sketch.
If you do not have a full circuit diag, then stop and make one before you do anything else.
What level of experience with arduino, programming and electronics do you have?
Hope to help, but we need full picture.

Tom....... :slight_smile:

Thank you All guys! optocoupler definitely solved my problem. Until now I have no unexpected switching ON/OFF my solar controller. GREAT !

AS a reward here is my messy prototype scatch of my project its a combination of websocket + standard webserver with datalog and NTP time + TIMERS all it fits to one Arduino UNO. Maybye it can help someone :smiley:

webServerWebsocket.ino (21.1 KB)

Hi, good result mate.

Tom...... :slight_smile: