Triggering FX Soundboard with Bend Sensor

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Triggering FX Soundboard with Bend Sensor

Post by TryChick »

I have an Iron Man glove I am working on that has a hand plate with a bend sensor under it. When I flex my wrist backwards, the bend sensor sends a signal which passes through a 10K resistor and connects to my Pro Mini to turn on my "repulsor light" in the glove. The light portion works the way I want it to; however, I'd like to split the signal after the resistor so the signal also goes to my FX soundboard https://www.adafruit.com/products/2210 to create a "repulsor blast" sound effect at the same time. My question is, do I need anything else between the signal and the input pin on the FX soundboard to protect the board/make it work the way I want?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by adafruit_support_mike »

You'll have better luck using the signal that controls the LED.

The flex sensor's output will change gradually, so it's hard to be sure exactly when it will go low enough to trigger the FX board.

If you wire the LED for active-low logic (the LED comes on when the pin from the Pro Mini goes LOW), you can use the same control signal for the LED and the FX board.

If you can spare a pin on the Pro Mini to control the FX board directly, it will give you more flexibility to control the LED. You'll be able to use PWM to have the light fade up or pulse in time with the sound effect.

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

Hm, I think I know what you mean. Currently the amount of bend from the sensor controls how much light is emitted from the repulsor so it gets brighter as the sensor is bent more since I have the light brightness mapped to the amount of bend. As soon as I bend my wrist the light starts fading up. If my wrist is kept back, the light stays on. When my wrist returns to an straight position it gradually goes off. Though it tends to fade up/down too quickly/jerkily, probably because the sensor readings jump erratically and rapidly when I bend my wrist even a little bit, so the fade isn't very obvious.

Are you saying that as soon as the sensor sends a signal to the G4 bulb I'm using for the repulsor light, have the pro mini gradually fade to full brightness while triggering sound by sending a LOW signal from the pro mini to the FX board? I do have unused pins on the pro mini so that wouldn't be a problem.

Unless there is a way to "smooth" the readings from the sensor to slow the fade, I'm thinking your suggestion would definitely generate a smoother fade to brightness/dark if I just triggered the start of the fade using the sensor signal and didn't actually tie the increased output to the amount of bend in the sensor, but brought it up gradually. As soon as the lights start fading up also trigger the sound. When the sensor starts getting unbent, then gradually fade out.


Something like this?

Code: Select all

 // This sketch operates Iron Man glove to light up repulsor beam and play repulsor sound
 
//declare constants for pin assignment
const int flexSensor = 0;  // Pin A0 for flex sensor 
const int repulsorLight = 6;   // Pin 6 for repulsor light 
const int soundTrigger = 5 //Pin for Adafruit FX sound board Trigger

//declare variables
int sensorReading = 0;        //analog reading from sensor
int repulsorBrightness = 0;   //variable to store how bright light is
int lastRepulsorBrightness = 0; //variable to store last repulsor brightness

void setup(){
  
// initialize serial communications
	Serial.begin(9600); 
        
//set pin 6 as repulsorLight output
	pinMode(repulsorLight,OUTPUT);  
  
//set pin 5 as sound trigger output
	pinMode(soundTrigger,OUTPUT);  
	digitalWrite(soundTrigger, HIGH);//set it to HIGH
  
}

