I wrote some basic Arduino code to run the initial working prototype, based on the Test_IR_Emitter code I posted earlier. The Arduino code sends an IR pulse, measures the analog sensor readings after the pulse is reflected back, and shakes the vibration motor based on the IR signal strength. In order to reduce the effects of constant IR light sources such as sunlight or indoor lighting, I'll be sending pulses of IR and verifying that those pulses are detected. So by sending a special coded pulse signal (eg: 1 0 1 1 0 1 0), the microcontroller can verify that the received IR signal goes up & down accordingly, otherwise it would discard the signal since it would be caused by a different IR source such as sunlight. Since the IR receiver I'm using is so slow (roughly 3ms response time), sending a pulsed message takes up a lot of time, and therefore only allows roughly 50 messages per second, but that should be fast enough to feel smooth. The vibration motor is likely to have much slower response than this anyway!
Since I wanted to test the system straight away without a complex pulse code detection system, so far I've just written some code without the coded pulses. It's available at https://github.com/shervinemami/DepthIR/tree/master/DepthIR_Arduino
The crucial part of the code is shown here, for mapping the IR signal strength to a vibration strength (note that these values are just initial guesses and will need tweaking!):
// Map the IR strength (between 0 to 1023) to a vibration strength between 0 to 255.
// Since the IR strength is a steep exponential curve, we need to make sure there are
// still some vibrations when the IR is low, but not when the signal is just noise (below 3).
int vibrationStrength = 0;
const int MAX_VIBRATION = 130;
if (sensorVal > 3) {
vibrationStrength = 60 + sensorVal * 1;
if (vibrationStrength > MAX_VIBRATION)
vibrationStrength = MAX_VIBRATION;
}
// Vibrate the finger
analogWrite(VIBRATOR_PIN, vibrationStrength);
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.