Hi! I was doing a project for my school with Arduino (it’s not the first time I use Arduino, I’d say I’m quite capable), but it doesn’t work well.
It’s code for a speed camera project.
#define TR1 10
#define TR2 12
int detection1 = HIGH; // no obstacle1
int detection2 = HIGH; // no obstacle2
unsigned int inizioMisura = 0;
unsigned long Ti = 0;
unsigned long Tf = 0;
float deltaT = 0;
const float distanza = 0.115;
const float conv = 3.6; //conv=1 per m/S - conv=3.6 per Km/h
void setup() {
Serial.begin(9600);
pinMode(TR1, INPUT);
pinMode(TR2, INPUT);
}
void loop() {
detection1 = digitalRead(TR1);
detection2 = digitalRead(TR2);
if(detection1 == LOW && inizioMisura == 0){
Ti = millis();
//Serial.println("Ti= "+String(Ti));
inizioMisura = 1;
}
if(detection2 == LOW && inizioMisura == 1){
Tf = millis();
deltaT = (float)(Tf-Ti)/1000;
//Serial.println("Tf= "+String(Tf));
//Serial.println(deltaT,3);
Serial.println(conv*distanza/deltaT,1);
inizioMisura = 0;
}
}
I think the code is correct, but when I use it the values are "off": if I put my finger on the sensors slowly it gives me a lower number than when I pass it quickly.
This is the circuit design.
(the infrared sensors are different from the image, the sensors are these: https://it.aliexpress.com/item/1005006095222017.html)
