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 ...

Mixing Color with RGB LED!!

HELLO THERE!!!     Hi everybody!! How are you guys? This week, I am going to share with you guys a fun experiment that I did during the weekends. The objective of this experiment is to use the RGB LED to output different colors. Without wasting further time, let's get into the experiment!! HARDWARE: 1.Arduino UNO 2. 3 Potentiometer 3. RGB LED ( I used the Keyes RGB LED) SOFTWARE: 1.Arduino IDE CIRCUIT ASSEMBLY:   By referring to the image below: The RGB LED has 4 pins, 1 GND, 1 pin each for the color red, green and blue. RGB LED                      ----------> ARDUINO  GND(- sign of the pin)                  GND R,G,B                                              Any Digital pin(I used pin 9,10 and 11) T...

Arduino and Keyes KY-017 Mercury Tilt Sensor

HELLO THERE!!!     How are you guys? I hope everyone is fine and good as always. I am back in tinkering after a few months of hiatus( busy stuff :) ). So, today i would like to share with you guys on KY-017, which is a Keyes Mercury Tilt Sensor. KY-017 Sensor KY-017      The picture above shows the KY-017 Sensor from Keyes. It has 3 pins, A ground, A vcc, and A signal pin. If you look closely, there is a mercury ball inside the bulb like object. The mercury ball acts like a switch for this sensor. KY-017 Working Procedure: 1. When the sensor is not tilted, the mercury ball will be at the bottom of the bulb. This will complete the circuit and turns on the LED of the sensor. The output that is sent through the signal pin will be LOW. 2.When the sensor is tilted, the mercury ball will be at the top of the bulb(near at the sharper end). This will complete break circuit and turns off the LED of the sensor. The output that is sent through t...