Using MCP 9808 with SD Card Reader

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);
}

#define sensorPin A4, A5 //temp sensor pin SDCard

What will be the value of sensorPin after this line ?

Damn those macro's!

UKHeliBob:

#define sensorPin A4, A5 //temp sensor pin SDCard

What will be the value of sensorPin after this line ?

Sorry i don't understand what you mean. do you mean what is the value after i compile the code? if this is what you mean, the value will be the temperature of the surrounding and it is 24.3 e.g

Not even close...

"sensorPin" literaly is "A4, A5" which turns "analogRead(sensorPin)" just into "analogRead(A4, A5)". See the problem?

Ben then up to the next, read up about how to actually read a MCP9808. Non will tell you to use analogRead(), that's for sure.

And why don't you save the pin numbers to a variable like decent people instead of a macro?

By the way, your error did contain more info which you would have known if you invested the time read How to get the most out of this forum. It would have stripped your cool sunglasses though...

septillion:
Not even close...

"sensorPin" literaly is "A4, A5" which turns "analogRead(sensorPin)" just into "analogRead(A4, A5)". See the problem?

Ben then up to the next, read up about how to actually read a MCP9808. Non will tell you to use analogRead(), that's for sure.

And why don't you save the pin numbers to a variable like decent people instead of a macro?

By the way, your error did contain more info which you would have known if you invested the time read How to get the most out of this forum. It would have stripped your cool sunglasses though...

Thank you for pointing out my mistake on analogRead and i already edit the code.
I have watch different types of video on MCP9808. Yes, no code for use analogRead. I'm just adding analogRead as i am trying to define the analog pin. But now i delete the line.
Sorry for not reading the article of first time user. FYI the sunglasses is actually this " while (!SD.begin( 8 ) ) "

FYI the sunglasses is actually this " while (!SD.begin( 8 ) ) "

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.