help simple relay code not looping build a machine

hey guys need your help with a project, its very easy for who understand lool but im not an expert in it, so lets go...the code below should work like this...

  1. when press botao2, the motor start to spin until it reaches the first sensor of three.
    the sensor is (botao) acting like a button input..
    so when it reaches the sensor it stops the motor for 3 seconds and start to spin again, until it reaches
    the second one, so its stops again for another 3 seconds and start to spin, until it reaches the third one, in the third it must stay stopped until press the (botao2) to start all over again..

my english is not perfect sorry, but after this project i will pay a beer for us loool
i want to know whats wrong with the code cause it doenst work properly.. it works the first cicle but in the end it doenst loop back to wait for (button2)

im making a production machine for make foods..ive serchead a lot before in the internet if you guys
point me to were it wrong i will apreciate thanks

const int botao2 = 8;
const int botao = 2;

const int led = 10;

int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

unsigned long previousMillis = 0;  
unsigned long previousMillis2 = 0; 

const long interval = 5000;
const long interval2 = 5000;

int botaoState;

int botaoState2;

void setup() {
  pinMode( botao2, INPUT_PULLUP);
  pinMode( botao, INPUT_PULLUP);

pinMode (led, OUTPUT);

  // put your setup code here, to run once:


void loop() {
unsigned long currentMillis = millis();

botaoState2 = digitalRead(botao);
if (botaoState2 == LOW){
   digitalWrite (led, LOW);
 botaoState = digitalRead(botao2);
if (botaoState == LOW){
   digitalWrite (led, HIGH);
   Serial.print(" led on ");

buttonState = digitalRead(botao);

if (buttonState != lastButtonState) {
  if (buttonState == LOW){
 Serial.print("number of button pushes: ");

} else {


lastButtonState = buttonState;

if (buttonPushCounter == 1){

if (currentMillis - previousMillis >= interval) {
 previousMillis = currentMillis;
digitalWrite (led, HIGH);


if (buttonPushCounter == 2){
  if (currentMillis - previousMillis2 >= interval2) {
previousMillis2 = currentMillis;
digitalWrite (led, HIGH);

if (buttonPushCounter == 3){
  digitalWrite (led, LOW);

if (buttonPushCounter++ == 3){
  buttonPushCounter = 0;

No one?

I think you need to change these
previousMillis = currentMillis;
previousMillis2 = currentMillis;
previousMillis = currentMillis + interval;
previousMillis2 = currentMillis + interval2;

that way you are setting up the next time to check for.

Thanks CrossRoads I will try it I will let you guys know if its worked :wink: fingers crossed lool