So I've just spent an hour or two trying to get the parking sensor to work independently, using an Arduino Uno, a Texas Instruments CD4052B multiplexer, and a Fairchild LM324 op amp.
Here's my schematic, click on image for larger view:
I wanted to start with just one sensor, for a "proof of concept".
And here's my Arduino sketch:
#include <avr/interrupt.h>
#define burst 4
#define echo 5
boolean burstSent = false;
volatile boolean echoSent = false;
unsigned long burstTime = 0;
volatile unsigned long echoMicros = 0;
void setup() {
pinMode(burst, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(250000);
// Setting Interrupt Registers
PCICR |= 0b00000100; // turn on port D
PCMSK0 |= 0b00100000; // turn on interrupt on pin PD5
}
void loop() {
if (!burstSent) {
noInterrupts();
burstTime = micros();
tone(burst, 50000);
delayMicroseconds(1);
noTone(burst);
interrupts();
burstSent = true;
Serial.println("Burst sent.");
}
if (echoSent) {
unsigned long microsDifference = echoMicros - burstTime;
Serial.print("Time delay (microseconds):\t\t");
Serial.println(microsDifference);
burstSent = false;
echoSent = false;
}
}
ISR (PCINT2_vect) {
if (PIND & 1 << echo) {
echoMicros = micros();
echoSent = true;
}
}
So far, this does nothing. It was a shot in the dark just throwing this together, because I've got a big electronics store just around the corner and they had these parts in stock for less than 50 cents each.
I was trying to follow the observations in the quote in my last post, but so far, again, nada.
Any thoughts?
