unwanted signal or pulse reading from arduino

it is good now

Edit your post. Post your question/issue BEFORE the code tags, NOT IN the code tags.

  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);

This just looks stupid. Do you plan to name the input pins out1 and out2?

void coinInserted()   

{
  delay(100);

You can NOT use delay() in an ISR. ISRs are supposed to be lightening fast. It is stupid to even THINK of trying to delay in an ISR.

Sorry for that, it is named in1 and in2 because it is written on the relay module.

although i removed the delay and the problem still sticks.

is this a hardware problem or a software problem?

Sorry for that, it is named in1 and in2 because it is written on the relay module.

The INPUT to the relay module is OUTPUT from the Arduino. The name of the pin in the Arduino code should reflect the purpose of the pin, not the name of the pin on the other end. relayOnePin and relayTwoPin make far better names than in1 and in2.

Your code knows nothing about what the relays are actually controlling, or if they are doing anything other than clacking. It is, therefore, unreasonable to expect the code to stop counting down time when you remove power to the output side of the relay.

well my problem is not to stop the counting down time, the problem is that every time i plugged any laptop chargers or any appliance onto the AC output of the relay, the timer adds even when i don't insert a coin into the coin acceptor.

is there something i can do with the program?

skyskysky505:
Is there something i can do with the program?

you should use a State Machine approach, and consider just using the TimLib library rather than the timer… it is much easier to make sense of what’s happening

try this:

#include<LiquidCrystal.h>
#include <TimeLib.h>

enum State{
  NOT_CHARGING,
  CHARGING,
  STATE_UNKNOWN,
} volatile state = NOT_CHARGING;

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

volatile uint32_t expirationTime;

const byte coinInt = 0;
const byte in1 = 4;
const byte in2 = 5;

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();

  pinMode(coinInt, INPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  Serial.begin(9600);

  attachInterrupt(coinInt, coinInserted, FALLING);
  //expirationTime = now() + 15;  // debug
  Serial.println(F("Let's Go!"));
}

void coinInserted()
{
//  static uint32_t lastCoinMillis = 0; // debug
//  if(millis() - lastCoinMillis > 500) // debug
//  { // debug
    if (expirationTime > now())
    {
      expirationTime += 900;
    }
    else
    {
      expirationTime = now() + 900;
    }
    state = CHARGING;
//    lastCoinMillis = millis();  // debug
//  } // debug
}

void loop()
{
  static State lastState = STATE_UNKNOWN;
  uint32_t currentTime = now();
  if (state == CHARGING)
  {
    static uint32_t lastSecondsRemaining = 0;
    if (expirationTime > currentTime)
    {
      if (lastState != state)
      {
        Serial.println(F("CHARGING"));
        lcd.setCursor(0,0);
        lcd.print(F("    CHARGING    "));
        lastState = state;
      }
      uint32_t secondsRemaining = expirationTime - currentTime;
      if (secondsRemaining != lastSecondsRemaining)
      {
        lastSecondsRemaining = secondsRemaining;
        uint16_t hoursRemaining = secondsRemaining / 3600;
        secondsRemaining %= 3600;
        uint16_t minutesRemaining = secondsRemaining / 60;
        secondsRemaining %= 60;
        char lcdBuffer[21];
        snprintf(lcdBuffer, sizeof(lcdBuffer), "Time:%5u:%02u:%02u", hoursRemaining, minutesRemaining, (uint16_t)secondsRemaining);
        lcd.setCursor(0,1);
        lcd.print(lcdBuffer); // <<<<< added
        Serial.println(lcdBuffer);
      }
    }
    else
    {
      state = NOT_CHARGING;
    }
  }
  else
  {
    if (lastState != state)
    {
      Serial.println(F("Insert Coin"));
      lcd.setCursor(0,0);
      lcd.print(F("  INSERT  COIN  "));
      lastState = state;
    }
  }
}

well my problem is not to stop the counting down time, the problem is that every time i plugged any laptop chargers or any appliance onto the AC output of the relay, the timer adds even when i don't insert a coin into the coin acceptor.

Are you saying that just connecting something to the output side of the relay causes the ISR to be triggered?

If so, you have a hardware problem, not a software problem. Diodes and capacitors are your friends.

thanks for your suggestion i will consider doing your advice

I attached the schematic diagram that I’m using, in which part of the connection do I alter? do you have any suggestions? thank you :slight_smile:

chargingstation.jpg

I can't see how you connect the Arduino board to power. Are you using 5 volts or 12 volts?

Paul

Hi,
I don't see Arduino gnd connected to any of the other peripherals gnds! ! !

Tom.. :slight_smile:

Paul_KD7HB:
I can't see how you connect the Arduino board to power. Are you using 5 volts or 12 volts?

I am using a usb connector to power the arduino with 5volts.

TomGeorge:
I don't see Arduino gnd connected to any of the other peripherals gnds! ! !

I forgot to put it on the schematic diagram, but i do connect the gnd from the arduino into the common gnd.

Hi,
Can you post a picture of your project and a picture of your 12VAC adapter please.?

What does the adapter have printed in it?

Thanks.. Tom.. :slight_smile:

this is the pic of the whole project, I am using a 12V lead acid battery rated at 12AH instead of an adapter.

the whole project is a Solar powered charging station that is why I used a lead acid battery

Hi,
Ops Circuit
chargingstation.jpg

What are the relays switching and can you draw your schematic with PV and battery included please.

You show in your picture the two USB sockets connected, what do they do?
You know that you will be limited to about 300mA total current out of the USB sockets due to the fact that the LM7805 is not on a heatsink?

Tom... :slight_smile:

Hi,
Does the project malfunction on the 12V battery?
Or is it only on the 12V Adapter?

If it is only the adapter, them can you post the make/model/spec info?

A picture of the adapter would be good.

Sorry you are talking about the AC you are switching with the relay, am I right?

Tom... :slight_smile:

TomGeorge:
What are the relays switching and can you draw your schematic with PV and battery included please.

You show in your picture the two USB sockets connected, what do they do?

the relays are switching the charging cables which is connected in the usb port, and the AC plug.

the usb socket is used, one for the charging cables and one to give power to the Arduino Uno

skyskysky505:
the usb socket is used, one for the charging cables and one to give power to the Arduino Uno

You cannot feed power in that socket with the output of the LM7805 connected, the LM7805 does not like having external current put on its input.
Tom... :slight_smile:

TomGeorge:
You cannot feed power in that socket with the output of the LM7805 connected, the LM7805 does not like having external current put on its input.

those 2 usb sockets both draws power from the output of the 7805.