Hello all, since you all were so helpful with figuring out how to wire speakers together, I'm hoping maybe you could also help me with this other project I've been stuck on....
I'm working on a project where an Arduino Uno uses 2 heart pulse sensors to trigger 2 solenoids (Sensor A triggers Solenoid A, Sensor B triggers Solenoid B) and is powered by one external power supply.
This is the pulse sensor I'm using: http://pulsesensor.com/
This is the solenoid: http://www.sciplus.com/p/POWER-DOOR-LOCK_47851
I'm attaching the schematic below and arduino code.
My friend drew up a schematic of what it should look like, but when I wired everything together it didn't work and now both of my pulse sensors don't seem to be working at all.
Link to video of what the circuit/code did do: https://drive.google.com/file/d/0B6GJZjLN3rhwNXVaY2JJUnBXbXM/view?usp=sharing
So I wasn't totally sure if the problem was the code, the schematic, or my own flawed wiring, but I posted on the Arduino forums my problem and this was a response I received:
"Your ground wiring is deeply flawed I'm afraid.
You are passing the 5.2A ground return from the solenoids through thin traces and directly
routing these to the sensor grounds.
1) Ground and power traces need to be wide so they have low inductance, and also need to be
wide for high current as here.
2) Never use the same ground wiring for high current loads as sensors - run these separately
except at one common point, the Arduino ground pins. There should be a thick set of traces from where
the 12V + ground comes in to the solenoid loads. There should be separate traces for 5V and ground
to the sensors, so that transients on the high current wiring doesn't affect the sensor. This is
probably why they are dying.
3) Keep the sources of interference well away from sensitive analog wiring. Using analog pins to drive
out to the MOSFETs isn't a great move, you'll always get some crosstalk from traces that run side-by-side
especially without a ground-plane.
4) Ground planes are very useful, use them whenever possible. You ideally need two ground plane
sections here, one for sensors, one for high current load side of circuit.
5) You don't need 1200V freewheel diodes, 20V is plenty - they do have to take the 2.6A peak
current of the solenoids though."
So seems the problem is the schematic. Now the problem is, I need help understanding this response, or you can add your own input to of course. I am a novice so I can't read schematics very well, but I can understand a parts layout.
Here are my questions in response to this feedback...
1) What are traces? Does it mean I need to be using a thicker gauge wire than standard jumper cables? What gauge do you recommend?
2) So does this mean the grounds from the RFP12N10L's should connect to the arduino ground pin instead of the sensors?
2/3) What should the new parts layout look like with the changes of the ground and power traces?
4) What is a ground plane?
Thank you!
Arduino Uno Code:
I'm working on a project where an Arduino Uno uses 2 heart pulse sensors to trigger 2 solenoids (Sensor A triggers Solenoid A, Sensor B triggers Solenoid B) and is powered by one external power supply.
This is the pulse sensor I'm using: http://pulsesensor.com/
This is the solenoid: http://www.sciplus.com/p/POWER-DOOR-LOCK_47851
I'm attaching the schematic below and arduino code.
My friend drew up a schematic of what it should look like, but when I wired everything together it didn't work and now both of my pulse sensors don't seem to be working at all.
Link to video of what the circuit/code did do: https://drive.google.com/file/d/0B6GJZjLN3rhwNXVaY2JJUnBXbXM/view?usp=sharing
So I wasn't totally sure if the problem was the code, the schematic, or my own flawed wiring, but I posted on the Arduino forums my problem and this was a response I received:
"Your ground wiring is deeply flawed I'm afraid.
You are passing the 5.2A ground return from the solenoids through thin traces and directly
routing these to the sensor grounds.
1) Ground and power traces need to be wide so they have low inductance, and also need to be
wide for high current as here.
2) Never use the same ground wiring for high current loads as sensors - run these separately
except at one common point, the Arduino ground pins. There should be a thick set of traces from where
the 12V + ground comes in to the solenoid loads. There should be separate traces for 5V and ground
to the sensors, so that transients on the high current wiring doesn't affect the sensor. This is
probably why they are dying.
3) Keep the sources of interference well away from sensitive analog wiring. Using analog pins to drive
out to the MOSFETs isn't a great move, you'll always get some crosstalk from traces that run side-by-side
especially without a ground-plane.
4) Ground planes are very useful, use them whenever possible. You ideally need two ground plane
sections here, one for sensors, one for high current load side of circuit.
5) You don't need 1200V freewheel diodes, 20V is plenty - they do have to take the 2.6A peak
current of the solenoids though."
So seems the problem is the schematic. Now the problem is, I need help understanding this response, or you can add your own input to of course. I am a novice so I can't read schematics very well, but I can understand a parts layout.
Here are my questions in response to this feedback...
1) What are traces? Does it mean I need to be using a thicker gauge wire than standard jumper cables? What gauge do you recommend?
2) So does this mean the grounds from the RFP12N10L's should connect to the arduino ground pin instead of the sensors?
2/3) What should the new parts layout look like with the changes of the ground and power traces?
4) What is a ground plane?
Thank you!
Arduino Uno Code:
Code:
/************************************************************************
Cadence
========
DESCRIPTION:
Actuates two solenoids to hit snare drum when heartbeats are found
by two Pulse Sensors.
REQUIRES:
1 x Arduino Uno
2 x Pulse Sensor Amped - http://pulsesensor.com/
2 x Solenoid driver circuits with gates attached to pins defined by
SOLENOID1_PIN and SOLENOID2_PIN below
INSTALLATION + USAGE:
1) Upload sketch to board
2) Build solenoid driver circuits and install on board
3) Install Pulse Sensors
**************************************************************************/
// Pins of all inputs and outputs
#define PULSE1_PIN A0
#define PULSE2_PIN A1
#define SOLENOID1_PIN A2
#define SOLENOID2_PIN A3
#define BUFFER_SIZE 10 // Number of readings to take. More readings = smoother data
#define HOLD_AMOUNT 100 // Amount in milliseconds to hold solenoids on for
// Variables used by sensor smoothing and beat detection code
int pulseBuffer1[BUFFER_SIZE], pulseBuffer2[BUFFER_SIZE];
int pulseTotal1 = 0, pulseTotal2 = 0;
int pulseAverage1 = 0, pulseAverage2 = 0;
int beatDetected1 = false, beatDetected2 = false;
int lastBeatTime1 = 0, lastBeatTime2 = 0;
int index = 0;
// Peak detection variables
int peakThreshold = 520; // Minimum value from sensor before beat is detected
int timeThreshold = 200; // Minimum time between beats. Helps filter out incorrect multiple triggers
void setup() {
// Get a serial connection going for debugging
Serial.begin(9600);
// Set up Pulse Sensor pins
pinMode(PULSE1_PIN, INPUT);
pinMode(PULSE2_PIN, INPUT);
// Set up solenoid driver pins
pinMode(SOLENOID1_PIN, OUTPUT);
pinMode(SOLENOID2_PIN, OUTPUT);
// Set up on-board LED
pinMode(13, OUTPUT);
// Initialize buffers to be empty
for(int i=0; i<BUFFER_SIZE; i++) {
pulseBuffer1[i] = 0;
pulseBuffer2[i] = 0;
}
}
void loop() {
// Get most recent sensor data and calculate averages
readSensors();
// Detect beats in sensor data
detectBeats();
Serial.println(pulseAverage1); // troubleshooting
// Activate solenoid 1 when beat is detected by Pulse Sensor 1
if(beatDetected1) {
// Serial.println("Beat detected on Pulse Sensor 2");
digitalWrite(SOLENOID1_PIN, HIGH); // activate solenoid
digitalWrite(13, HIGH); // turn on on-board LED
delay(HOLD_AMOUNT); // wait for solenoid to move
digitalWrite(SOLENOID1_PIN, LOW); // decactivate solenoid
digitalWrite(13, LOW); // turn off on-board LED
beatDetected1 = false; // reset flag
}
// Activate solenoid 2 when beat is detected by Pulse Sensor 2
if(beatDetected2) {
// Serial.println("Beat detected on Pulse Sensor 2");
digitalWrite(SOLENOID2_PIN, HIGH); // activate solenoid
digitalWrite(13, HIGH); // turn on on-board LED
delay(HOLD_AMOUNT); // wait for solenoid to move
digitalWrite(SOLENOID2_PIN, LOW); // decactivate solenoid
digitalWrite(13, LOW); // turn off on-board LED
beatDetected2 = false; // reset flag
}
}
/**************************************************
Read sensors
- take new readings and calculate new averages
***************************************************/
void readSensors() {
// Remove last readings
pulseTotal1 -= pulseBuffer1[index];
pulseTotal2 -= pulseBuffer2[index];
// Obtain new sensor values
pulseBuffer1[index] = analogRead(PULSE1_PIN);
pulseBuffer2[index] = analogRead(PULSE2_PIN);
// Add values to totals
pulseTotal1 += pulseBuffer1[index];
pulseTotal2 += pulseBuffer2[index];
// Advance to next position in array
index++;
// Wrap index when it exceeds size of buffer
if(index >= BUFFER_SIZE)
index = 0;
// Calculate averages
pulseAverage1 = pulseTotal1 / BUFFER_SIZE;
pulseAverage2 = pulseTotal2 / BUFFER_SIZE;
}
/**************************************************
Detect beats from Pulse Sensors
- analyes data from Pulse Sensors and looks for
peaks of appropriate frequency
***************************************************/
void detectBeats() {
// Detect beat on Pulse Sensor 1
// - If sensor values rise above threshold and enough time has passed since last beat was detected
if(pulseAverage1 > peakThreshold && (millis() > lastBeatTime1 + timeThreshold)) {
beatDetected1 = true;
lastBeatTime1 = millis();
}
// Detect beat on Pulse Sensor 2
//- If sensor values rise above threshold and enough time has passed since last beat was detected
if(pulseAverage2 > peakThreshold && (millis() > lastBeatTime2 + timeThreshold)) {
beatDetected2 = true;
lastBeatTime2 = millis();
}
}