I am new at programming and i am writing my project sketches in modules to get each working before putting it all together. I have an arduino uno, a protoshield board stacked on the uno. I also have a 2 channel relay like this :
http://www.ebay.com/itm/like/140764956257?lpid=82&chn=ps&ul_noapp=true
One sketch takes 5 values from a remote light sensitive resistor, averages them and displays the result on a serial monitor. The code works fine and it loops continuously when plugged into the usb cable. If I have load the sketch via a usb cable, and then disconnect the usb cable with a 12v external power supply plugged into the arduino, the sketch stops. All the components for this sketch are mounted on the protoshield.
Another module turns a relay off and on, and the relay has a different external power supply. The relay is wired isloated from the arduino. (The jumper between the JDVCC-VCC terminals is off) . Its wired like the diagram in this link:
The arduino runs the relay board but the external power supply runs the relays themselves.
I have a light bulb connected to the relay. In this case, I load the arduino board with the usb cable, and it works fine. The light bulb goes off and on. I can then pull the usb cable with the 12 volt external power supply plugged into the board ( JDVCC and GND) and the sketch continues to operate normally.
I am not trying to operate both sketches at the same time. I have the protoshield stacked on the arduino and I know the 5v is available to the protoshield because I have used the 5v pins for other sketches powering an lcd. Any ideas on why a sketch with components on a protoshield would run fine on usb power but not on 12v external power? Thanks
Have you considered posting your sketches so people can see if its a coding error ?
Just a thought.
Oh and if you do PLEASE use the CODE TAGS provided to you ( </> )
This is the sketch that has components on the protoshield and won't run on 12 external power source.
// WRITTEN 3_19_17
//THIS MODULE WORKS AND WILL AVERAGE 5 LIGHT SENSITIVE RESISTOR (LSR) VALUES
//EVERY 10 SECONDS AND DISPLAYS ON SERIAL PORT
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sval = analogRead(0);
Serial.println("New Measurement");
Serial.println(sval);
delay(10000);
}
int ReadSens_and_avg(){
int i;
int sval = 0;
for (i = 0; i < 5; i++){
sval = sval + analogRead(0); // sensor on analog pin 0
}
sval = sval / 5; // average
return sval;
}
This is the sketch for the relay board that continues to run when the usb plug is pulled .
#define CH1 8 // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
void setup(){
//Setup all the Arduino Pins
pinMode(CH1, OUTPUT);
//Turn OFF any power to the Relay channels
digitalWrite(CH1,LOW);
delay(5000); //Wait 5 seconds before starting sequence
digitalWrite(CH1,HIGH);
delay (5000);
}
void loop(){
digitalWrite(CH1, HIGH);
delay(5000);
digitalWrite(CH1, LOW);
delay(5000);
}
one other piece of information. while researching this issue, i found that boards within a certain serial number range had a similar issue. These problem boards had a serial number that started with 39. My board has alot more digits in the serial number and starts with 85.
Which board relay / proto / arduino ?
Real arduinos or clones ? (we dont care)
Think a schematic might also be useful at this point don't care if its hand drawn.
Relays tend to pull more than the some of the smaller displays and dont forget that you should still share the ground with the Arduino too from the additional parts.
board is a a real arduino uno, here is what the board info tab shows:
VID 2A03
PID 0043
SN 8543130373635140
protoshield is like this link and is from arduino store:
relay board is like this link:
http://www.ebay.com/itm/like/140764956257?lpid=82&chn=ps&ul_noapp=true
I do have both a 5v connection and a ground between the relay and the arduino .THose are connected in the group of pins with the input. THe external power source on the relay connects to jdvcc and ground on other set of pins. i will work on a schematic.
here are the wiring diagrams for the two sketches. first is the lsr that quits running when i unplug the usb cable.
the second is for the relay that works on either an external power supply or the usb.
links to the relay :

Am returning your pics with minor edits for you to confirm.
yes, in both cases you show the arduino ground as i have it wired. sorry it wasn't clear
I just set up and ran the ISR sketch. works fine here in CREATE...
Going to try your relay sketch next.
EDIT relay sketch is fine too.
I think you may have an issue with your wiring and might want to double check with a multimeter that you don't have anything shorting or a poor solder joint.
just to clarify. the sketches both run ok when the usb plug is attached to the arduino. the lsr resitor sketch won't run on a 12v power supply, but will run with a usb connection. i'm not sure what solder connections would be related only to the 12v power supply. i am using a power supply with the standard plug that fits the arduino uno.
It shows 5 volts on the resistor / photo resistor picture are you feeding that with 12 volts ?
If so stop right away and use no more than 5 volts.
The relay sketch on the arduino side should also be fed with no more than 5 volts (preferably less) as it only needs to turn on the diode inside the opto isolator.
I didn't disconnect for the LDR test otherwise I would not have been able to see the output on the serial monitor but the relay test ran fine when the UNO was powered from 7.5 volts external.
i was using 12 v as i was also going to add an lcd screen into this mix and i read 5-12 v was fine. but i had another power supply i tried which was 4.5v and the same thing happened. the lsr wouldn't run. is it possible there is a problem with my arduino board?
Start with basics.
Disconnect everything.
Does you OS see it ?
Can you still upload sketches ?
Where were you feeding the 12 volts into on the Arduino ?
Is the 5 volt pin still 5 volts (or very close) ?
Is the 3.3 volt pin also close to that ?
If it works on USB you could try each pin with an LED and appropriate resistor.
You could also do a simple potentiometer test on the analog pins to see if they respond and give approx the same values.
If its a true Arduino then there seems to be an awful lot failing around the 12 volt mark recently.
Clones seem a lot more tolerant.
ok thanks for the ideas. with a meter, the 5v pin shows 5.1 and the 3.3v is right on the money. this sure is a puzzler. i think i am going to replicate it on a breadboard and see what happens.
the o/s (windows 8.1 ) sees the board, and sketches load fine. if i get this figured out, i'll post the solution. thanks for all the help.
the sketch does not run on a breadboard with external power supply either. The external power supply is supplying power to the board as i tried other sketches and they ran on only the external power supply. it seems the problem is in the sketch. i'll try to rewrite it in another way. I have no idea why the sketch will not run on external power supply.