Mailbag #18
This week I open a variety of mail - no dog products! There are some nice SOT-23 transistors based on the SS8050 NPN and SS8550 PNP TO-92 packages that I have enjoyed over time.
There are some other nice bits and pieces - enjoy!
Each week I will feature a circuit based on one or more of the electronic parts I have ordered then forgotten about over the years.
This week I open a variety of mail - no dog products! There are some nice SOT-23 transistors based on the SS8050 NPN and SS8550 PNP TO-92 packages that I have enjoyed over time.
There are some other nice bits and pieces - enjoy!
It is useful to both display and be able to react to analog inputs. A microcontroller such as the ATTiny13 or PFS154 is fine for this, but you could also go a bit "old school" and use a comparator such as the LM339.
The scenario is that a 12V battery is "green" above 9V, fine from 3V-9V and "red" below 3V.
Using the LM339 a "window comparator" can be made according to the following circuit diagram.
The first voltage divider (two resistors) simulates voltage changes for an analog input to be tested, whilst the second one with the three resistors "sets" the cutoffs for the window comparator.
The input to be tested is tied to the inverting input of one comparator and the non-inverting input of another comparator. The cutoffs are fed to the remaining inputs, and then the output will reflect where the testing voltage has landed.
Two weird things about the LM339 which caused me pause during the build. One is the unusual position of VCC/GND compared to a lot of CMOS chips, and the other is the fact that it does not source current from it's "outputs" - but rather sinks current. That was a bit unexpected!
This mailbag is not much different, excepting for a weird event whereby I re-tweeted a @PCBWAYofficial prize draw...and...WON! So first up is a nice little digital oscilloscope - to augment my diagnostic tools.
Thanks PCBWAY - in this video I open up the prize and put it to good use straight away.
Also there are some other packets to open, including one of the most unusual (and probably useless) module I've ever seen - a joyous mailbag.
The appearance of the Stable Joule Thief (SJT) means that I can now supply a steady reliable voltage for a microcontroller from a single solar charged NiMH battery! It still seems like a wild idea to me, even though I've been using the SJT for in projects for more than a year now.
Basically, if you can think of a simple low power project running on, for instance, an ATTiny μC, then you can use a cheap solar powered garden light to run the project.
Here is the blog link for this SJT and here is the video link that matches that post.
For this post, I've had it in mind that I'd like to look out the window on a cold night and get a rough idea of the temperature. The initial idea comes from a project of Julian Ilett where he uses a flashing LED to indicate the charge in a solar charge battery rig.
Also recently I've been looking at the 'cold monitoring' flashing lights we sometimes see on our roads here in Tassie.
For this project, I just wanted to know if the temperature was in the following ranges:
The chosen garden light is a very cheap local hardware store version - bought in bulk for just under $2 per light.
We've seen on this blog and as a video a very similar project, but in that occasion I just wanted simple flashing LEDs.
In this version, there is an added LM35 probe which is used for temperature monitoring. The code for the ATTiny13 (at 128kHz) works as follows:
1. Sleep2. Wake up every 3 minutes and turn on the LM353. Measure the temperature using the internal reference voltage4. If it's above 10 degrees go back to sleep!5. If it's lower than 10 degrees then flash accordingly, sleeping between flashes to conserve energy.
/* LM35 solar light temperature monitor OneCircuit: https://www.youtube.com/c/onecircuit-as/videos https://onecircuit.blogspot.com/ pin PB1 used as VCC for LM35 pin A1 used as analog input pin PB0 used as LED output Device: ATtiny13A ____________ 1 / | 8 o-- | RESET VCC | --o o-- | PB3 PB2 | --o--A1 measure o-- | PB4 PB1 | --o--LM35 on/off o-- | GND PB0 | --o--LED 4 |____________| 5 Sun 19 Jun 2022 11:45:21 AEST */ #include <avr/sleep.h> #define sensorPin A1 // temp limits in celsius #define upper_temp 10 #define mid_temp 7 #define low_temp 3 void setup() { analogReference(INTERNAL); // greater accuracy DDRB = 0b00000011; // LEDPin output PORTB = 0b00111000; // pullups enabled } ISR(WDT_vect) { // watchdog ISR } void snooze(uint8_t cycles, uint8_t howlong) { // sleep preparation WDTCR = howlong; ADCSRA &= ~(1 << ADEN); ACSR |= (1 << ACD); cli(); BODCR = (1 << BODSE) | (1 << BODS); BODCR = (1 << BODS); sei(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); // sleep now for (cycles; cycles > 0; cycles--) { sleep_mode(); } sleep_disable(); // waking up ADCSRA |= (1 << ADEN); // turn on ADC ACSR = (0 << ACD); // Turn on Analog comparator. delay(10); // take a breath } // blinking routine (including sleeping) void blinkme(uint8_t blinks) { for (blinks; blinks > 0; blinks--) { PORTB = 0b00000001; // turn on LED snooze(1, 0b01000001); // 1x32 ms sleep PORTB = 0b00000000; // turn on LM35 snooze(1, 0b01000100); // 1x250 ms sleep } } void loop() { DDRB = 0b00000011; // LM35 pin to output PORTB = 0b00000010; // turn on LM35 delay(1000); // settle LM35 uint16_t reading = analogRead(sensorPin); uint16_t voltage = reading * (1100 / 1024.0); uint8_t temperature = voltage / 10; PORTB = 0b00000000; // turn off LM35 DDRB = 0b00000001; // LM35 pin to input // analyse result if (temperature > upper_temp) { DDRB = 0b00000000; // all pins to input snooze(20, 0b01100001); // 20x8 seconds DDRB = 0b00000001; // LEDPin to output } else if (temperature > mid_temp) { blinkme(1); } else if (temperature > low_temp) { blinkme(2); } else { blinkme(3); } DDRB = 0b00000000; // all pins to input snooze(1, 0b01000111); // 1x2 seconds DDRB = 0b00000001; // LEDPin to output }
The early version of this project had the LM35 "on" the whole time, thus consuming more power (60 μA current drain according to the datasheet) than necessary, but the latest version runs very very sparingly!
It has been up and running happily in the garden for a few weeks now, and is might useful as well.
For my 156th (10011100) post and video, feast your senses on an odd assortment of bits and pieces arriving somewhat confusedly in Tasmania!
Being a teacher can be an interesting gig. One day you're out on the oval in freezing slush, separating overly enthusiastic teenagers intent on wrestling one another into submission and wondering where your life went astray.
Then some days you will have an experience of sublime excellence in your chosen field (mathematics natch), be complimented by a parent, be paid to go to a wonderful concert, and leave work early because you can.
It's the proverbial box of chocolates!
A couple of weeks ago I was asked to help out on a STEM project where CO₂ gas-powered model cars are fired along a wire to test student design.
In the past the "runs" were measured using manual techniques such as a stopwatch.
We can improve the accuracy of the timing using a laser gate - a laser light shines into a photodiode. When the light is shining, there is a voltage generated. When there is no light, this voltage drops.
The difference can be used to see when a laser beam is interrupted, in this case by a toy car!
The photodiode is connected reversed biased with VCC to cathode and the anode via a resistor to ground. If light falls on the diode it will cause a current through the resistor, which will cause a voltage across it.
There needs to be enough voltage drop across the photodiode to measure.
The following code is a skeleton for the students to work with, but it demonstrates how such a circuit can be used to capture start and stop times for this project.
/* Timing gate using laser diodes as transmitters and photodiodes as receivers. 25 May 2022 */ const int startPin = A0; // starting receiver const int stopPin = A1; // stopping receiver int sensorValue = 0; // value read from the photodiode int outputValue = 0; // scaled value long gotime = 0; // timing variables used by long stoptime = 0; // millis() long racetime = 0; float printtime = 0; // converted for display byte ambient = 50; // can use this or a 10k pot in // circuit to adjust for ambient light void setup() { Serial.begin(9600); Serial.println("RACING: "); delay(500); // settle time before race } void loop() { sensorValue = analogRead(startPin); outputValue = map(sensorValue, 0, 1023, 0, 100); if ((outputValue > ambient)) { gotime = millis(); // and we're racing Serial.println("GO!"); delay(500); // delay while end of car goes past start gate sensorValue = analogRead(startPin); outputValue = map(sensorValue, 0, 1023, 0, 100); delay(2); // ADC convert time delay while (outputValue < ambient) { sensorValue = analogRead(startPin); outputValue = map(sensorValue, 0, 1023, 0, 100); delay(2); // keep reading } stoptime = millis(); // and we've finished Serial.println("STOP!"); racetime = stoptime - gotime; printtime = racetime / 1000.0; Serial.print("Racetime: "); Serial.print(printtime, 3); Serial.println(" seconds"); Serial.println(); Serial.println(); delay(5000); // delay until next race possible Serial.println("RACING: "); } delay(2); }
That all works fine, but some fine tuning (due to OH&S considerations) has seen the laser swapped out for an ordinary LED so the kiddies don't burn out their eyeballs staring too long at the pretty red light!
In the video below I use a straw hat LED which actually has quite a wide throw, so perhaps another LED or indeed the proposed glass/aluminium "tunnel" which should focus the light better.
It doesn't really matter as the sensitivity can either be adjusted in the circuit (via R), or in the code (via the variable "ambient").
I'm now handing this all over to the students and their teachers for the next stage - they need to do some of the development work, right?
I was caught up a bit in the lovely arrivals this week, so there is a fair bit of faffing about - particularly with a "fake" CCTV camera!
The option to put an ESP32 CAM module inside a realistic looking fake is hilarious. In the meantime a random blinking guy is keeping watch over all the buckets of goodies - but where is the real cam? 😉