One of my processes for choosing a topic or theme for this blog and video is to look into the "buckets of wire critters" and randomly choose an IC, then research for a bit about how it might be usefully employed.
And so it came to pass that I spied a few CD40106 ICs which I had ordered in June of 2018 (and then forgotten).
The CD40106 is a hex Schmitt-Trigger inverter which has a score of useful circuits with it at the heart. For instance in the datasheet we see applications including wave and pulse shapers, high-noise-environment systems, monostable multivibrators and astable multivibrators.
Here is the pinout:
However, in the course of researching I found a "train crossing" circuit which used three 555 chips to simulate a warning and then actual flashing LEDs.
I was surprised that this 555 based circuit came up as a "hit" when I was searching for CD40106 - but when checking the bottom of the website I found the following circuit.
Whilst the circuit is fairly simple to both understand and construct, I was stymied by the first lot of ICs I picked up being clearly faulty.
Firstly, they did not behave as expected (blinking at odd times although not as per the circuit). The biggest problem was that after a few minutes they went into a short circuit, thus triggering the current limiter on my power supply, and refusing to do any more work!
Fortunately the second batch I tried worked and worked well.
I'm thinking that although this was a "train crossing" application it would suit an "alarm" style circuit - perhaps even with a "cancel" option as per a commercial home alarm.
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!
I built up the circuit on a breadboard using 1206 components on my own breakout PCB (comes in handy!) - and it all worked as expected.
Normally I have to buy stuff and wait forever for it to turn up. Then I open it and say "Now what was I thinking when I bought that?".
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:
greater than 10 degrees celsius (no LED flashing)
between 7 and 10 degrees (1 flash)
between 4 and 7 degrees (2 flashes)
below 4 degrees (3 flashes)
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. Sleep
2. Wake up every 3 minutes and turn on the LM35
3. Measure the temperature using the internal reference voltage
4. 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 3voidsetup() {
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 nowfor (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 LM35uint16_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 resultif (temperature > upper_temp) {
DDRB =0b00000000; // all pins to input
snooze(20, 0b01100001); // 20x8 seconds
DDRB =0b00000001; // LEDPin to output
}
elseif (temperature > mid_temp) {
blinkme(1);
}
elseif (temperature > low_temp) {
blinkme(2);
}
else {
blinkme(3);
}
DDRB =0b00000000; // all pins to input
snooze(1, 0b01000111); // 1x2 seconds
DDRB =0b00000001; // LEDPin to output
}
There are probably some improvements to be found - mainly by converting to assembler - but at the moment it works and works pretty well!
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.