datalogging without computer

Hey world!

couldnt find a threat by the same, and have only been working with arduino for a month or 2..

im about to make a school-project, where i will test the indoor climate at a firm.

I has started this project where i can measure Temperatur, humidity, heat-index and Co2-level. with this data i logged it on a sd card. my problem is when i want to go "offline" (without a computer) and connect it with a 5V power suply. it wont log the data on the SD-card..

any suggestion?

any suggestion

Describe what you have, post a schematic, post your code, otherwise it is all hand waving.

You are right.. :slight_smile: seems no problem with the wiring, like i said it work when its conecthed to the computer. think the problem is with my code..

i have a sd-adapter, Mq135 sensor and the humidity/temperatur sensor, connected to my arduino Uno

my code is, and hope its readable:

#include <SD.h>
#include <SPI.h>
#include "DHT.h"

#define DHTPIN 7
#define DHTTYPE DHT11

#define anInput A0 //analog feed from MQ135
#define co2Zero 44 //calibrated CO2 0 level

long seconds=00;
long minutes=00;
long hours=00;

int CS_pin = 10;

DHT dht(DHTPIN, DHTTYPE);
File sd_file;

void setup() {
Serial.begin(9600);
pinMode(CS_pin, OUTPUT);
dht.begin();
// SD Card Initialization
if (SD.begin()) {
Serial.println("SD card is initialized. Ready to go");
}
else {
Serial.println("Failed");
return;

}

sd_file = SD.open("data.txt", FILE_WRITE);

if (sd_file) {
Serial.print("Time");
Serial.print(",");
Serial.print("Humidity");
Serial.print(",");
Serial.print("Temperature");
Serial.print(",");
Serial.print("CO2-index");
Serial.print(",");
Serial.println("Heat_index");

sd_file.print("Time");
sd_file.print(",");
sd_file.print("Humidity");
sd_file.print(",");
sd_file.print("Temperature");
sd_file.print(",");
sd_file.print("CO2-index");
sd_file.print(",");
sd_file.println("Heat_index");
}
sd_file.close(); //closing the file
}

void loop() {

sd_file = SD.open("data.txt", FILE_WRITE);
if (sd_file) {
senddata();
}
// if the file didn't open, print an error:
else {
Serial.println("error opening file");
}
delay(1000);
}

void senddata() {
for(long seconds = 00; seconds < 60; seconds=seconds+10) {
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float heat_index = dht.computeHeatIndex(temp, hum);

int co2now[10]; //int array for co2 readings
int co2raw = 0; //int for raw value of co2
int co2comp = 0; //int for compensated co2
int co2ppm = 0; //int for calculated ppm
int zzz = 0; //int for averaging
int grafX = 0; //int for x value of graph

for (int x = 0;x<10;x++){ //samplpe co2 10x over 2 seconds
co2now[x]=analogRead(A0);
delay(1000);
}

for (int x = 0;x<10;x++){ //add samples together
zzz=zzz + co2now[x];

}
co2raw = zzz/10; //divide samples by 10
co2comp = co2raw - co2Zero; //get compensated value
co2ppm = map(co2comp,0,1023,400,5000); //map value for atmospheric levels

sd_file.print(hours);
sd_file.print(":");
sd_file.print(minutes);
sd_file.print(":");
sd_file.print(seconds);
sd_file.print(",");
sd_file.print(hum);
sd_file.print(",");
sd_file.print(temp);
sd_file.print(",");
sd_file.print(co2ppm, DEC);
sd_file.print(",");
sd_file.println(heat_index);

Serial.print(hours);
Serial.print(":");
Serial.print(minutes);
Serial.print(":");
Serial.print(seconds);
Serial.print(", ");
Serial.print(hum);
Serial.print(", ");
Serial.print(temp);
Serial.print(", ");
Serial.print(co2ppm, DEC);
Serial.print(", ");
Serial.println(heat_index);

if(seconds>=50) {
minutes= minutes + 1;
}

if (minutes>59) {
hours = hours + 1;
minutes = 0;
}

sd_file.flush(); //saving the file

delay(9000);
}
sd_file.close(); //closing the file
}

with this data i logged it on a sd card. my problem is when i want to go "offline"

mrDickson:
seems no problem with the wiring, like i said it work when its conecthed to the computer. think the problem is with my code..

