output only generates when USB cable is connected with PC and UNO

Hello Team

i am new, working on an ADC ZMPT101B.

i am using a separate 5Vdc power supply.

my program is showing Veff while in serial.print.

and the logic is working perfect.

only issue is that when i remove the USB cable from UNO

the program become halt/ or no output generated by the UNO

kindly help me.

program file is attached.

regards
Nasir

Power_Change_System.ino (1.33 KB)

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.

What exactly do you mean by "output"? The only output I see in the code is the relays (and a commented out Serial.println()).
[/quote]

"Output" means the command i write to follow the IF condition.

What is connected to A2?

nashfaq1981:
"Output" means the command i write to follow the IF condition.

Which if?

if (Veff >= 200 and Veff <= 250)

my code is not executing or checking this IF condition...

even though on serial print i can read the value of Veff.

nashfaq1981:
if (Veff >= 200 and Veff <= 250)

my code is not executing or checking this IF condition...

So by "output" you meant relays. Why is it so difficult to get you to tell us the information we need to help you?

nashfaq1981:
even though on serial print i can read the value of Veff.

How are you doing that with the USB cable not connected to your PC?

Hello nashfaq1981

nashfaq1981:
i am not using any phone charger, i am using a 5Vdc power supply.

Where is connected your 5Vdc power supply?

Regards,
bidouilleelec

DKWatson:
What is connected to A2?

ZMPT101B module

the comparison is only working when USB cable is connected with UNO.

if i remove the cable, comparison doesnt work.

Hello nashfaq1981

]

from: nashfaq1981 on Today at 06:30 am

i am not using any phone charger, i am using a 5Vdc power supply.

Is your 5Vdc power supply connected to Vin or +5V ?

Regards,
bidouilleelec

please find the picture of the adopter and the connection with UNO

may be i am not explaining the issue properly...

let me write the problem again.

when i run my code and watch the Veff on Serial Monitor i am getting values of Veff.
and the comparison of IF Statement executes and Relay turn ON.

but when i disconnect the USB cable, it looks to me that IF condition gets failed and relay did not turn ON.

i am confused that why IF statement only works while USB cable connected with PC and UNO.

hope now everything is clear.

sorry for the english, as it is not my mother language.

regards
Nasir

nashfaq1981:
please find the picture of the adopter and the connection with UNO

regards
Nasir

The voltage on the jack must me between 7v and 12v.

Regards,
bidouilleelec

Dear Friends

thanks for help, i change the power connection from Jack to Vin, now i have relays are getting ON,

i also need help in the programming of Voltage monitoring

when i turn ON AC supply for ZMPT101 Module, the relays gets ON, as i have 220Volts

but when i switch OFF the 220 volts supply of ZMPT101 Module, my code store the last max value,

instead of checking the volts continuously that goes down to Zero and switching OFF the relay.

kindly help me on this also...

regards
Nasir

Check this thread.

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.

nashfaq1981:
Dear Friends

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!

Ian

Hi team

thanks for your support.

the last issue is in the code below, Veff value is only be read by the IF statement when USB cable is connected with UNO.

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);
}

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?