Hello Everyone!
I'm new here. I need guidance for my code. I'm using 4 component and that is RTC (Real Time Clock), MCP 9808 (Temperature Sensor), SD Card Reader and LCD with Arduino UNO.
I can compile everything except for my SD Card reader. I can't define my temp sensor with my SD Card as the program needs to define the sensor pin. MCP 9808 uses VDD, GND, SCL and SDA pin. I have connected SCL to A5 and SDA to A4. It has an error that state " too many arguments to function 'int analogRead(uint8_t)' "
I'm not sure how to define my sensor pin. I hope someone can help me Thank you in advance!
This is my code:
#include<LiquidCrystal.h>
#include <Wire.h>
#include "Adafruit_MCP9808.h" //mcp9808 SCL Pin = A5 SDA Pin = A4
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>
int rs=2,en=3,d4=4,d5=5,d6=6,d7=7;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
#define sensorPin A4, A5 //temp sensor pin SDCard
File myFile; //create file sdcard
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
RTC_DS3231 rtc;
//-------------------------------------------------------------
void setup() {
lcd.begin(16,2);
Serial.begin(9600);
Serial.print("Initializing SD Card...");
while (!SD.begin(8)) {
Serial.println("STARTUP SD Card Initialization FAILED!");
}
Serial.println("STARTUP Initialization Success.");
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(DATE), F(TIME)));
}
if (!tempsensor.begin()) {
Serial.println("Couldn't find MCP9808!");
while (1);
}
if (! rtc.begin())
{
lcd.print("RTC is NOT running!");
}
lcd.clear();
}
//----------------------------------------------------------------
void loop() {
DateTime now = rtc.now();
float c = tempsensor.readTempC();
int reading = analogRead(sensorPin);
while (!SD.begin(8)) {
Serial.println("SD CARD NO LONGER READABLE!");
}
myFile = SD.open("temptLog.txt", FILE_WRITE);
if (myFile) {
myFile.print(now.year(), DEC);
myFile.print('/');
myFile.print(now.month(), DEC);
myFile.print('/');
myFile.print(now.day(), DEC);
myFile.print(" ");
myFile.print(now.hour(), DEC);
myFile.print(':');
myFile.print(now.minute(), DEC);
myFile.print(':');
myFile.print(now.second(), DEC);
myFile.print("Temp: ");
myFile.print(c,1);
myFile.print("C");
}
else {
Serial.println("ERROR OPENING FILE");
}
lcd.setCursor(0, 0);
//lcd.print(now.year(), DEC);
//lcd.print('/');
//lcd.print(now.month(), DEC);
//lcd.print('/');
//lcd.print(now.day(), DEC);
//lcd.print(" ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(c,1);
lcd.print("C");
delay(1000);
}