void loop(){
   
//set sensorReading to the reading of the flex sensor
	sensorReading = analogRead(flexSensor);
  
/*change range of analog reading (0-1023) to range used by analogWrite (0-255)
  use map function to calibrate this sensor reads 720 for straight and 830 for 90 degrees*/
	repulsorBrightness = map(sensorReading, 179 ,276, 0, 255);

//if flex sensor is below 177 set brightness to zero
  if(repulsorBrightness < 177){ 
    repulsorBrightness =0; 
    }
    
 //set all repulsorBrightness readings over 255 to the max value analogWrite value
  if(repulsorBrightness >255){
    repulsorBrightness = 255;
  }
 
 //gradually fade up repulsor LEDs if flex sensor is bent
	if(repulsorBrightness > 177){
	int a;
	for(a = 0; a<=255; a++){
		analogWrite(repulsorLight, a);

	//Once brightness gets to 100 trigger the sound 
		if(a > 100){  
			digitalWrite(soundTrigger, LOW);//set pin to LOW
			digitalWrite(soundTrigger, HIGH);//reset pin to HIGH
		}
 
	//keep repulsor on bright if flex sensor remains (mostly) bent 
		if(repulsorBrightness > 245){//allow 10 for erratic sensor readings
		  analogWrite(repulosrlight,255);
		  lastRepulsorBrightness = 255; //use as comparison for fading out
		  }
  }
  }
  //fade repulsor light
  if (repulsorBrightness < lastRepulsorBrightness - 10){//10 allows for erratic sensor readings
  
   for(int a = 255, a > 0 ; a--){ 
     analogWrite(repulosrlight, a)
  }
  }
                         
}

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by adafruit_support_mike »

Yeah, that looks like it would work.

One thing to note: the human eye's response to light is logarithmic rather than absolute.. we perceive brightness in terms of ratios rather than specific amounts. Twice as many photons are about "one step brighter" whether it's a change of 1 photon to 2 (which we can see) or 10 million to 20 million (a moderately sunny day).

If you ramp your LED values up on a linear scale:

