Greetings everyone!
So, I'm a Information Systems student from Brazil and my aunt is a teacher of an elementary school which every year has an event where the students come with a problem and a solution for this problem.
This year my aunt's students raised the problem of adults using a smartphone while driving their cars. Then, my aunt came to me looking for a solution where she could present her students to technology.
We thought about a little box that the parents could carry inside their cars and place their smartphones. If the parents took the smartphones out of the box, then a speaker would play their child voice saying something like: "Hey, dad, do not use your cellphone while driving, it's dangerous!".
As I didn't know anything about Arduino, I'd started to make some researches and, so far, I've done this:
The idea is:
- A photo resistor is placed on the bottom of the box;
- The pre-recorded file is stored in a micro SD card;
- If the photo resistor gets a lot of light, then there's no cellphone in the box and the pre-recorded file is played.
- If the photo resistor gets a low amount of light, then the cellphone is in the box and the pre-recorded file is stopped if it was being played.
I want to supply this circuit with a 9V battery.
What I want to know is this circuit and code are going to work as I want? And, also, if we will understand the audio file being played from the speaker.
Schematic:
Code:
#include <SPI.h>
#include <SD.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10 //defines the digital pin used by CS terminal of BT module
TMRpcm audio; //creates an object to the speaker library
const int checkEvery = 300; //loop interval in miliseconds
const int shadowThreshold = 500; //threshold to the foto resistor that will define if the cellphone is in or out the box
const int audioFile = "audio.wav"; //the audiofile to be played
void setup() {
audio.speakerPin = 9; //defining the speaker pin (it must be 9 in arduino uno)
audio.setVolume(6); //defining the volume (1 a 7)
pinMode(SS, OUTPUT);
Serial.begin(9600);
if(!SD.begin(chipSelect)) { //if the microSD can't be read
return; //do nothing
}
}
void loop() {
checkCel(shadowThreshold);
delay(checkEvery);
}
void checkCel(int shadowLevelLimit) {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue > shadowLevelLimit) { //if there's a low amount of light
if (audio.isPlaying()) { //if the audio file is being played
audio.disable(); //stops the sound
}
} else { //if there's a hight amount of incoming light
audio.play(audioFile); //play audio file
}
}
Thank you so much for your attention ![]()

