I’m currently trying to build a chronograph to measure the velocity of a projectile between two IR beams, but the IR recievers are behaving very strangely. The IR gates detect the beam is broken at the beginning. If I break the beam, nothing changes, but when I unblock the beam, it breifly senses the IR beam before going back to not detecting it again. I’ve linked a video of the problem here.
I based it off of this project with a few differences, such as using an OLED with u8glib instead of a segmented display
I purchased this nano clone, and these IR LED’s and receivers.
Here is my code for the project
#include <U8glib.h>
/*
* This is a test program to confirm that the photogates work correctly and is not supposed to display or calculate velocity yet
*/
extern const int PHOTOGATE_1_PIN = 4; //D4
extern const int PHOTOGATE_2_PIN = 7; //D7
/* SLboat Add Device */
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_FAST); // I2C 128x64(col2-col129) SH1106,Like HeiTec 1.3' I2C OLED
void u8g_prepare(void) {
u8g.setFont(u8g_font_6x10);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
}
//Draws two strings displaying the status of each of the two photogates
void drawPhotogateStatus()
{
// Prepare the strings to be drawn
String val;
String val1;
if(digitalRead(PHOTOGATE_1_PIN) == HIGH)
val = "true";
else
val = "false";
if(digitalRead(PHOTOGATE_2_PIN) == HIGH)
val1 = "true";
else
val1 = "false";
String str1 = "Photogate 1: " + val;
String str2 = "Photogate 2: " + val1;
// Set font
u8g.setFont(u8g_font_helvB10);
// Draw the strings
u8g.drawStr(0, 30, str1.c_str());
u8g.drawStr(0, 60, str2.c_str());
}
void setup(void)
{
// Display Setup
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// Photogate 1 Setup
pinMode(PHOTOGATE_1_PIN, INPUT);
digitalWrite(PHOTOGATE_1_PIN, HIGH);
// Photogate 2 Setup
pinMode(PHOTOGATE_2_PIN, INPUT);
digitalWrite(PHOTOGATE_2_PIN, HIGH);
}
void loop(void) {
// picture loop
u8g.firstPage();
do
{
u8g_prepare();
drawPhotogateStatus();
}
while ( u8g.nextPage() );
// rebuild the picture after some delay
}
Sorry if it’s something really simple, I have quite a bit of coding experience but I’m quite new to electronics and hardware. Thanks so much for any help!