Code: Select all

   for(a = 0; a<=255; a++){
      analogWrite(repulsorLight, a);
      [...]
you'll see most of the change between values of a=0 and a=64.

If you increase it in terms of a ratio:

Code: Select all

   for(a = 1; a<=255; a *= 2){
      analogWrite(repulsorLight, a);
      [...]
you'll see a smoother fade, but it will take place in fewer steps (8 rather than 256).

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

I can't seem to make this work. I swapped out my flex sensor for a reed switch so now I have a more stable digital signal to use as a trigger for both light and sound, but my sound still isn't working. My light does fade up, but I hear a constant clicking sound from my speakers and the light flickers with the clicking. I'm not sure what is wrong with my wiring. After reading through another thread

viewtopic.php?f=19&t=62447&p=317604&hil ... d+#p317604

where you said:
Connect the Arduino's GND to the FX board's GND, then connect one of the Arduino's digital output pins to the FX board input you want to control.

Sending the Arduino pin LOW will have the same effect as closing a switch between the FX input and GND.
I attempted to wire per your suggestion and modified my code, but something still isn't correct. I posted a picture of my wiring.
labeledbread.JPG
labeledbread.JPG (110.42 KiB) Viewed 1147 times

Code: Select all

 //Declare constants
const int soundTrigger = 10;//pin for soundTrigger 
const int reedSwitch = 5;//pin for reed switch 
const int repulsorLight = 6;//pin for light
int fadeAmount = 1; //amount of fade

//declare variables

int brightness; //variable to store how bright repulsor light is
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
unsigned long currentMillis;
int sensorState; //reed switch HIGH or LOW

void setup(){
    
  //declare pin 6 to be repulsorLight output and set to off
  pinMode(repulsorLight, OUTPUT);
  digitalWrite(repulsorLight, LOW);
    
  //declare pin 5 to be reedSwitch input
  pinMode(reedSwitch, INPUT);
   
  //declare pin 10 to be soundTrigger output
 pinMode(soundTrigger, OUTPUT);
 digitalWrite(soundTrigger, HIGH);
 
 brightness = 0; //set initial brightness to 0 (off)

}

//function to sound repulsor blast
void repulsorBlast(){
  
  previousMillis2 = currentMillis ;
  digitalWrite(soundTrigger, LOW); //pull pin low
  if(currentMillis - previousMillis2 >=50) //delay 50 millis to allow trigger
    digitalWrite(soundTrigger, HIGH); //reset pin to high
}

void loop(){
  
   currentMillis = millis();
   
   sensorState = digitalRead(reedSwitch); //continually read the state of the reed switch
   
 
   if(sensorState == HIGH){  
 //fade up repulsor to full bright
 if(currentMillis - previousMillis > 90 && brightness <= 127){
 //brightness values: 1,3,7,15,31,63,127,255
     analogWrite(repulsorLight, brightness);
     brightness = brightness + fadeAmount;
     
     if(brightness == 63){
       repulsorBlast(); //call function for sound
     }
        
     fadeAmount = fadeAmount * 2;
     previousMillis = currentMillis;
      
      }
   }
    
  else{
    digitalWrite(repulsorLight,LOW);
  }
  }

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by adafruit_support_mike »

That's an amazingly good wiring breakdown! Thank you for tagging the lines so I don't have to try and trace them all in my head.

I don't see an external pull-up resistor at the point where your reed switch connects to pin 5 on the Pro Mini, and you haven't told the microprocessor to enable an internal pull-up in the code.

Try connecting a 10k resistor between the Pro Mini's pin 5 and its VCC pin (you can also put the resistor between pins 4 and 5 and configure pin 4 as OUTPUT/HIGH).

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

Mike,

On LEG 1 of the reed switch, my wiring splits and one wire (blue and white) has an in-line 10K resistor. That wire is the one going to ground, the other wire coming off of that leg (green) connects to pin 5 and LEG 2 connects to vcc. Should have mentioned it on the last post. Here is an updated wiring pic with changes to labels in red.
newbreadboard.JPG
newbreadboard.JPG (114.36 KiB) Viewed 1141 times

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

Mike,
I disassembled my breadboards and reassembled, adding a piece at a time to troubleshoot. I got the soundboard and Arduino working together with some modifications to my original wiring and code. It worked while using my laptop to power through my USB, when I swapped to battery, I got more of the clicking sound and the soundboard wouldn't work. Swapping back to USB it worked again. Could this indicate a short somewhere in the battery wiring? I attached another image. This shows the current set up. The changes I made were to only use 2 leads from the reed switch, one with an in-line resistor that goes to pin 5 and the other goes to ground.
newbreadboard.JPG
newbreadboard.JPG (130.5 KiB) Viewed 1120 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by adafruit_support_mike »

That does sound like a power issue.

What kind of battery are you using?

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

It is an A23 (looks like a short AAA). It is in a battery holder I bought on line and it is wired to one of your tactile on/off switch with leads https://www.adafruit.com/products/1092. Before connecting the battery, I disconnect the FTDI basic breakout board I'm using to upload sketches/power via USB from my laptop, but leave it connected to the mini. The RX and TX lights on the breakout board flash a couple of times when the battery switch is flipped on.

Update: I used a different battery holder with no switch, then connected a different speaker directly to the soundboard thinking the wiring might have been compromised somehow, but I still heard the clicking sound after making those changes. Next, I replaced the wires to the speakers (went back to original ones), reed switch and light noticing some fraying after all the plugging and unplugging. When I reconnected everything I still got the clicking noise. So I disassembled again, leaving only the reed switch and speakers wired to the mini and sound board and powered them from the USB cable. Worked fine with the reed switch triggering the sound. Then I unplugged the USB to power from the battery. Again there was the clicking sound. Disconnected the battery and reconnected USB to power and continued to get the clicking sound despite having disconnected it from the battery. I don't get it.

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

I was able to get the lights and sound working together as long as the lights were the only thing getting power from the 12v battery. Powering the mini and the soundboard either through the USB or a 9v fed into the raw pin of the mini works fine. My set up with the 3.3v step down regulator worked fine when all I had connected were the lights and the mini. For some reason, adding the soundboard creates issues. I'm wondering if the 12v battery wasn't providing enough juice for everything...

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by adafruit_support_mike »

That's entirely possible.. the clicks could be momentary brownouts.

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

IMG_8882.jpeg
IMG_8882.jpeg (394.42 KiB) Viewed 994 times
IMG_8880.jpeg
IMG_8880.jpeg (327.41 KiB) Viewed 994 times
I'm still trying to get this soundboard to work in my Iron Man gauntlet. I tested the board using a button to trigger the sound and it plays fine that way. But when I hook it up to my pro mini and try to trigger the repulsor sound by pulling pin 10 low, I see no red LED flash indicating a signal has been sent to trigger the sound, though I know the sensor is working correctly since my light is fading up and down at the correct time. Not sure what I am doing wrong here. Previously I thought the components needed more power than they were getting so I am now using two power sources: one 12v A123 for the light and 3AA for the 3.3v ProMini and the soundboard.

Link to video to show what is going on.
https://www.youtube.com/watch?v=yftaXLx ... e=youtu.be

Code: Select all

//Declare constants
const int soundTrigger = 10;//ProMini pin for soundTrigger connected to FX pin 9
const int reedSwitch = 4 ;//pin for reed switch 
const int repulsorLight = 6;//pin for light


//declare variables
int sensorState = 1; //reed switch HIGH (1) or LOW (0) to trigger sound
int soundTriggerState; //debugging to find the state of the sound trigger pin
int fadeUpAmount = 1; //amount of fade up
int fadeDownAmount = 256;//amount of fade down
int brightness = 0; //variable to store how bright repulsor light is
unsigned long currentMillis;//used to control speed of fade up/down (current time)
unsigned long previousMillis = 0;//used to control speed of fade up/down (time of last fade)

void setup(){
   Serial.begin(9600);   
  //declare reedSwitch as an input & activate internal pullup resistor
  pinMode(reedSwitch, INPUT);
  digitalWrite(reedSwitch, HIGH); 
      
  //declare soundTrigger oas an utput and & activate internal pullup resistor
  pinMode(soundTrigger, OUTPUT);
  digitalWrite(soundTrigger, HIGH); 
 
  //declare repulsorLight as an output and set to LOW (off)
  digitalWrite(repulsorLight, LOW);
  pinMode(repulsorLight, OUTPUT);
 
}

void loop(){
  Serial.print("SensorState:  ");
  Serial.print(sensorState);
  Serial.print("     ");
  Serial.print("Brightness:  ");
  Serial.println(brightness);
  sensorState = digitalRead(reedSwitch); //read the state of the reed switch
 
   
   //code to control lights and sound for the right side 
  if(sensorState == LOW){//wrist is bent
   
    currentMillis = millis(); 
    
    fadeDownAmount = 127;//reset the fade down amount for next fade down
        
   //if(currentMillis - previousMillis > 30 && brightness < 255){ 
    if(currentMillis - previousMillis > 30 && brightness <= 127){ 
      //brightness values: 1,3,7,15,31,63,127,255 with (fadeUpAmount = fadeUpAmount * 2)
      brightness = brightness + fadeUpAmount;//increase brightness each time through the loop
       
      analogWrite(repulsorLight, brightness);
      
      if(brightness == 255){ 
        
        digitalWrite(soundTrigger, LOW);//pull pin LOW
      ///////////////////
         if (digitalRead(soundTrigger) == LOW){
           Serial.println("SoundTriggerState is LOW   1");
         } else
         Serial.println("SoundTriggerState is HIGH   1");
        ////////////////////////////// 
         delay(300);//hold for a second to allow soundboard to receive signal 
                      
        digitalWrite(soundTrigger, HIGH);//reset to HIGH
     //////////////////////////
        if (digitalRead(soundTrigger) == LOW){
           Serial.println("SoundTriggerState is LOW   2");
         } else
         Serial.println("SoundTriggerState is HIGH   2");
         ///////////////////////////////////
       }   
      
      fadeUpAmount = fadeUpAmount * 2;
      
      previousMillis = currentMillis;
      
     }
 
  }
  if(sensorState == HIGH){//wrist is straight
  
    fadeUpAmount = 1;//reset for next fade up
    
    if(brightness == 255){//keep light on for 5 seconds before fading down
    
     delay(500);
    } 
    
    currentMillis = millis();  
 
    if(currentMillis - previousMillis > 30 && brightness > 0){
    
     brightness = brightness / 2;//reduce brightness by half each time through the loop
              
     analogWrite(repulsorLight, brightness);
        
      if(brightness <= 0){
        
         digitalWrite(repulsorLight, LOW);//set repulsor to low
         
         brightness = 0;//reset to off for next fade up
      
       }
       
      previousMillis = currentMillis;
               
    }
  } 
}
       

I used Cool Term to copy my output to show what I'm getting with the sensors
I did power the set up via USB to get the data, but I know the soundboard doesn't work when connected via USB, so I then tested with the ProMini and Soundboard powered by a 9v.


SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 0 Brightness: 1
SensorState: 0 Brightness: 3
SensorState: 0 Brightness: 7
SensorState: 0 Brightness: 15
SensorState: 0 Brightness: 31
SensorState: 0 Brightness: 63
SensorState: 0 Brightness: 127
SoundTriggerState is LOW 1
SoundTriggerState is HIGH 2
SensorState: 0 Brightness: 255
SensorState: 1 Brightness: 127
SensorState: 0 Brightness: 127
SensorState: 0 Brightness: 127
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 0 Brightness: 128
SensorState: 1 Brightness: 64
SensorState: 1 Brightness: 32
SensorState: 0 Brightness: 33
SensorState: 0 Brightness: 35
SensorState: 0 Brightness: 39
SensorState: 0 Brightness: 47
SensorState: 0 Brightness: 63
SensorState: 1 Brightness: 31
SensorState: 1 Brightness: 15
SensorState: 1 Brightness: 7
SensorState: 1 Brightness: 3
SensorState: 1 Brightness: 1
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
SensorState: 0 Brightness: 1
SensorState: 0 Brightness: 3
SensorState: 0 Brightness: 7
SensorState: 0 Brightness: 15
SensorState: 0 Brightness: 31
SensorState: 0 Brightness: 63
SensorState: 0 Brightness: 127
SoundTriggerState is LOW 1
SoundTriggerState is HIGH 2
SensorState: 0 Brightness: 255
SensorState: 1 Brightness: 127
SensorState: 1 Brightness: 127
SensorState: 1 Brightness: 127
SensorState: 1 Brightness: 63
SensorState: 1 Brightness: 31
SensorState: 1 Brightness: 15
SensorState: 1 Brightness: 7
SensorState: 1 Brightness: 3
SensorState: 1 Brightness: 1
SensorState: 1 Brightness: 0
SensorState: 1 Brightness: 0
Attachments
IMG_8881.jpeg
IMG_8881.jpeg (360.26 KiB) Viewed 994 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by adafruit_support_mike »

You code looks good, all your connections look right, and your documentation is still awesome.. thank you for that.

You only need one GND wire between the Pro Mini and the FX Board. All the GNDs are connected, so whichever wire is most convenient will be fine.

Let's check the basics: Pull the wire to the FX board loose from the breadboard and plug it into the GND rail to make sure it will trigger that way. If so, wire an LED to pin 10 on the Pro Mini and make sure the pin value is changing when it should.

User avatar
TryChick
 
Posts: 47
Joined: Wed Apr 30, 2014 3:44 pm

Re: Triggering FX Soundboard with Bend Sensor

Post by TryChick »

Problem fixed. First I tried grounding the pin on the soundboard but got nothing. Then I put an LED on pin 10 and it went out when I triggered the reed switch with the magnet, I double checked the soundboard to confirm it would fire on it's own using a button and it did.

Originally I had everthing hooked to a 12v A123 battery so I could use one power source for all the components. I had used a voltage regulator to bring the volts down to 3.3 for the ProMini and was powering the soundboard through the ProMini's VCC pin, but I was getting those clicking noises mentioned in my earlier posts.

Yesterday when I switched to powering the lights using the A123 and powering the ProMini with 3AAs, I kept the soundboard powered through the VCC and still got the clicking noises and the soundboard wouldn't fire. But since the soundboard can handle up to 5v, I tried plugging it directly into the power rail to give the sounboard direct voltage from the 3AAs. The clicking coming from the speaker stopped and the soundboard pin fired. I don't understand why this would fix the problem though, since the soundboard should have been getting enough juice through the ProMini's VCC pin.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”