Arduino Introduction

I’m describing the situation where I would need my sound volume detector in my storyboard in the attached scanned Pdf image. I wanted to build a sensor that would tell me if my laptop music volume was too high and disturbing my roommates as often they are studying at home.


I started by taking a micro-phone sensor and attaching it to the Arduino. Then I connected an LCD display that would print the volume level as ‘Very Low’, ‘Low’, ‘Medium’, ‘High’ and ‘Very High’ depending on the ranges defined by my thresholds. I used an example in the basics section of the Arduino to get the code for the microphone and the IC2 library for the LCD display. I combined the code from these two source files and added my own logic to give my project the functionality of a volume detector. The LCD address had to be changed to 0x3F.



 At first, the LCD screen showed ‘Low’. When I spoke into the microphone, however, ti momentarily changed to ‘Medium’ and started showing ‘Lowium’ after that, a combination of ‘Low’ and ‘Medium’. So I added code to clear the lcd before displaying anything at the start of the loop. This however, would give flicker the ‘Low’ on the screen now as it was coming on and going off when I cleared it.  The ‘Lo’ in the picture below shows that the ‘w’ is coming on and going off. 


So to fix this I added another variable ‘levelValue’ aside from the thresholds that mapped the number 1,2,3,4 and 5 to ‘Very Low’, ‘Low’, ‘Medium’, ‘High’ and ‘Very High’ respectively. On changing what was showed on the lcd screen, I would change levelValue as well and then check to see if levelValue was different from the mapping for this level on the next iterations of the loop before clearing the screen and setting a new levelValue and changing what was displayed on the screen. This solved the flickering problem and I could see the full word on display now. Also two inputs on the back of my Arduino did not have a black solid holding them together so that also caused my Arduino to heat up the first time. I used the black casing to cover the two inputs together. 

//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

int threshold1 = 100;
int threshold2 = 200;
int threshold3 = 300;
int threshold4 = 400;
int levelValue = 0;

void setup()
lcd.init(); // initialize the lcd
// Print a message to the LCD.

void loop()
{ // read the input on analog pin 0:

int sensorValue = analogRead(A0);
// print out the value you read:
delay(1); // delay in between reads for stability
lcd.print(“Very low”);
levelValue = 1;

else if(sensorValue>=threshold1&&sensorValue<threshold2){
levelValue = 2;

else if(sensorValue>=threshold2&&sensorValue<threshold3){
levelValue = 3;

else if(sensorValue>=threshold3&&sensorValue<threshold4){
lcd.setCursor(3, 0);
lcd.print(“Slightly High”);
levelValue = 4;

lcd.setCursor(3, 0);
levelValue = 5;



As a CS major, I have done coding problems but they have mostly been in computer architecture, app design or algorithms. This was the first time I was programming for hardware and I enjoyed solving the practical problem of the ‘flickering’ light. It made me see that I needed to picture what the lcd screen would actually do and not just what I think it will do in my abstract idea of the code.  Also useful was to learn to think of a practical problem to build something useful. A few days ago my music had been too loud and my roommate had asked me to turn the volume down, so I found it insightful to think back to my everyday life to come up with an idea for the project and rather simple too. It is always fun to think of logical ways to solve a problem you have, so creatively figuring out how to get the lcd screen to stop flickering was fun. That’s my favorite thing about code. It’s logic and creativity combined.