I have an Arduino Uno, I would like to be able you use the TCRT5000 to sense a metal object from about 20mm.After sensing the object, I would like the Adruino to turn on a pneumatic solenoid though external circuuit. I somewhat understand the analog read (0-1023). I'm having trouble understanding how to use the values to achieve my goal. Any help would be greatly appreciated. I'm new to Arduino programing.
I have a TCRT5000 that Im trying to get to light external LED. The sensor works however doesn't stay on. Just blinks, but it works correctly on pin 13 LED. I programmed pull up resistor. Not sure what the deal is. Can you look at my code and see if I wrote it correctly and if so any thoughts to my issue? Thanks.
int sensePin = A1;
int ledPin = 13;
void setup() {
analogReference(DEFAULT); //Analog Reference of 5V is default, I know not needed.
pinMode(ledPin, OUTPUT); // set ledPin as output
pinMode(sensePin, INPUT); //set sensePin as input
digitalWrite(15, HIGH); //set pullup on analog 1
Serial.begin(9600);
}
void loop() {
int val = analogRead (sensePin);
if(val < 1000) digitalWrite(ledPin, HIGH); // value less then 1000, turn on led
else digitalWrite(ledPin, LOW); // value greater then 1000, turn off led
Serial.println(analogRead(sensePin)) ;
delay(50)
}