I have one question, I using rtc ds3231 for my project. My question is how to set a timer for the servo to turn on let say I want to make 3 meals per day. With using rtc ds3231 , servo motor and lcd_i2c . Can someone help me to do the timer for my project . If anyone who pro in coding can u drop your email for me to contact . Thank you
What you want to do should be easy
You can read the hour and minute from the RTC and compare them with the required feeding times. As a starting point can you read the values and print the values ?
If you are willing to pay for help then this topic can be moved to the Jobs and paid consultancy" category of the forum. Do you want me to do that ?
Yes can
Post your code that prints the values, using code tags when you do
What you mean sir? Sorry I’m new with this forum and not soo good in coding
You said
I took that to mean that you could print the values so I suggested posting your code here. If you post your code then follow the instructions about how to use code tags in How to get the best out of this forum
I will tag the problem in this reply by put the tagging the problem with "//##"
This is the code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <DS3231.h>
//LCD
LiquidCrystal_I2C lcd(0x27,16,2);
//Servo (!!Setting ni!!)
Servo servo;
int servoPin = 7; //servo pin to pwm 7
int pos =0;
int buka =90;
//Ultrasonic hc-sr04
const int trigPin = 9; //hc-sr04 for measuring stock
const int echoPin = 8; //hc-sr04 for measuring stock
//Formula for measuring percentage
long distance,cm; //calculation
long duration; //formula for calculate sound wave
int foodPercentage; //percentage stock in container
//RTC DS3231
DS3231 rtc(SDA, SCL);
int feedHour;
int feedMin;
int feedSec;
void setup()
{
Serial.begin(9600);
//lcd
lcd.begin();
lcd.setCursor(0,0);
lcd.print("Projek Anchor");
lcd.setCursor(0,1);
lcd.print("SPM");
delay(3000);
//RTC DS3231
rtc.begin();
rtc.setTime (07, 29,55);//hour,min,sec
rtc.setDate(13, 6, 2021);//DD,MM,YY
//SERVO
servo.attach(7);//servo
servo.write(pos);//initial condition.
//Ultrasonic
pinMode(trigPin, OUTPUT); //hc sr04
pinMode(echoPin, INPUT); // hc sr04
}
void loop()
{
//for lcd food percentage
void foodsPercentage();
{
lcd.clear();
delay(100);
lcd.noDisplay(); // Turn off the display:
delay(100);
lcd.display(); // Turn on the display:
digitalWrite (trigPin,LOW);
delayMicroseconds (10);
digitalWrite (trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration= pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
foodPercentage = map(distance, 30, 2, 0, 100 );// this is the math for the percentage dont mind
if(foodPercentage < 0)
{
foodPercentage =0;
}
else if(foodPercentage>100)
{
foodPercentage =100;
}
lcd.setCursor(0,0);// set cursor to column 0, row 0 (the first row)
lcd.print("Food Contain: ");
delay(20);
lcd.setCursor(0,1);
lcd.print(foodPercentage);
lcd.print("%");
delay(2000);
}
void alert();
{
lcd.clear();
delay(1);
if(foodPercentage <20)
{
lcd.setCursor(0,0);
lcd.print("Need to refill");
lcd.setCursor(0,1);
lcd.print("We're hungry");
delay(1000);
}
}
void masa();
{
lcd.clear();
delay(0);
lcd.setCursor(0,0);
lcd.print("Date:");
lcd.print(rtc.getDateStr());
// Send time
lcd.setCursor(0,1);
lcd.print("Time:");
lcd.print(rtc.getTimeStr());
// Wait 3 second before repeating
delay (3000);
}
//SERVO
void feedingtime(); //## the problem at here
{
if(feedHour ==7, feedMin ==30,feedSec ==00)
{
servo.write(buka);
lcd.clear();
lcd.print("TIME TO EAT !!");
delay(2000);
}
else if (feedHour ==7, feedMin >=30,feedSec >=32)
{
servo.write (pos);
delay (0);
}
if(feedHour ==18, feedMin ==30,feedSec ==0)
{
servo.write (pos);
delay(500);
servo.write(buka);
lcd.clear();
lcd.print("TIME TO EAT !!");
delay(2000);
servo.write (pos);
}
}
delay(0);
return 0;
}
void feedingtime(); //## the problem at here
That semicolon should not be there
Sir I it still can’t be set as timer for servo to open 90 degree. When the time arrived at 7:30:00 as I set for example. After it has opened, servo keep open like a normal loop and not like a timer that open just like I set . My objective is , when I 7:30:00 it should open once and wait to the another set time . Can you help ke
Have you fixed the problem noted in reply #8 ?
When the time comes to move the servo then move it. If you want to move it back to its original position then do it say a few seconds later
time = 07:30:00 - open feeder
time = 07:30:05 - close feeder
Can you help me by put it inside coding format? I understand the flow but to put in coding I don’t know
First you need to get the hour , minute and second from the RTC. Where do you do that in the code ?
If you don't know how to do it then look at the examples that came with the DS3231 library
I dont know how to get that time to be fill in the loop. can you give example based on my situation .
Have you looked at the library examples ?
Read this: && - Arduino Reference
dont have sir
Let say I set
feed1 at 9:00:00
feed2 at 14:00:00
feed3 at 18:00:00
My question is what is the code to call function time to set the timer
Where did you get the library ?
I would be very surprised if there were no examples with it. Have you looked under File/Examples in the IDE ?
i have example, but it does'nt required as I want sir. I want the servo to open at certain time. but I dont know the coding to call the time to servo to operate
Post the example code here but make sure that you follow the advice in How to get the best out of this forum and use code tags