Schedule fix desired time to control servo motor

Hi there!.

I'm working on an App for my final year project. I want the servo motor turn ON at specific time (for an example at 9am). I already go through some tutorial about schedule time but mostly used time picker. Is it a must to use time picker for this case? In my app, the user will have 3 option 3 pick (morning/evening/night) with a specific set of time (9am/3pm/9pm). I have given the interface below.

Here is what I have been working on

but I'm still stuck here.

Not clear. Does that mean that it is possible within the hour (ie from 9:00 to 9:59) or only at exactly 9:00? Or does "Morning" mean between 9 am and 3 pm?

No, you can have clickable image, as you have provided in image above. When, morning :sunrise: image is clicked, map it to 9AM, and when evening :city_sunset: is clicked, map to 4PM, and night :night_with_stars: to 9PM. Send your selection to Servo via Arduino to open pet feeding door.

No, you do not need to use a TimePicker. You can hard code the times. Here is an example you might be able to adapt

The servo will ON exactly at 9am or maybe plus/minus 1min.

Yup I have already turn on the clickable image option. About the selection of servo, do I need to write the selection code via Arduino first? Or just manage the selection via mit app? Because the user supposed to select the option based on the app right?

I have already look through this one but I seems cannot understand. At the link you share, it seems that user can change the date or it is fixed? I'm confused.Any action at fixed time
I try look at this one but it also got me confused on how it will work.

Getting real time, use e.g. this API:

Yes, it would be convenient, and I think, it is the flow, to instruct Arduino via application, and you may include, Real-Time Clock Module. With your application, you would be able to send a specific time, lets say, 9AM, now it is job of microcontroller to execute task at that specified time.

In the example, the date is fixed, however it is possible to write code using more Blocks to change the time or date. Set the date/time to anything you want. Even multiple times during a day.

The example does not run in the background. It either needs to be running or you should use a StayAwake routine to force the app to stay on continuously or use an extension to make the code run in the foreground or background continuously.

To understand how either example works; build the example and run the code :slight_smile: then adapt the code to do what you want. :astonished: Only you can determine whether the basic code is suitable for your project.

is it possible to use the system time block in mit to recall the actual time?

At the beginning, I thought the same concept as you. But my lecturer suggest me to use the system time which is already in the phone/app which can help me to reduce the cost of my project.

With this arrangement you must have to have phone near to your Arduino to keep feeding the phone-time via BT signal.

Yes, you can have.

I'm sorry that I could not catch up on this things cause this is the first time I'm using mit. Here is what i have tried is it good?

I hope this community could help me :cry: cry:

My project will use nodemcu esp8266 which will use wifi for the connection to the app. Will it work if i just program it through mit?

But, my question is why do you want to keep feeding MCU with phone system time, once you have send a fixed time to Microcontroller then you can relax, since rest will be handled by MCU, and your app can only need to be in picture when you decide to set new time, from 9AM to 3PM.

If I make the selection in arduino code, do I still need to make the selection blocks in mit as well?

I do not think so. Did you try it? I suspect it will not run.

Here is how to determine the time the servo should be on. For your purposes, you need lots more code to interface to your arduino. Sorry, I cannot help you with that.

This is a modification of the code Taifun provided on StackOverflow. It corrects an issue with his code (use of <= ).

1 Like

Thanks for this one, I will try it out