I'm using rtc DS3231 and arduino uno
I'm looking to code the rtc and servo to switch a switch at a specific time
I'm also trying to create it with an if statement
an example of a code would help a lot. Thanks.
I'm using rtc DS3231 and arduino uno
I'm looking to code the rtc and servo to switch a switch at a specific time
I'm also trying to create it with an if statement
an example of a code would help a lot. Thanks.
Welcome to the forum.
Common problem, lotsa solutions.
Read
This has some interesting servo stuff:
HTH
a7
Which Arduino and DS3231 library are you using? What time for switch ON & OFF?
I'm using arduino uno and <DS3231.h> library. The time is at 5:30
There are dozens of similar named RTC libraries. Please provide a link, not just the name of the header file. Also please provide information about your particular hardware components.
Please make an attempt to code this. If you are completely lost, you have skipped valuable lessons and need to go back and do some simpler work.
You said, "I'm also trying to create it with an if statement". We can't help without seeing your work. Don't forget to use code tags when you post code in the forum.
This is what I have done so far I am also using an ldr for the project, I don't know where I'm doing wrong
#include <Servo.h>
#include <DS3231.h>
int ldr = 0;
int val;
Servo x;
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200);
rtc.begin();
pinMode(A0, INPUT);
x.attach(2);
}
void loop() {
int val = analogRead(A0);
Serial.println("Received value : ");
Serial.println(val);
delay(1);
DateTime now = rtc.now();
if (val < 700 && now.hour() == 5 && now.minutes() == 30) {
x.write(30);
}
if(val > 700 && now.hour() != 5 && now.minutes() !=) {
x.write(40);
}
}
Thank you for the code. However, you did not supply the information I asked for.
I don't know where I'm doing wrong
... and we don't know what is wrong, because you didn't say.
You didn't finish this line. '!=' what?
You need to tell us specific problem information, like "it won't compile without errors".
For the RTC library, I thought there was only one library for specifically DS3231 so I just put in DS323.h. I'm a beginner in using the libraries so I didn't know there was more than one.
That's great but you still didn't post a link to it, as I requested.
Sorry, I forgot to put that one in, I meant
if(val > 700 && now.hour() != 5 && now.minutes() !=30) {
So, the code you posted is not the code you are running? We can't debug fictional code. Please re-post your entire, exact sketch.
this is the link. DS3231/DS3231.h at master · NorthernWidget/DS3231 · GitHub
Great, thanks. Please read the forum guidelines and come back with the rest of the information!
here's the sketch
#include <Servo.h>
#include <DS3231.h>
int ldr = 0;
int val;
Servo x;
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200);
rtc.begin();
pinMode(A0, INPUT);
x.attach(2);
}
void loop() {
int val = analogRead(A0);
Serial.println("Received value : ");
Serial.println(val);
delay(1);
DateTime now = rtc.now();
if (val < 700 && now.hour() == 5 && now.minutes() == 30) {
x.write(30);
}
if(val > 700 && now.hour() != 5 && now.minutes() != 30) {
x.write(40);
}
}
Exact problem is?
By the way, this
if (val < 700 && now.hour() == 5 && now.minutes() == 30) {
x.write(30);
}
if(val > 700 && now.hour() != 5 && now.minutes() != 30) {
x.write(40);
}
could be
if (val < 700 && now.hour() == 5 && now.minutes() == 30) {
x.write(30);
}
else {
x.write(40);
}
it says 'class D3231' has no member named 'now' for rtc.begin();
line
I got this line from a different code so I don't know how to fix it
Obviously, you can't mix and match functions from completely different libaries. Simply, don't!!! Look at the library examples and documentation to find out how.
Also please catch up and provide hardware details!
Your responses are limited in number on your first day as a member. I suggest you don't waste any posts with incomplete answers. You are almost out of replies and will soon be locked out for a day.
Again, in case you missed it:
Thanks for mentioning that.
Complex if statement logic can be hard to get right. I can't tell if yours, or @anon57585045's version what I will assume does the same thing, because @anon57585045, does anything sensible.
So in plain English words describe how the LDR and time are to be respected to inform the movement of the servo.
Then maybe my brain won't hurt trying to help.
TIA
a7
In fact, this code has no state change detection, it computes and sets the servo every millisecond. So for one minute a day, the servo is written 1000x60 = 60,000 times. For the rest of the day, it's written a bazillion times.
So whatever I wrote, is just a patch. Also speculative, as I also need a clear description of what it is supposed to do.