Salah UddinIoT-Bangladesh
Published © LGPL

Water Purification Level Testing Device for Blind Person

A portable device for visually impaired persons, which helps them to determine the purification level of drinking water.

IntermediateFull instructions providedOver 1 day949
Water Purification Level Testing Device for Blind Person

Things used in this project

Hardware components

Spresense boards (main & extension)
Sony Spresense boards (main & extension)
×1
Electrical Conductivity Probe
×1
Seeed Studio Grove - Button
×1
Speaker: 3W, 4 ohms
Speaker: 3W, 4 ohms
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Circuit Diagram

Reference circuit diagram (check the PIN diagram section for actual pin diagram)

Code

Source Code

Arduino
/*Modified version for water purity level tester
  * Mohammad salah uddin
  * March 04, 2019
  */



/*
 *  player.ino - Simple sound player example application
 *  Copyright 2018 Sony Semiconductor Solutions Corporation
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

 
#include <SDHCI.h>
#include <Audio.h>

SDClass theSD;
AudioClass *theAudio;

File myFile0, myFile1;

const int buttonPin = 8;
int buttonState = 0;

bool ErrEnd = false;

const float ArduinoVoltage = 5.00; // CHANGE THIS FOR 3.3v Arduinos


const float ArduinoResolution = ArduinoVoltage / 1024;


const float resistorValue = 10000.0;
int threshold = 3;


int inputPin = PIN_A0;

int outputPin = PIN_A5;


/**
 * @brief Audio attention callback
 *
 * When audio internal error occurc, this function will be called back.
 */

static void audio_attention_cb(const ErrorAttentionParam *atprm)
{
  puts("Attention!");
  
  if (atprm->error_code >= AS_ATTENTION_CODE_WARNING)
    {
      ErrEnd = true;
   }
}

/**
 * @brief Setup audio player to play mp3 file
 *
 * Set clock mode to normal <br>
 * Set output device to speaker <br>
 * Set main player to decode stereo mp3. Stream sample rate is set to "auto detect" <br>
 * System directory "/mnt/sd0/BIN" will be searched for MP3 decoder (MP3DEC file)
 * Open "Sound.mp3" file <br>
 * Set master volume to -16.0 dB
 */
void setup()
{
  Serial.begin(115200);
  pinMode(outputPin, OUTPUT);
  pinMode(inputPin, INPUT);


  
  // start audio system
  theAudio = AudioClass::getInstance();

  theAudio->begin(audio_attention_cb);

  puts("initialization Audio Library");

  /* Set clock mode to normal */
  theAudio->setRenderingClockMode(AS_CLKMODE_NORMAL);

  /* Set output device to speaker with first argument.
   * If you want to change the output device to I2S,
   * specify "AS_SETPLAYER_OUTPUTDEVICE_I2SOUTPUT" as an argument.
   * Set speaker driver mode to LineOut with second argument.
   * If you want to change the speaker driver mode to other,
   * specify "AS_SP_DRV_MODE_1DRIVER" or "AS_SP_DRV_MODE_2DRIVER" or "AS_SP_DRV_MODE_4DRIVER"
   * as an argument.
   */
  theAudio->setPlayerMode(AS_SETPLAYER_OUTPUTDEVICE_SPHP, AS_SP_DRV_MODE_LINEOUT);

  /*
   * Set main player to decode stereo mp3. Stream sample rate is set to "auto detect"
   * Search for MP3 decoder in "/mnt/sd0/BIN" directory
   */
  err_t err = theAudio->initPlayer(AudioClass::Player0, AS_CODECTYPE_MP3, "/mnt/sd0/BIN", AS_SAMPLINGRATE_AUTO, AS_CHANNEL_STEREO);
  err_t err1 = theAudio->initPlayer(AudioClass::Player0, AS_CODECTYPE_MP3, "/mnt/sd0/BIN", AS_SAMPLINGRATE_AUTO, AS_CHANNEL_STEREO);


  /* Verify player initialize */
  if (err != AUDIOLIB_ECODE_OK)
    {
      printf("Player0 initialize error\n");
      exit(1);
    }

  /* Open file placed on SD card */
  myFile0 = theSD.open("pure.mp3");
  myFile1 = theSD.open("not_pure.mp3");

  /* Verify file open */
  if (!myFile0 && !myFile1)
    {
      printf("File open error\n");
      exit(1);
    }
  // printf("Open! %d\n",myFile0);

  /* Send first frames to be decoded */
  err = theAudio->writeFrames(AudioClass::Player0, myFile0);
  err1 = theAudio->writeFrames(AudioClass::Player0, myFile0);

  if ((err != AUDIOLIB_ECODE_OK) && (err != AUDIOLIB_ECODE_FILEEND))
    {
      printf("File Read Error! =%d\n",err);
      myFile0.close();
      exit(1);
    }

  puts("Play!");

  /* Main volume set to -16.0 dB */
  theAudio->setVolume(-160);
  theAudio->startPlayer(AudioClass::Player0);
  pinMode(buttonPin, INPUT);
}

