For celebrating Arduino Day 20201 , here is an amazing mashup project: a Talking Useless Box called the Switch of Enlightenment.
Like all useless boxes, throwing the switch will cause a servo controlled arm to turn the switch back off after a random time delay.
In my build version, an ISD1760PY voice recorder is also triggered to utter some useless, but funny, comments or sound effects.
The ISD1760PY is unique as the voice recordings can be changed on the fly.
The ISD1760PY demo board has switches and a Electret microphone build in.
I did have to cobble the ISD1760PY so it could be hardwired to the Arduino Nano.
This version has a strobing bar LED to bring attention to the switch.
Here is the video showing it in action. The video also shows how the useless box was built and tested.
https://www.youtube.com/watch?v=ZeozFojEMJg
Here is the schematic
The code:
/*
TalkingUselessBoxWorks.ino
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 7; // variable increment LED Bar segment
int SwitchIsOn = LOW; //initiale var to LOW
int SwitchIsOnLastScan = LOW; //initiale var last scan's value to LOW
int RDY = HIGH ; //initiaze READY signal from ISD170 PY
long randNumber; // random number for servo to wait to flip switch
void setup() {
myservo.attach(4); // attaches the servo on pin 9 to the servo object
pinMode(2, OUTPUT); // falling edge triggered output to ISD1760PY voice card FWD input, selects next track. Pull LOW to trigger
pinMode(3, OUTPUT); // falling edge triggered output to ISD1760PY voice card PLAY input. Pull LOW to trigger
pinMode(5, INPUT); // ISD1760PY Ready signal. Pulled LOW when ISD is playing or busy. HIGH when available
pinMode(6, INPUT); // panel mounted toggle switch input. TRUE means Closed and starts the circus
pinMode(7, OUTPUT); //LED BAR segment 1
pinMode(8, OUTPUT); //LED BAR segment 2
pinMode(9, OUTPUT); //LED BAR segment 3
pinMode(10, OUTPUT); //LED BAR segment 4
pinMode(11, OUTPUT); //LED BAR segment 5
pinMode(12, OUTPUT); //LED BAR segment 6
pinMode(13, OUTPUT); //LED BAR segment 7
randomSeed(analogRead(1));//generate a random #
}
void loop() {
digitalWrite(3, HIGH); //start off with no chatting
digitalWrite(2, HIGH);
myservo.write(0);
for (pos = 7; pos <= 14; pos += 1)
{
digitalWrite(pos, HIGH); // sets the "scanner" LED bar segment on
SwitchIsOn = digitalRead(6); // read the input pin value to start operation
RDY = digitalRead(5); // read the input pin 5 value ,connected to RDY signal of ISD1760PY. TRUE is ready to play
if ((SwitchIsOn == HIGH) && (RDY==HIGH)) ///may need to one shot the switch input
{
// blank the LEDs while the cycle executes
digitalWrite(7, LOW); //
digitalWrite(8, LOW); //
digitalWrite(9, LOW); //
digitalWrite(10, LOW); //
digitalWrite(11, LOW); //
digitalWrite(12, LOW); //
digitalWrite(13, LOW); //
// PLAY TRACK
digitalWrite(3, LOW); // trigger sound card message , pull PLAY input to ground
delay (50); //set trigger width, debounce time = 192/Fs, figure worst case = .048msec
digitalWrite(3, HIGH); // trigger sound card message falling edge
randNumber = random(1500,5000);
delay(randNumber); // add some small randomness for turning off the main switch, give the soundtrack some time to start playing
HitSwitch(); // turn the switch off
// wait for track to finish
RDY = digitalRead(5); // read the input pin value of the ISD1760PY Ready signal TRUE is Ready
while (RDY == LOW) // keep checking to see of track is done playing
{delay (5);
RDY = digitalRead(5);
}
// increment to next track when ready
FWDtoNextMessage(); // pulse output to FWD
}
delay (30); //on time of LED bar segment
digitalWrite(pos, LOW); // turns off LED segment
}
}
void HitSwitch ()
{
myservo.write(0);
delay(5); // spaceholder for inserting randomness to speed and response time
myservo.write(90); // tell servo to go to trip switch position
delay(300); // waits 15ms for the servo to reach the position
myservo.write(0); // tell servo to go back to home position
}
void FWDtoNextMessage()
{
digitalWrite(2, LOW); // increment to next sound card message, pull FWD input to ground
delay (40); //set trigger width, debounce time = 192/Fs, figure worst case = .048msec
digitalWrite(2, HIGH); // sound card message falling edge
delay(100); // LED flash time head start for 1760PY to load in new signal
}
Top Comments