9. Sense changes in the environment¶
This week I prototyped some input tags to make my spice bottles uniquely identifiable, and a corresponding Multiplexer PCB board which can expand the ability of my Xiao board to read up to 16 tags.
👉An Input Device is a piece of hardware that sends data to another device or digital system, translating environmental data and human actions into signals that the machine can understand. - Wikipedia
Group assignment:
- Probe input device(s)'s analog levels and digital signals
Individual assignment:
- Measure something (Add a sensor to a microcontroller board that I have designed, and read it)
Groupwork:¶
This week we probed 3 input devices’ Analog levels; .
Link to Group Assignment documentation.
When I have the chance, I would also like to look into understanding more about Digital signals, as I’m wondering how that might be relevant for my final project design.
Measure something with my microcontroller board:¶
This week I made a variety of input tags with different resistance values, and a multiplexer board to enable my Xiao ESP32C3 to read 16 of these tags.
My personal goals for this week’s assignment was to answer these questions;
- How do I use the multiplexer to expand the number of analog inputs? and what’s the time lag of this multiplexer to read multiple inputs simultaneously?
- How do different placements of resistor(s) translate to actual voltage readings? What range/variety of tags could potentially be provided with this approach?
- Does the presence of magnets impact the resistor readings?
- What are potential designs for tags (and corresponding slots for the tags), and how could I optimise the user experience?
1. Grasping the mechanism¶
The biggest challenge for me in this week’s assignment was actually getting my head around the mechanism of the circuit I was building. In fact, I only fully understood this mechanisms at the end of the week, after the assignment was completed. But for the reader of this documentation, it will help to understand the whole mechanism before reading about the development process.
Essentially, the circuit I made is based on the concept of the Voltage divider.
Placing two resistors in series creates a lower Voltage output (Vout) from a higher Input voltage (Vin), and the Voltage out is proportional to the ratio of the resistor values (R1 and R2).
The output voltage (Vout) is calculated using the following formula:
Vout = (R2 / (R1 + R2)) * Vin
For example;
The circuit I created this week was based on this principle; using a voltage divider and variety of Input tags to create a range of Voltage out readings, that will enable me to assign unique tags for each spice bottles.
Based on this understanding, I was able to calculate the expected Vout values of each tags, by calculating the relative resistance of R2 versus the R1 of 100 Ohms. Seeing these values gave me much better idea of the range of tags I should have ideally tested.
Once I understood this mechanism, I realised that I was essentially making a very basic type of Potentiometer. Perhaps what I should be doing is to look into next is to make a simple Potentiometer using some type of resistive material (instead of struggling to string together multiple resistors, which are limited in their variety).
I hope to continue exploring this approach for my final project.
2. Breadboarding a Test Circuit¶
Thanks to my amazing instructor Nagano-san, I eventually managed to Breadboard the below test circuit, which could in theory be used to test various resistor combinations.
But I didn’t manage to test a lot of tags with this circuit, as for some reason, the readings on my Serial Plotter was fluctuating at high frequency, which made reading their values a little tricky.
Strangely, when we plugged the same circuit and code to Nagano san’t computer, it produced clean, straight lines. Nagano san initially thought the problem was the AC adapter not being plugged in (resulting in less secure ground connection) but plugging it in didn’t make a difference. Since the circuit itself was working on Nagno san’s Pc, I decided it must be functional and proceeded to board fabrication.
For reference, this is the Multiplexer board I used;
16-channel Multiplexer | Specs |
---|---|
Chip used | HP4067 |
Power supply voltage | 2-6V |
On-state resistance | 70Ω at 4.5V supply, 60Ω for 6V |
Dimensions | 41x19mm |
Arduino library | Link |
And the code I used are below.
The important points to note are;
- Row 7, where I set the analogRead Resolution to 12 bits, which converts the measured voltage into digital values of 0 to 2,046.
- Row 15, where I print 2046 to make sure the max value is always plotted
- Row 18 onwards, which is the code for reading the inputs on the multiplexer .
#include <CD74HC4067.h> // Include the multiplexer board library
#define SIG_PIN D0 // Define D0 pin as the Analog Sig_pin
CD74HC4067 my_mux(D10, D9, D8, D7); // Xiao D10-D7 pins connect to Multiplexer S0, S1, S2, S3 pins
void setup() {
analogReadResolution(12); // Set the resolution to 12bit
int sensorValue = analogRead(D0); // Read the Analog inputs from pin D0 as integer values
Serial.begin(9600); // Initialise serial communication at 9600 bits per second
}
void loop() {
Serial.print(0); // Print the lowest value
Serial.print(",");
Serial.print(2046); // Print the highest value
Serial.print(",");
for(int i=0; i<5; i++){ // For inputs from pin# i to i<5...
my_mux.channel(i);
Serial.print(analogRead(SIG_PIN)); /// Read the Analog value on D0 sig pin
Serial.print(","); // and Serial.print that value
delay(1);
}
Serial.println("");
}
3. Potential Tag designs¶
Before designing the Tags, I tried to explore several potential approaches for physically implementing the tags onto the spice bottles.
At this moment, I am leaning towards the third design, because of its simplicity and flexibility.
4. Creating Board and Input Tags¶
4.1 Creating a Multiplexer Board¶
First I designed a Multiplexer board to enable simultaneous analog input.
When designing the board, I couldn’t find the footprint for the Multiplexer that I bought off Rico, so I made a visual approximation of the distance between 2 Pin Headers. Because I didn’t use proper rulers, I struggled with soldering later on, so I would make sure to measure more precisely next time!
Once happy with the design, I milled and soldered them.
I had plenty of opportunity to understand the importance of testing the board before connecting it, but in the excitement of completing it, I totally forgot to this time. It seems there was some kind of faulty circuit, because a smoke came out of my PC's USB port when I plugged the board to it.
The reason for the smoke is unclear, since when I tested it later, I couldn't find any issues. Thankfully there seemed to be no damage to my computer after I restarted it.
4.2 Creating Input Tags¶
I designed 8 input tags with different resistance values (some for soldering overlapping resistors - i.e., to try Parallel circuits).
Later, I realised that I should have made more variety of the serial circuits (with more resistors strung together), as the objective was to see how far apart the resistance values would need to be for the processor to recognise them as different tags.
Also, I made them using chip resistors to make them as small as possible, but carbon resistors are not that large either and might have been easier to handle.
The resistor I used was 1kΩ, with tolerance value of ±5%, but I’m wonder if I should be using weaker resistors to minimise energy consumption.
5. Reading the Input Tags¶
Finally, I connected all the boards together as I explained before, and uploaded the same code from the breadboard test.
These were the readings I got. As you can see, I was still getting strange wavy readings. So I decided to redo everything again.
Measure Something…Take Two¶
Because of the mysterious smoke and wavy readings, as well as finding my Development board difficult to use, I decided to retry the assignment.
First, I redid the Multiplexer board.
I then connected different resistors once again. This time I calculated the expected readings for different resistor values.
Simulation of R2 when R1=1KΩ:
Later I found this very useful calculator from this site.
Finally, I got the correct readings🙌
Serial Plotter:
Specific figures:
Design files:¶
Reflections:¶
This week I learnt the workflows for reading input devices.
- The basic mechanism of analog input devices: I learnt that a lot of the time they use the concept of resistance or capacitance.
- Voltage divider mechanism: I learnt how to create voltage drop and how I can program a code to read them as digital values. Understanding this mechanism helped me deepen my understanding of Electronics, particularly the relationship between Voltage, Current and Resistance.
- Multiplexers: I learnt how to use multiplexers to increase the number of analog signals that can be read.
Regarding my initial questions:
- Time lag of multiplexers: I couldn’t see any time lags with ~10 inputs, but I have yet to test with significantly more inputs.
- How many tags can be recognised: I need to do a more vigorous test, but 10 is probably possible.
- Impact of magnets: No impact on voltage dividers, but I need to watch out next week as they will impact devices that use electromagnets.
- How to optimise the device for user experience: I need to spend much more time prototyping and testing.
Further Questions:
- Wondering what was the cause of those strange wavy lines. I hope they won’t cause difficulties down the line.
- What are the benefits/disadvantages of digital and analog signals?? How could that be relevant for my final project?
Useful links:¶
- Useful Multiplexer documentation
- Multiplexing Code for Arduino
- Multiplexer Hookup Guide
- Multiplexer Datasheet
- Potentiometer as variable resistor: Normally, potentiometers are wired as variable voltage dividers: connect +V to one side, connect the other side to ground, and the middle pin will output a voltage between 0 and +V (fig 2).
- How to make my own potentiometer: Automotive ignition wires (Graphite cores) should yield somewhere around 10000 ohms per foot, and they are nice and flexible.
Assignment Checklist:¶
- Linked to the group assignment page
- Documented what I learned from interfacing an input device(s) to my microcontroller and optionally, how the physical property relates to the measured results
- Documented my design and fabrication process or linked to the board I made in a previous assignment
- Explained the programming process(es) I used
- Explained any problems I encountered and how I fixed them
- Included original design files and source code
- Included a ‘hero shot’ of my board