Probably quite the opposite. While your first post is barely coherent, you have said the code works but apparently Arduino will not work when disconnected from the computer. There is nothing to suggest you have changed the code, so there is a lot to suggest there is nothing wrong with it. There is also a lot to suggest the only thing that HAS changed is the power supply, so that is likely to be the problem. Posting the wiring details is probably a good idea but, as a guess, either your 5v supply is inadequate, or incorrectly connected.

Having said that, and despite your saying it is OK, I have glanced at your code, and would be suss about

  sd_file.flush(); //saving the file

I think it is nonsense.

Quite some power is drawn by both the CO2 sensor (over 150 mA for just its heating element) and the SD card when writing (can be 300 mA).

What exact power supply do you use and how is it all connected?

In the middle of your code there are some spurious black dots. Please repost your code between code tags as per the instructions so it doesn't get munged by the forum software.

I agree with the suspicious others, as there is a rule that the problem nearly always is where the user thinks it isn't.

I agree with the suspicious others, as there is a rule that the problem nearly always is where the user thinks it isn't.

That is very true. When you finally track down a stubborn problem it is always in the bit that is “obviously” right. So -

seems no problem with the wiring, like i said it work when its conecthed to the computer. think the problem is with my code..

It is the same code running, you have to go some to write code that will work when connected to the computer and will not work when it is not. It is not something that happens by accident, it is only something where you are asking the computer to do something and are waiting for a reply.

i see.. :slight_smile:

i use a AC/DC 5V 3A.

the wiring, are:

A0 = Q135

7 = DHT11

10 = CS
11 = MOSI
12 = MISO
13 = SCK

all connected to 5V/GND

didnt notice the missing part of the code in the middle.. :slight_smile: here it is:

int co2now[10]; //int array for co2 readings
int co2raw = 0; //int for raw value of co2
int co2comp = 0; //int for compensated co2
int co2ppm = 0; //int for calculated ppm
int zzz = 0; //int for averaging
int grafX = 0; //int for x value of graph

for (int x = 0;x<10;x++){ //samplpe co2 10x over 2 seconds
co2now[x"]=analogRead(A0);
delay(1000);
}

for (int x = 0;x<10;x++){ //add samples together
zzz=zzz + co2now[x"];

}
co2raw = zzz/10; //divide samples by 10
co2comp = co2raw - co2Zero; //get compensated value
co2ppm = map(co2comp,0,1023,400,5000); //map value for atmospheric levels

sd_file.print(hours);
sd_file.print(":");
sd_file.print(minutes);
sd_file.print(":");
sd_file.print(seconds);
sd_file.print(",");
sd_file.print(hum);
sd_file.print(",");
sd_file.print(temp);
sd_file.print(",");
sd_file.print(co2ppm, DEC);
sd_file.print(",");
sd_file.println(heat_index);

mrDickson:
i see.. :slight_smile:

No, you very probably don't see. You have already said the code works when connected to the computer. Is that true or not? If it is true, you might start over by giving a concise summay of the reasons why you consider the code is suss. Failing that, you might plug Arduino back into the computer and report on the result. If it does work, again, you might have found some motivation for reading reply#3, amongst others, again. What have you done to change the situation? You have changed the power supply. Is the power suss? Very likely. Does your description of the wiring make any difference to that suspicion? Not really, as your verification of the adequacy of the connections is non-existent..

In the meantime, what happens when you connect the 5v,3A, to 5v and GND, any lights? Have you actually checked the voltages, or are you just guessing? In view of the code working, and 3A very likely to be adequate, a slack-arsed connection is a reasonable bet. I recognise that you appear to have cut yourself off from visual indication, a temporary LED activity light might help - or even repeating to LCD, but a $5 digital volt meter is a good thing to have right now.

How are the things powered, exactly? Connected to Arduino power pins, or directly to the power supply?

How does the power supply connect to the Arduino exactly?

A verbal description of the wiring is useless, especially the one you gave. It has no indication of what pins are connected to what sensors. Draw a diagram and answer questions asked of you.

IIRC- the USB from the PC cannot provide more than 500mA

if that is the case, power does not jump out as the issue.

that said, as a test, REM out the high power draw heater and try it with the other sensors.
just to eliminate that possibility.

can you post a photo of your set-up?

Also, others have mentioned how to post code. please visit 'how to use this forum' it is a sticky-post on the top of every forum. Item #7 shows to to use 'code tags' to post code.