Here
#include <SD.h>
#include <Wire.h>
#include <SPI.h>
int CS_pin = 4;
int SD_led = 8;
#include "floatToString.h"
#include "RTClib.h"
RTC_DS1307 RTC;
float COValue = 0;
float NO2Value = 0;
float O3Value = 0;
float e_NO2Value = 0;
float e_NOValue = 0;
float e_COValue = 0;
float celsius = 0, kelvin=0;
#include <math.h>
int dustPin=0;
int ledPower=2;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
float ZeroPercentVoltage = 0.8;
float val = 0;
float RH = 0;
float max_voltage = 3.27;
char date_time[10];
char CO_Vout[10];
char NO2_Vout[10];
char O3_Vout[10];
char cel[10];
char hum[10];
char e_NO2_Vout[10];
char e_NO_Vout[10];
char e_CO_Vout[10];
void setup()
{
Wire.begin();
Serial.begin(9600);
SPI.begin();
pinMode(53, OUTPUT);
//digitalWrite(53, HIGH);
RTC.begin();
pinMode(ledPower,OUTPUT);
pinMode(5, OUTPUT);
String header = "Date_Time, Temp, Humidity(%), e_NO2_Vout, e_NO_Vout, e_CO_Vout, CO_Vout, NO2_Vout, O3_Vout, Dust_Vout";
Serial.println(header);
}
void loop()
{
NO2Value = analogRead(1) * 0.004882812;
COValue = analogRead(2) * 0.004882812;
O3Value = analogRead(3) * 0.004882812;
kelvin = analogRead(4) * 0.004882812 * 100;
celsius = (kelvin - 273.15) - 15;
val = analogRead(5);
max_voltage = (3.27-(0.006706*celsius));
RH = ((((val/1023)*5)-ZeroPercentVoltage)/max_voltage)*100;
digitalWrite(ledPower,LOW);
delayMicroseconds(delayTime);
int dust_Vout = analogRead(dustPin);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH);
delayMicroseconds(offTime);
e_NO2Value = analogRead(8) * 0.004882812;
e_NOValue = analogRead(9) * 0.004882812;
e_COValue = analogRead(10) * 0.004882812;
pinMode(SD_led, OUTPUT);
digitalWrite(SD_led, HIGH);
floatToString(CO_Vout, COValue, 8);
floatToString(NO2_Vout, NO2Value, 8);
floatToString(O3_Vout, O3Value, 8);
floatToString(cel, celsius, 1);
floatToString(hum, RH, 1);
floatToString(e_NO2_Vout, e_NO2Value, 8);
floatToString(e_NO_Vout, e_NOValue, 8);
floatToString(e_CO_Vout, e_COValue, 8);
DateTime now = RTC.now();
sprintf(date_time,"%d/%d/%d %d:%d:%d",now.day(),now.month(),now.year(),now.hour(),now.minute(),now.second());
String dataString = String(date_time) + ", " + String(cel) + ", " + String(hum) + ", " + String(e_NO2_Vout) + ", " + String(e_NO_Vout) + ", " + String(e_CO_Vout) + ", " + String(CO_Vout) + ", " + String(NO2_Vout) + ", " + String(O3_Vout) + ", " + String(dust_Vout);
Serial.println(dataString);
pinMode(SD_led, OUTPUT);
digitalWrite(SD_led, HIGH);
delay(59000);
digitalWrite(SD_led, LOW);
delay(1000);
At the bottom of the code:
DateTime now = RTC.now();
sprintf(date_time,"%d/%d/%d %d:%d:%d",now.day(),now.month(),now.year(),now.hour(),now.minute(),now.second());
String dataString = String(date_time) + ", " + String(cel) + ", " + String(hum) + ", " + String(e_NO2_Vout) + ", " + String(e_NO_Vout) + ", " + String(e_CO_Vout) + ", " + String(CO_Vout) + ", " + String(NO2_Vout) + ", " + String(O3_Vout) + ", " + String(dust_Vout);
Serial.println(dataString);
pinMode(SD_led, OUTPUT);
digitalWrite(SD_led, HIGH);
delay(59000);
digitalWrite(SD_led, LOW);
delay(1000);
LED turns on without printing the datastring on screen and it never turns off.