int TDS()
{
  int value;
  int analogValue=0;
  int oldAnalogValue=1000;
  float returnVoltage=0.0;
  float resistance=0.0;
  double Siemens;
  float TDS=0.0;

while(((oldAnalogValue-analogValue)>threshold) || (oldAnalogValue<50))
{
 oldAnalogValue = analogValue;
 // digitalWrite( outputPin, HIGH );
 analogWrite( outputPin, 1000 );
 delay(10); // allow ringing to stop
 analogValue = analogRead( inputPin );
 // digitalWrite( outputPin, LOW );
 analogWrite( outputPin, 0 );
}

// Serial.print("Return voltage = ");
returnVoltage = analogValue *ArduinoResolution;  
// Serial.print(returnVoltage);
// Serial.println(" volts");


// Serial.print("That works out to a resistance of ");
resistance = ((5.00 * resistorValue) / returnVoltage) - resistorValue;
// Serial.print(resistance);
// Serial.println(" Ohms.");


// Serial.print("Which works out to a conductivity of ");
Siemens = 1.0/(resistance/1000000);
// Serial.print(Siemens);
// Serial.println(" microSiemens.");
// Serial.print("We can estimate Total Dissolved Solids to be on the order of ");
TDS = 500 * (Siemens/1000);
// Serial.println(TDS);
// Serial.println(" PPM.");
// if(returnVoltage>4.9) Serial.println("Are you sure this isn't metal?");
value = TDS;
  return value;
}

/**
 * @brief Play stream
 *
 * Send new frames to decode in a loop until file ends
 */
void loop()
{
  puts("loop!!");
  buttonState = digitalRead(buttonPin);
 
  if (buttonState == HIGH) {

    if(TDS() <= 199){

     /* Send new frames to decode in a loop until file ends */
  int err = theAudio->writeFrames(AudioClass::Player0, myFile0);
  
  /*  Tell when player file ends */
  if (err == AUDIOLIB_ECODE_FILEEND)
    {
      printf("Main player File End!\n");
    }

  /* Show error code from player and stop */
  if (err)
    {
      printf("Main player error code: %d\n", err);
      goto stop_player;
    }

  if (ErrEnd)
    {
      printf("Error End\n");
      goto stop_player;
    }
    }
    else{


     /* Send new frames to decode in a loop until file ends */
  int err = theAudio->writeFrames(AudioClass::Player0, myFile1);
  
  /*  Tell when player file ends */
  if (err == AUDIOLIB_ECODE_FILEEND)
    {
      printf("Main player File End!\n");
    }

  /* Show error code from player and stop */
  if (err)
    {
      printf("Main player error code: %d\n", err);
      goto stop_player;
    }

  if (ErrEnd)
    {
      printf("Error End\n");
      goto stop_player;
    }


      
    }

  /* This sleep is adjusted by the time to read the audio stream file.
     Please adjust in according with the processing contents
     being processed at the same time by Application.
  */
      
  }
  
  
 
  usleep(40000);


  /* Don't go further and continue play */
  return;

 stop_player:
  sleep(1);
  theAudio->stopPlayer(AudioClass::Player0);
  myFile0.close();
  exit(1);
}

Credits

Salah Uddin

Salah Uddin

44 projects • 146 followers
Technology and IoT Hacker, Robot Killer and Drone lover.
IoT-Bangladesh

IoT-Bangladesh

19 projects • 49 followers

Comments