Silícios LabPCBWay
Published © GPL3+

Data Collection System with SD Card and Arduino

You'll learn how to construct a data collection system of sensors using SD card with Arduino.

BeginnerFull instructions provided30 minutes9,344
Data Collection System with SD Card and Arduino

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1
SD Card Module - UTSOURCE
×1
UTSOURCE Arduino UNO R3
×1
UTSOURCE 330R Resistor
×3
UTSOURCE Push Button Micro Switch
×1
LED 5mm - UTSOURCE
×1
10kR Potentiometer - UTSOURCE
×1
Arduino UNO R3 - UTSOURCE
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Schematic of the Circuit - SD Card

Code

Alarm of the high-temperature

Arduino
#include <SD.h>
#include <SPI.h>

File myFile;

#define LEDSinal 7
#define buzzer 8
#define AnalogPin A0
int pinoSS = 10; // Pin 53 para Mega / Pin 10 para UNO

unsigned long int tempo_atual = 0; //Variavel utilizada para armazenar o tempo de execucao atual do codigo
unsigned long ultimo_tempo = 0; //Variavel utilizada para armazenar o ultimo valor armazenado na variavel tempo_atual

int DigitalValue = 0;

byte count = 0, samples = 0, value = 0;

bool state = 0, ButtonControl = 0, control = 0;

void setup() 
{ 

//Executado uma vez quando ligado o Arduino
pinMode(9, INPUT); //Config digital pin 9 as digital input
pinMode(buzzer, OUTPUT); //Config digital pin 8 as digital input
pinMode(LEDSinal, OUTPUT);

Serial.begin(9600); // Define BaundRate
pinMode(pinoSS, OUTPUT); // Declara pinoSS como saída
 
if (SD.begin()) { // Inicializa o SD Card
Serial.println("SD Card pronto para uso."); // Imprime na tela
}
 
else {
Serial.println("Falha na inicialização do SD Card.");
return;
}
 
//myFile = SD.open("usina.txt", FILE_WRITE); // Cria / Abre arquivo .txt 
 
}
 
void loop()
{
    bool pino = digitalRead(9);

    //Serial.println("SD Card pronto para uso."); // Imprime na tela
    
          //Condicao para detectar quando o botao e pressionado
          if(pino == 1 && control == 0 && ButtonControl == 0)
          {
              myFile = SD.open("usina.txt", FILE_WRITE); // Cria / Abre arquivo .txt
              delay(500);
              Serial.println("Entrou novamente...");
              ButtonControl = 1;
              value++;
              myFile.print("Amostragem: ");
              myFile.println(value); 
              samples = 0;
          }

      tempo_atual = millis();
    
          if((ButtonControl == 1) && (tempo_atual - ultimo_tempo >= 1000) && samples < 10 && control == 1)
          {
            Serial.println("Leitura de dados!"); // Imprime na tela
            DigitalValue = analogRead(AnalogPin);
            myFile.println(DigitalValue);
            control = 0;
            ultimo_tempo = tempo_atual;//Armazena o tempo atual
            samples++;
            digitalWrite(7, HIGH);
          }
      
          if(samples >= 10)
          {
            digitalWrite(7, LOW);
            myFile.close();
            ButtonControl = 0;
            digitalWrite(buzzer, HIGH);
            delay(300);
            digitalWrite(buzzer, LOW);
            delay(300);
          }
          
          control = control ^ 1;
}

Credits

Silícios Lab

Silícios Lab

73 projects • 176 followers
Hello, I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

94 projects • 149 followers
We are a PCB and assembly manufacturer, As low as $5/10pcs and 24 hours delivery time. We are committed to helping creators build project.

Comments