Skip to main content

Arduino Beginner Experiments: Graphing and Data Logging Big Sound Sensor Data

HELLO THERE!!!

      How are you guys? I hope everyone is fine and in good mood always. This week, I wanted to show you guys an experiment I made throughout the weekend. Continuation of last week's experiment, this week, I decided to make a graph out of my output and log the data into a SDcard. Let's get to the specifics without wasting any further time.

HARDWARE:
1.Arduino UNO
2.Big Sound Sensor

3. Ethernet Shield/ MicroSD Shield/ Any board with Micro SD slot ( I used and will concentrate the ethernet Shield for this post)
4.MicroSD Card

SOFTWARE:

1.Arduino IDE
2.Processing IDE (download here:https://processing.org/download/)

CIRCUIT ASSEMBLY:

OK,  the circuit is assembled as follows:

1. Plug in the Ethernet Shield on top of your Arduino
2. Connect the Big Sound sensor as follows:

SENSOR                                   ARDUINO
A0                  ----------->          Analog pin A0
G                    ----------->          GND
+                    ------------>          5V





The circuit assembly( sorry for the mess :) ) 

BEFORE CODING:

    Before coding the Arduino, create a text file in the SD Card. Name the text file anything you wanted (make sure you put the same name in the code). Then, plug in the SD Card to the ethernet shield



CODING THE ARDUINO:


  I would like to divide this into two parts:

a)ARDUINO CODE:





#include <SPI.h>
#include <SD.h>
int chipSelect = 4;
int bgsound = A0;
int sensorval;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);


  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop() {
  // make a string for assembling the data to log:
  String dataString = "";

  // read the big sound sensor ( any sensor you have also can be used here)
  
     bgsound = analogRead(sensorval);
    dataString += String(bgsound);
    

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("bgsound.txt", FILE_WRITE);// Change the txt file name according 
//to the txt file in your sdcard

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening text file");
  }
}


b)PROCESSING CODE:

import processing.serial.*;


Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph
float inByte = 0;

void setup () {
  // set the window size:
  size(800, 500);

  // List all the available serial ports
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
   myPort = new Serial(this, "COM2", 9600);  

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // set inital background:
  background(255,255,255);
}
void draw () {
  // draw the line:
  stroke(255, 0, 0);//rgb
  line(xPos, height-10, xPos, height-10 - inByte);

  // at the edge of the screen, go back to the beginning:
  if (xPos >= width) {
    xPos = 0;
    background(255,255,255);
  } else {
    // increment the horizontal position:
    xPos++;
  }
}


void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }
}


   Upload the Arduino Code to your Arduino and then run the Processing code. This is what I get as the output of the experiment:
The Graphical output which reads the Arduino Analog Input.



The text file in the SD Card.




A short demo video is shown as below:








Well, that's all from me this week guys. I hope to see you guys next week. Till then, HAPPY TINKERING!!!

Comments

Popular posts from this blog

Arduino and Multi Function Shield: Pots,LEDs and buzzers

HELLO THERE!!!!!    How are you guys? I hope everyone is fine and in good mood always. This week, I continue my tinkerings with the Multi Function Shield. In this experiment, I used the potentiometer in the shield to control the LEDs in the shield. Without further wasting time, let's jump in straight to the experiment!! HARDWARE 1.ARDUINO UNO  2.MULTI-FUNCTION SHIELD SOFTWARE: 1. ARDUINO IDE CIRCUIT ASSEMBLY    The circuit assembly is fairly simple. Just attach the multi function shield on top of Arduino properly. Please attach the shield properly as failure to do so would cause the shield  not to function as intended. CODING THE ARDUINO: Let's refer to the multi-function shield image below: Referring to the image of the shield, it can be seen that the potentiometer (blue object near buttons) is connected to pin A0 (analog 0)     int pot = A0; //declaring the pot and led pins int l1 = 13; int l2

Arduino Beginner Experiments: Arduino and Light Blocking Sensor

HELLO THERE!!!     How are you guys? I hope everyone is fine and in a good mood always. This week, I would like to share with you guys my experiment on Arduino and Light Blocking Sensor. The objective of this experiment is to receive feedback from the sensor ( Digital and Analog) What is Light Blocking Sensor?      A linear hall sensor is a type of sensor which responds when the sensor is blocked out from light. The sensor is different for LDR's as LDR's responds to the amount of light it received while the light blocking sensor responds if the light is blocked out or not from the sensor.It can be used for both digital and analog measurements. HARDWARE: 1.Arduino UNO 2. Light Blocking Sensor SOFTWARE: 1.Arduino IDE CIRCUIT ASSEMBLY   Let's refer to the image of the blocking sensor below: The Connection of the Sensor to the Arduino is shown below: SENSOR  ----->       ARDUINO Signal      ------>     Any Analog/Digital pin

Arduino Tinkering : Controlling multiple LED with multiple potentiometers

HELLO THERE!!!!            How are you guys? I hope everyone is fine and well always. For this week's post, I would like to share with you guys a simple tinkering on Arduino, LED, and potentiometers. The objective of the experiment is to light up different amount of LED's with different intensity by controlling two potentiometers. Before starting, of course, we need to know what items are needed. The items needed are: 1. Arduino UNO   2. 4 to 5 LEDs 3. 2 Potentiometers The software used in this experiment is: 1. Arduino IDE. Now that all the hardware and software are obtained, let's go to the schematics of the circuit. The circuit is quite simple actually. The long legs of the LED's were connected to PWM pins while the shorter legs were connected to ground. The potentiometers however have three legs. The middle leg is connected to the analog pins (A0, A1) while the other two legs were connected to 5V and GND respectively. Don't w