The seventh part of this series is all about the sensor board. It hosts the position sensor and four fill sensors. Speaking of sensors sounds complex, but these are just pairs of IR-LEDs and phototransistors. All design files for the board are in the GitHub repository and if you missed one of the previous parts, look at the overview page.
You will find all required files for the electronics and prints in the following GitHub repository:
Pet Feeder by Lucky Resistor is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Based on a work at https://luckyresistor.me.
About the Sensor Board
The sensor board has two main functions: It contains the position sensor to rotate the turntable exactly one slot and there are four fill sensors to detect if food is in the compartments.
It is a minimal design, each sensor is a pair of IR LED with a phototransistor.
The Position Sensor
The circuit for the position sensor is straight forward. If VCC is applied to
LED5 will light up, and there is a working voltage on Q5. If more light falls on the phototransistor, more current will flow from the collector to the emitter and therefore, the voltage on
POS-OUT will drop.
You can see this voltage drop in the measurement above. With no light on the phototransistor, the voltage is around 3.0V and drops down to 1.5V.
Why using a 100kΩ Resistor?
Let’s have a look at the specification of the phototransistor:
The “Collector Dark Current” is at a maximum of 100nA and the “On State Collector Current” is typical around 3mA. You can imagine the circuit with
Q5 as a voltage divider. To find a suitable value for
R14, you just need to do a rough calculation how the phototransistor in this voltage divider will behave.
To simplify things, just assume the phototransistor is a resistor. At full light, it will passes a current of 3mA, therefore with 3.3V it will be a 1.1kΩ resistor.
With no light, it will pass in the worst case 100nA, which is like a 33MΩ resistor.
To be clear, a phototransistor will never act like a resistor. This is only a very rough estimation to see if the chosen resistor will give us measurements in a usable range.
The no light situation, with almost no current flowing makes no huge difference, no mater which resistor we choose for
Choosing the right value for
R14 ist about the some light situation. Here, the resistor defines how fast the voltage drops and how low it goes.
If we would have chosen an 1kΩ resistor, the voltage would never drop below 1.73V. It would be still possible to use the position sensor, but it limits the range of possible voltages. Also, with the 1kΩ resistor, you could not use a digital input to detect the position.
Probably, using a ~250kΩ resistor would have been better. Using these generic 10Ω, 100Ω, 1kΩ, 10kΩ, 100kΩ resistors reduces the number of different components on the board. It is the same reason, why I use an 100Ω resistor in front of the IR LED and not a 82Ω one.
I repeat this part for completeness: The turntable has five position slots.
They lead into a small excavation, reflecting the light from the infrared LED to the phototransistor.
The Fill Sensors
The circuit for the fill sensors is similar to the position sensor. There are four inputs,
SENS-IN-4, but only one output line
SENS-OUT. The output is pulled low, with resistor
R2. If all inputs are at GND,
SENS-OUT is at GND too.
Now if you set one of the inputs to VCC, the IR LED in the compartment lights up and the phototransistor gets a voltage at its collector. Therefore, you only measure the response on one single phototransistor. All other phototransistors will get a voltage on the emitter and will block most of the current flowing back to GND.
If you look into the data sheet of the
PT333-3B, there is a “Emitter-Collector Breakdown Voltage” of minimum 5V. Because your input voltage never exceeds 3.3V, this should be no problem at all.
Still, it is important you set all unused inputs to GND and do not keep these lines in a high-z state. Otherwise, very little current will flow in reverse through all other phototransistors, and through all other IR LEDs – which would distort the measurements.
The arrangement is reversed compared to the position sensor. If the phototransistor passes more current, the voltage will rise.
If no light is received by the phototransistor, the output is at a low voltage level.
A resistor is not a great simulation of a phototransistor, but it is enough to roughly verify the values.
If the compartment is empty, the light from the IR LED is reflected at the sides and the lid back to the phototransistor in the middle. Therefore, we get a high voltage reading from the sensor.
If food filled in the compartment, the light is blocked. Therefore, we get a lower voltage reading.
Fill Sensor Measurements
If you look at actual measurements, there is an initial voltage spike before the phototransistor stabilises. I am not sure what causing this effect. I tried to simulate the circuit using NPN transistors, but never got this spikes.
After 30ms, the signal stabilises, so I wait 50ms before I read the value from the ADC. At a later time, I will publish detailed measurements with different revisions of the turntable platform.
The last element on the board are connectors to connect it with the controller board.
There are pads to solder a TE MicroMaTch or similar connector to the board and eight plated through-holes. So you have different methods to chose, connecting this board with the controller.
- I personally recommend using the MicroMaTch system:
- The pads are large enough to solder a ribbon cable directly to the pads.
- There are plated through-holes where you can solder wires directly to the board.
How to Order the Board
If you plan to use the original design, you can order the board from OSHpark using the following link:
Alternatively, you find Gerber files, Eagle files and a Fusion360 design in the GitHub repository. Use them to order the boards from your favourite PCB manufacturer or as a good starting point for your custom design.
I hope this part gave you an idea, how to design the sensor board. Instead of a complex design, I use something simple and reliable and solve smaller problems in software.
In the next part, I will talk about the controller board. It will complete the electronic design, host the microcontroller and stepper motor driver.
If you have any questions, missed information, or simply want to provide feedback, feel free to comment below. 😄