First project

Hi guys,

I am in need, in need of your help!

Its my first project, a complete novice, and after your help to see if what I want to do is remotely possible.

  1. Programme a coin acceptor to only work when the target value is reached. (I think this is possible, but I don't understand how to do it) i.e. 50p for 15 minutes

  2. Once the target value is reached, programme the start button on a PS3 to start the timer. i.e. once 50p is inserted, press start and that starts the timer for the user.

Are either / both of these possible to do? Is someone able/willing to mentor me?

Really appreciate your help
I know you must get loads of similar asks every day, but I really would value your expertise.

Thanks!
Dan

coin acceptor to only work when the target value is reached

I don't understand that. What does it mean to "work"?

Hey, thanks for the reply, I should have been clearer.

My coin acceptor is connected to and powers a USB port.

In my scenario a 50p coin gives power to the USB ports for 15 minutes.
My question and where i need help is - the coin acceptor should not allow the USB to work if you put in under the target value. i.e. if you put in a 10p - you would need the remaining 40p before it would give power to the USB port.

Yeah then that's very doable but I'm in the middle of paying work right now so can't help with specifics.

But along these lines:

Accumulate amount tendered coin by coin
If target reached (50p) then set a flag say feePayed= true
Then only if feePayed=true listen for the button to be activated* and if it is (and we only listen for the button if the fee has been payed), set the output high**
When output is newly high make a note of the time with millis()
Every time through loop() check to see if the new millis minus the stored start time exceeds the interval, the 15 minutes
If it does, set output off; if it doesn't, do nothing

  • I have no idea how to read a ps3 button
    ** I have no idea how to talk through a USB but let's just for arguments sake say some pin or other is switched.

Very top of the head, but might get you thinking.

I might try this as a min-project tonight if I'm not too tired and shagged out....

Hi there,

I am looking for someone who can help me and mentor me with my first piece of code

The ask is:
I have a coin acceptor, that pulses and gives power to a USB time control board. At the moment that works with any coin I programme and it gives a set amount of time.

The first part is:
I want it to only allow the power to be given to the USB port once a minimum value has been inserted. I.e. the minimum amount to give power to the USB port should be 0.50p. So 50p = 1 credit, if 60p is inserted, it would give 1 credit (0.50p) plus carry over 0.10p for the next credit.

The second part is:
I want the 0.50p credit to equal a 15minute time window.

I can give a more detailed brief, but in a nutshell that is the overall requirement.

My coding skills are not really existent - so I could offer a small reward in return for help getting this working.

BTW you may find this Wikipedia article on state machines helps to clarify your thoughts.

Here's some code which might help you at least as far as some logic is concerned.

My hardware is nothing like yours so:

  • Coin acceptor is a single button which I had to debounce due to poor quality. Each press is 10p
  • I just have a red led to come on to indicate it's operational

This is a state machine with 3 states, WAITING, ARMED and POWER_ON explained in sketch comments. States are handled in a switch... case where each does its thing with some leds and moves to next state when appropriate. When the timer turns the power off, it goes back to WAITING.

I also have the led on pin 13 doing a continuous Blink WithOut Delay to indicate none of the code is doing any blocking, which would prevent any other code from working properly.

//http://forum.arduino.cc/index.php?topic=459230
// coin operated power supply

//states are:
//WAITING for money
//   blue led means no money yet
//   blue and green led means 10, 20, 30, 40p has been inserted
//ARMED 50p inserted, awaiting start button
//   green only led means 50p and waiting start
//POWER_ON working
//   red only led
//   stays on for 5 seconds (not the real 15 minutes)

//I don't have a coin box so using a button to mean 10p inserted
//coin button is debounced becuase my buttons are crap
//    used Bounce2 library

//pulse is a delay()-less blink on 13 to prove nothing blocks

//

//button pins
byte coinButton = 8; //mimics 10p inserted
byte startButton = 9; //turn on power
//led pins
byte POWER_ONled = 2; //red
byte ARMEDled = 3;    //green
byte WAITINGled = 4;  //blue

//timing
unsigned long currentMillis;

//power timing
unsigned long poweredOnAt;
int powerOnFor = 2000; //not 15m for test
bool weAreTiming = false;

//pulse timimg
unsigned long previousPulse = 0;
byte pulseInt = 250;
bool pulseState;


//money
byte insertedSoFar = 0;
bool coinButtonState;
bool coinButtonStatePrev = true;


//states
enum { WAITING, ARMED, POWER_ON} currentState = WAITING;

//coinButton needs debouncing
#include <Bounce2.h>
Bounce dbCoin = Bounce();


void setup() {
  // put your setup code here, to run once:
  //leds
  pinMode(POWER_ONled, OUTPUT);
  digitalWrite(POWER_ONled, LOW);

  pinMode(ARMEDled, OUTPUT);
  digitalWrite(ARMEDled, LOW);

  pinMode(WAITINGled, OUTPUT);
  digitalWrite(WAITINGled, LOW);

  pinMode(LED_BUILTIN, OUTPUT); //pulse

  //buttons
  pinMode(coinButton, INPUT_PULLUP);
  pinMode(startButton, INPUT_PULLUP);
  //debounce
  dbCoin.attach(coinButton);
  dbCoin.interval(50);

}

void loop() {
  // put your main code here, to run repeatedly:

  currentMillis = millis();

  //always update the debouncer
  dbCoin.update(); //dbCoin.read() to read

  pulse(); //blink the heartbeat

  //now sit in each state
  //states show certain leds and await buttons to move to new state
  //power state reverts to waiting when time is up

  switch (currentState) //WAITING, ARMED, POWER_ON
  {
    case WAITING:
      digitalWrite(WAITINGled, HIGH);
      //handle a coin
      coinButtonState = dbCoin.read();
      if (coinButtonState != coinButtonStatePrev) //it changed
      {
        if (coinButtonState == LOW) //new press = new coin
        {
          digitalWrite(ARMEDled, HIGH);
          insertedSoFar = insertedSoFar + 10;
        }//coin button new press
      }//coin button change
      coinButtonStatePrev = coinButtonState;

      //got 50p yet?
      if (insertedSoFar == 50)
      {
        insertedSoFar = 0; //for next time
        digitalWrite(WAITINGled, LOW);
        currentState = ARMED; // moving on....
      }//got 50


      break;

    case ARMED:
      digitalWrite(ARMEDled, HIGH);
      if (!digitalRead(startButton)) //active low
      {
        digitalWrite(ARMEDled, LOW);
        currentState = POWER_ON; // moving on....
      }//start
      break;

    case POWER_ON:

      digitalWrite(POWER_ONled, HIGH);
      if (!weAreTiming)
      {
        weAreTiming = true;
        poweredOnAt = currentMillis;
      }

      if (weAreTiming)
      {
        if (currentMillis - poweredOnAt >= powerOnFor) //we done
        {
          digitalWrite(POWER_ONled, LOW);
          weAreTiming = false;
          currentState = WAITING; // moving on....
        }
      }
      break;
  }//switch

}//loop

void pulse()
{
  if (currentMillis - previousPulse >= pulseInt)
  {
    digitalWrite(LED_BUILTIN, pulseState);
    pulseState = !pulseState;
    previousPulse = currentMillis;
  }
}//pulse

@DanTexeter, do not cross-post. Other threads removed / merged.