Turn motor 0.5 seconds every day code

I wanted to make a code that turns a moter 0.5 seconds every day. It is a motor on pin D5 and D16 it works on 3 AA batteries. I don't know much about coding but i used mBlock and it didn't work. Here is the code i had.

// generated by mBlock5 for <your product>
// codes make you happy

// generated by mBlock5 for <your product>

// codes make you happy

#include <Arduino.h>

#include <Wire.h>

#include <SoftwareSerial.h>

void _delay(float seconds) {

  long endTime = millis() + seconds * 1000;

  while(millis() < endTime) _loop();


void setup() {



  while(1) {








void _loop() {


void loop() {



I hope you can help find what is wrong.

What board are you using?
What motor are you using?
Can you post your wiring diagram?

Here is an Arduino sketch that will do basically what your code is doing:

const unsigned long SECONDS = 1000ul;
const unsigned long MINUTES = SECONDS * 60;
const unsigned long HOURS = MINUTES * 60;
const unsigned long DAYS = HOURS * 24;
void setup()
  pinMode(5, OUTPUT);
  pinMode(16, OUTPUT);

void loop()
  static unsigned long startTime = 0;
  if (millis() - startTime >= (DAYS * 1))
    startTime += (DAYS * 1);

    digitalWrite(5, HIGH);
    digitalWrite(16, LOW);

I don't know how setting Pin 5 HIGH and Pin 16 LOW once each day will turn a motor on and off. After the first day, 5 will be HIGH and 16 will be LOW forever.

So, what you want is the Blink Example except with an on-time of 500ms and an off-time of 86,399,500ms.

Note that the Arduino's oscillator isn't as good as a digital wristwatch and there will be some drift. Probably several seconds or more everyday. The error will be fairly constant so if you can figure-out how much error there is, you can tweak the off-time (if it's that important).

I am using an arduino leonardo with this motor: Motor Yellow 3-12VDC 2 Flats Shaft.
This is a photo of my arduino and motor if it wil help. (Don't mind the oter stuff on the board)
Thank you for your help already.

<Message>Access denied.</Message>
<Details>Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.</Details>

You could get more help by posting a wiring diagram

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.