newbie here. I can write simple programs but electronics not really my strong point.
I got my hands on a Alge Timing photocell and I've been trying to make it work with the Arduino.
I have push buttons to mimic a photocell passing but from the photocell itself I am not getting any info.
I'm planning to use the signal from the photocell to mimic a keypress. So far my code goes as follows:
#include <Keyboard.h>
int manualPassing = 3; // photocell is here
int greenFlag = 9; // push-button is here
void setup()
{
pinMode(manualPassing, INPUT_PULLUP); // Set the button as an input
pinMode(greenFlag, INPUT);
digitalWrite(manualPassing, LOW);
digitalWrite(greenFlag, HIGH);
}
void loop()
{
if (digitalRead(manualPassing) == HIGH) // I'm assuming it will be always HIGH as it is a NPN Transistor type
{
Keyboard.write('z');
delay(1000);
digitalWrite(manualPassing, LOW);
}
if (digitalRead(greenFlag) == LOW) // if the button goes low
{
Keyboard.write('G');
delay(500);
digitalWrite(greenFlag, HIGH);
}
}
I'm wiring it simply with common ground for both input and directly connecting to the pins.
Any help on how to receive the signal? I've tried with a PNP Type photocell and it works.
Delete the two instances of “digitalWrite(manualPassing, LOW);” and the program should work. If not, post a schematic of how it is connected to the sensor. Use the forum to post images, don’t expect people to use external websites, especially when you provide broken, non-clickable links.
Your link doesn’t work.
You are clearly trying to deliver only one simulated button press, no matter how long the input is brought low by your external device. You need to maintain your own flag to indicate that you have acted on a detection from the device. You set this flag when you have simulated a button press. You clear the flag when you no longer detect an input.
int manualPassing = 3; // photocell is here
void setup
{
pinMode(manualPassing, INPUT_PULLUP );
}
void loop()
{
if (digitalRead(manualPassing) == LOW)
{
Serial.println('Z');
delay(1000);
}
}
If it doesn't work with the photocell trigger attached to pin 3, then try removing it and short pin 3 to ground to see if you get anything in the serial monitor.
The photocell does not output a voltage if it is an NPN output, it shorts a voltage to ground. You'd have to put one probe on Vcc (photocell) and the other on the output pin of the photo cell.