Dear Stack Exchange community.
I'm a beginner Arduino user and am attempting to replicate a 24-hour alarm clock demonstrated in a tutorial found at: https://diyhacking.com/arduino-alarm-clock-using-real-time-clock-lcd-screen/.
I downloaded and installed all the most updated libraries associated with the DS3231 Real Time Clock module.
When I attempt to run the following program (I am not the author of this code, as it is directly taken from the page I linked above), I am met with an error that seems to be a result of missing a key library.
Can anyone tell me which libraries I need to install to eliminate the error?
#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
DS3231 rtc(SDA, SCL);
Time t;
#define buz 11
int Hor;
int Min;
int Sec;
void setup() {
Wire.begin();
rtc.begin();
Serial.begin(9600);
pinMode(buz, OUTPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("DIYHacking.com");
lcd.setCursor(0,1);
lcd.print("Arduino Alarm ");
delay(2000);
}
void loop() {
t = rtc.getTime();
Hor = t.hour;
Min = t.min;
Sec = t.sec;
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
lcd.setCursor(0,1);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());
if( Hor == 11 && (Min == 32 || Min == 33)) {
//Comparing the current time with the Alarm time
Buzzer();
Buzzer();
lcd.clear();
lcd.print("Alarm ON");
lcd.setCursor(0,1);
lcd.print("Alarming");
Buzzer();
Buzzer();
}
delay(1000);
}
void Buzzer() {
digitalWrite(buz,HIGH);
delay(500);
digitalWrite(buz, LOW);
delay(500);
}
The error returned when I compile and run this program is as follows:
sketch_oct29c:17: error: no matching function for call to
'DS3231::DS3231(const uint8_t&, const uint8_t&)'
DS3231 rtc(SDA, SCL);
^
Can anyone suggest a fix for this?
The following libraries are those that I installed:
DS3231,
MD_DS3231,
Rtc_by_Makuna,
RTClib,
RTCtime
Cheers!
Encountered the same error and had to google for a number of days to get it sorted out. Seems the issue is being caused by the library.
You need to download the Rinky Dink DS 3231 library. You can download it from here
Once downloaded, extract the DS3231 folder and place it into the libraries folder of your Arduino. Once you've done that, run the program and it would work. Hopefully.
Related
Can Anyone Please Convert the following Arduino Code to Embedded c code? I am very thankful to the one who converts this to an embedded c code. (this code is for Arduino lcd interfacing with Ultrasonic sensor)
#include <LiquidCrystal.h>
int inches = 0;
int cm = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(7, INPUT);
}
void loop() {
lcd.clear();
cm = 0.01723 * readUltrasonicDistance(7);
inches = (cm / 2.54);
if (cm<40){
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print("Caution: ");
lcd.setCursor(0,1);
lcd.print("Objects Nearby");
delay(1000);
}
}
long readUltrasonicDistance(int pin)
{
pinMode(pin, OUTPUT); // Clear the trigger
digitalWrite(pin, LOW);
delayMicroseconds(2);
// Sets the pin on HIGH state for 10 micro seconds
digitalWrite(pin, HIGH);
delayMicroseconds(10);
digitalWrite(pin, LOW);
pinMode(pin, INPUT);
// Reads the pin, and returns the sound wave travel time in microseconds
return pulseIn(pin, HIGH);
}
I'm sorry but you can't because the dependencies of this code are LiquidCrystal.h (written in C++ and it contains dependencies like Arduino.h or Wire.h, libraries exclusive of Arduino software) and because methods like pinMode(int,int),digitalWrite(int,int),delayMicroseconds(int) comes from Arduino.h.
You can make your LiquidCrystal library rewriting it from the original.
Here some resources: C header and source, compile and upload, setup, standard avr libs.
I hope this can help. Good luck!
You can do that but is bit painful. Convert the class based function into c type functions. Remove dependant functions and replace the function by your own.
and use int main(void) instead of void loop().
Someone know why ATTiny85 connect to ds1307 crystal get time the refresh frequency to slow?
The new time value refresh change at 4 second.
It running normal on arduino(UNO).
ATTiny clock (internal 8 Mhz)
Thx.
#include <TinyWireM.h>
#include "TinyRTClib.h"
#include <Tiny4kOLED.h>
RTC_DS1307 rtc;
void setup() {
// put your setup code here, to run once:
oled.begin();
oled.clear();
oled.on();
oled.switchRenderFrame();
rtc.begin();
rtc.adjust(DateTime(2019, 3, 30, 15, 38, 0));
}
void loop(){
if (! rtc.isrunning()) {
return disconnectCrystal();
}
DateTime now = rtc.now();
oled.fill(0xFF);
oled.clear();
oled.switchFrame();
oled.setFont(FONT6X8);
oled.setCursor(32, 2);
..
oled.print(now.hour(), DEC);
oled.print(':');
oled.print(now.minute(), DEC);
oled.print(':');
oled.print(now.second(), DEC);
..
delay(1000);
}
Try using millis() instead of delay()
https://gist.github.com/kubilisr/eaf9d488e258a2175313fb38f6f80aa2
I have an Arduino Pro Mini 5v, 16 mhz and it is connected to a digital switch on pin 2. This switch is used to wake the Arduino from sleep using a external digital interrupt. I also have a DHT11 temperature sensor connected to pin 9. What I want to achieve is the when the Arduino is awake for 5 seconds and also when the switch on pin 2 is HIGH, I want to read the temperature sensor and return the temperature. I am using the DHT11 library by Tillart and when I do this, it returns a TIME_OUT error. The only possible explanation I have for this is that somehow the voltage is changed when both the DHT11 and the switch on pin 2 is being read together? Any pointers to a solution will be greatly appreciated. Thank you.
Edit 1: Added code
#include <LowPower.h>
#include <dht.h>
int pin2 = 2;
dht DHT;
#define DHT11_PIN 9
void pin2interrupt(void)
{
// Function called when awoken from sleep
// Detach interrupt to stop it from continuosly firing when in normal mode
}
void enterSleep(void)
{
attachInterrupt(0, pin2interrupt, HIGH);
Serial.println("Sleeping");
delay(100);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
Serial.println("Awake!");
}
void setup()
{
Serial.begin(115200);
pinMode(pin2, INPUT);
pinMode(DHT11_PIN, INPUT);
}
int seconds = 0;
void loop()
{
delay(1000);
seconds++;
Serial.println("Awake in the loop!");
Serial.println(seconds);
if (digitalRead(pin2) == LOW && seconds == 5)
{
seconds = 0;
Serial.println("No child detected, so going to sleep!");
delay(200);
enterSleep();
}
else if (seconds == 5)
{
Serial.print("DHT11, \t");
int chk = DHT.read11(DHT11_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.println(DHT.temperature, 1);
delay(2000);
seconds = 0;
}
}
Edit 2: I also forgot to to mention that I am using the LowPower library by RocketScream to put the Arduino to sleep. The library can be found here: https://github.com/rocketscream/Low-Power
As discussed in the issues section on the official Github page of the DHT11 library by Rob Tillart, the problem is caused because some DHT11 sensors take longer to transfer data back to the board then the 50ms or so specified on the datasheet. Therefore, if you are encountering this problem try increasing the DHTLIB_TIMEOUT on the dht header file by reducing the the value dividing the F_CPU value to around 400 and try again. This allows the board to wait longer than 50ms for the board to receive data back from the sensor. If this fix doesn't work, you might want to try measuring the response time using an oscilloscope as it seems some DHT11 are built differently.
I was getting to know this ultrasonic detector with a simple code. All I was looking for was an output (my LED) to light up whenever the detector sensed an object within so many centimetres.
However the LED remains lit and the serial monitor just keeps spitting out the value '0.00cm'
I would appreciate any help, thanks.
(I do apologise if there is a very simple error I have overlooked)
#include <NewPing.h>
int TriggerPIN = 2;
int EchoPIN = 3;
int LEDPIN = 7;
void setup()
{
Serial.begin(9600);
//That started the distance monitor
pinMode(LEDPIN, OUTPUT);
pinMode(TriggerPIN, OUTPUT);
pinMode(EchoPIN, INPUT);
}
void loop()
{
float Distance, Duration;
digitalWrite(TriggerPIN, LOW);//These three blink the distance LED
delayMicroseconds(2);
digitalWrite(TriggerPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TriggerPIN, LOW);
Duration = pulseIn(EchoPIN, HIGH); //Listening and waiting for wave
Distance = (Duration*0.034/2);//Converting the reported number to CM
if (Distance > 50)
{
digitalWrite(LEDPIN,LOW);
}
else
{
digitalWrite(LEDPIN,HIGH);
}
Serial.print(Distance);Serial.print("cm");
Serial.println(" ");
delay(200);
}
A couple of things to try:
Change the serial print to display 'Duration', to see if the problem lies in the centimetre conversion.
If this is not the problem:
(Assuming you are using the NewPing 1.7 library, as found here. )
The NewPing library has a built in 'Ping' function, along with distance conversion.
Try replacing the start of your code with this:
#include <NewPing.h>
#define TRIGGER_PIN 2
#define ECHO_PIN 3
#define MAX_DISTANCE 200 // Maximum distance to ping for (cm). Up to ~450cm
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
You do not need to then set the Trigger and Echo pins as outputs in your setup.
In your main loop, use these methods to get time and distance in microsecs and centimetres:
unsigned int pingTime = sonar.ping(); //Gets the ping time in microseconds.
Serial.print(sonar.convert_cm(pingTime)); // Convert ping time in cm, serial out.
I hope this helps.
I am using Arduino mini 5V for my project and RTC - Real Time Clock Module DS1307
I would like to wake the board at a certain time and run a function. (Buzzer is connected to D3)
When I use the TimeAlarm alone and manually set the time everything works fine:
#include "Time.h"
#include "TimeAlarms.h"
void setup(){
setTime(22,29,55,12,31,14); // set time to Saturday 8:29:00am Jan 1 2011
Alarm.alarmRepeat(10,30,0,buzz); // 10:30am every day
Alarm.alarmRepeat(16,30,0,buzz); // 4:30pm every day
Alarm.alarmRepeat(22,30,0,buzz); // 10:30pm every day
Serial.begin(9600);
}
void loop(){
digitalClockDisplay();
Alarm.delay(1000);
}
void buzz(){
tone(3, 220, 1000);
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits){
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
However when I use RTC the buzzer function wouldn't get called, it still prints the time though
#include <Wire.h>
#include "RTClib.h"
#include "Time.h"
#include "TimeAlarms.h"
RTC_Millis rtc;
void setup(){
rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
Alarm.alarmRepeat(10,30,0,buzz); // 10:30am every day
Alarm.alarmRepeat(16,30,0,buzz); // 4:30pm every day
Alarm.alarmRepeat(22,30,0,buzz); // 10:30pm every day -- modify this to your current time when running the example
Serial.begin(9600);
}
void loop(){
//printing the current time
DateTime now = rtc.now();
Serial.print(now.year());
Serial.print('/');
Serial.print(now.month());
Serial.print('/');
Serial.print(now.day());
Serial.print(' ');
Serial.print(now.hour());
Serial.print(':');
Serial.print(now.minute());
Serial.print(':');
Serial.print(now.second());
Serial.println();
Alarm.delay(1000); // wait one second between clock display
}
void buzz(){
tone(3, 220, 1000);
}
OK so I found the answer:
First problem was: using RTC_DS1307 instead of RTC_Millis
RTC ds1307 is referring to pin 12C which in Arduino mini they are above A3 and VCC. They require soldering. Once that's done they should be connected to SDA and SCL, using M/F wires
SDA -> to the pin above A3
SCL -> to the pin above VCC
Then I changed the code to the following:
#include <Wire.h>
#include "RTClib.h"
#include "Time.h"
#include "TimeAlarms.h"
RTC_DS1307 rtc;
const int output = 3;
uint32_t syncProvider()//function which sets up the RTC as the source of external time{
return rtc.now().unixtime();
}
void setup(){
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(__DATE__, __TIME__));//comment this out when the RTC has been set
setSyncProvider(syncProvider); // the function to get the time from the RTC
Alarm.alarmRepeat(10,30,0,buzzer); // 10:30am every day
Alarm.alarmRepeat(16,30,0,buzzer); // 4:30pm every day
Alarm.alarmRepeat(22,30,00,buzzer); // 10:30pm every day
pinMode(output , OUTPUT);//new line
Serial.begin(9600);
}
void loop(){
//printing the current time
DateTime now = rtc.now();
Serial.print(now.year());
Serial.print('/');
Serial.print(now.month());
Serial.print('/');
Serial.print(now.day());
Serial.print(' ');
Serial.print(now.hour());
Serial.print(':');
Serial.print(now.minute());
Serial.print(':');
Serial.print(now.second());
Serial.println();
Alarm.delay(1000); // wait one second between clock display
}
void buzzer(){
//Do Stuff
}
Just to help noob like me who did tried this code by using copy paste and get error
named return values are no longer supported Error compiling.
After searching through the net found that the { the infamous curly bracket is part of comment so please change the same to
uint32_t syncProvider() { //function which sets up the RTC as the source of external time
return rtc . now() . unixtime();
}