This is likely because the 5v is not doing its job when you disconnect the USB, maybe because it is improperly connected to Arduino, like through the barrel jack...
"no output generated by the UNO" implies an alternative display, which may be the last staw for an inadequate power supply. Please don't tell us you are trying to use an old phone charger.
Whenever possible, please post your code directly to the forum, rather than using an attachment. This will make it easier for people to look at your code, which will make it more likely for you to get help with your question. In the case that the code exceeds the forum's 9000 character limit, it's fine to do an attachment but in this case the length is nowhere near 9000.
nashfaq1981's code
int sensorValue = 0;
int sensorValue1 = 0;
int crosscount = 0;
int climbhill = 0;
int VmaxD = 0;
int VeffD;
int Veff;
// Time Defining//
const long oneSecond = 500;
const long One_Min = oneSecond * 60;
const long Half_Min = oneSecond * 30;
int KE_Relay = 9; //Green
int Gen_Relay = 10; //Orange
int Gen_OFF = 11; // Yellow
int ledPin = 13; // select the pin for the LED
int AC_Volts = 0;
void setup() {
// Serial.begin(115200);
pinMode(KE_Relay, OUTPUT);
pinMode(Gen_Relay, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
sensorValue1 = sensorValue;
delay(20);
sensorValue = analogRead(A2);
if (sensorValue > sensorValue1 && sensorValue > 511) {
climbhill = 1;
VmaxD = sensorValue;
}
if (sensorValue < sensorValue1 && climbhill == 1) {
climbhill = 0;
VmaxD = sensorValue1;
VeffD = VmaxD / sqrt(2);
Veff = round((((VeffD - 420.76) / -270.24) * -150.2) + 150.2);
VmaxD = 0;
}
if (Veff >= 200 and Veff <= 250)
{
// delay(Half_Min);
delay(2000);
digitalWrite (KE_Relay, HIGH); // Gen Contactor De-Energized 10
//delay(Half_Min);
delay(2000);
digitalWrite(Gen_Relay, HIGH); // Turn ON the KE Contactor 9
//delay(2000);
}
else {
digitalWrite (Gen_Relay, LOW);
digitalWrite(KE_Relay, LOW);
}
//Serial.println(Veff);
}
nashfaq1981:
the program become halt/ or no output generated by the UNO
What exactly do you mean by "output"? The only output I see in the code is the relays (and a commented out Serial.println()).
"no output generated by the UNO" implies an alternative display, which may be the last staw for an inadequate power supply. Please don't tell us you are trying to use an old phone charger.
[/quote]
Hi Mate,
i am not using any phone charger, i am using a 5Vdc power supply.
nashfaq1981:
i am not using any phone charger, i am using a 5Vdc power supply.
Is there a difference?
Well not really, if it is not properly used, and it might as well be a phone charger. It says in your picture that it is 5v and you are putting it in a barrel jack that the Arduino specification says requires a minimum of 7v, so it is hardly surprising that you have a problem.
It is caused by losses in the regulators. You may fix it by coming up with some adapter that allows you to connect to the 5v pin - after you have checked the output really is 5v - or using a 7.5v or 9v wall wart.
thanks for help, i change the power connection from Jack to Vin, now i have relays are getting ON,
Hmmm...
That may operate but will not be reliable. The reason for this is that on a Uno the Vin pin is connected to the input side of a 5V regulator (usually a NCP1117ST50 or equivalent) which requires a minimum excess of around 1.1 volts to work correctly. That is the regulator requires the input voltage to be a minimum of 5 + 1.1 = 6.1V before it regulates correctly. It is the output of this regulator which supplies the Uno and it's outputs with 5V.
You are supplying it with +5V which means you are using the regulator out of spec and what it does when working with a below limits input voltage is not defined by the manufacturer. My guess is it will output the input voltage less some voltage drop across the regulator which might well be proportional to the amount of current you are trying to draw from the regulator.
If you measure one of the 5V pins on the Uno you will probably measure somewhere around 4 volts. The ATMega328p will work down to 3.3V but NOT reliably at 16MHz.
The reason your Uno didn't work with the 5V plugged into the barrel jack is that there is an additional reverse voltage protection diode between the barrel jack and the input to the regulator which adds another 0.7V voltage drop thus reducing the input to the regulator to 4.3V.
There is a good reason why the designers specified the input voltage at the barrel jack to be 7-24V.You should stick to those specifications!
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags: [code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.
I think the problem has already been explained to you. Supplying 5 V to the barrel jack or Vin pins will result in the microcontroller not getting the necessary voltage. This could cause unstable operation due to not running at spec for the 16 MHz clock speed and/or BOD (brown-out detection) resets. Have you resolved the power issue and verified that your microcontroller is indeed running at 5 V?