How to read output from SEN0506 with arduino?
The SEN0506 has one sensor output wire to check if the color that was configured is detected or not. (https://wiki.dfrobot.com/Smart_Color_Mark_Photoelectric_Sensor_SKU_SEN0506#target_3)
Now, the sensor operated between 12-24V, so I was wondering how to best attach this sensor to my arduino to read out?
Will the sensor wire go high when the color is detected? If so, will it output 12-24V (the source voltage)?
I assume I can't directly hook this up to my arduino and need some sort of optocoupler to read the output safely?
Can anyone provide me with some more information?
I figured it out myself:
The sensor basically has a NPN transistor built in on the sensor wire. This wire can be hooked up directly to the arduino and be read digitally, using a pullup resistor
Sample script:
const int sensorPin = 9; // change this to the pin you connected the sensor to
int RXLED = 17; // The RX LED has a defined Arduino pin
int TXLED = 30; // The TX LED has a defined Arduino pin
void setup() {
pinMode(sensorPin, INPUT_PULLUP); // set sensorPin as INPUT with pull-up resistor
pinMode(LED_BUILTIN, OUTPUT);
pinMode(RXLED, OUTPUT); // Set RX LED as an output
pinMode(TXLED, OUTPUT); // Set TX LED as an output
}
void loop() {
int sensorState = digitalRead(sensorPin); // read the state of the sensor
if (sensorState == HIGH) {
Serial.println("The transistor is OPEN");
digitalWrite(RXLED, HIGH); // set the LED off
digitalWrite(TXLED, HIGH); // set the LED off
} else {
Serial.println("The transistor is CLOSED");
digitalWrite(RXLED, LOW); // set the LED on
digitalWrite(TXLED, LOW); // set the LED on
}
}
Nick De Frangh