555 timer LED flasher
The most famous chip in electronics, blinking an LED about once a second.
Shop by category
Shop all componentsThe Nano's built-in ADC has 10 bits, about 4.9 mV per step. The MCP3202 is a 12-bit SPI ADC in an 8-pin DIP with two inputs, giving about 1.2 mV per step from a 5 V reference. The sketch talks to it directly with SPI: a start bit, the channel select bits, then reads 12 bits back. It averages 32 samples per channel and shows both voltages, a good bench meter for sensors and batteries.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB. VDD is also the reference, so measure the Nano's 5 V with a meter and set VREF.
mcp3202_meter.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
void big(const String& top, const String& value, const String& unit) {
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(1); oled.setCursor(0, 0); oled.print(top);
oled.setTextSize(3); oled.setCursor(0, 20); oled.print(value);
oled.setTextSize(1); oled.print(" "); oled.print(unit);
oled.display();
}
#include <SPI.h>
const int CS = 10;
const float VREF = 4.98; // measure your 5V pin
int readAdc(int ch) { // MCP3202: start bit, then SGL=1, ODD=ch, MSBF=1
digitalWrite(CS, LOW);
SPI.transfer(0x01);
uint8_t hi = SPI.transfer(ch ? 0xE0 : 0xA0);
uint8_t lo = SPI.transfer(0x00);
digitalWrite(CS, HIGH);
return ((hi & 0x0F) << 8) | lo;
}
float volts(int ch) { long s = 0; for (int i = 0; i < 32; i++) s += readAdc(ch); return s / 32.0 * VREF / 4096.0; }
void setup() {
pinMode(CS, OUTPUT); digitalWrite(CS, HIGH);
SPI.begin();
SPI.beginTransaction(SPISettings(900000, MSBFIRST, SPI_MODE0));
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
float v0 = volts(0), v1 = volts(1);
oled.clearDisplay(); oled.setTextColor(WHITE); oled.setTextSize(2);
oled.setCursor(0, 4); oled.print("A "); oled.print(v0, 4);
oled.setCursor(0, 36); oled.print("B "); oled.print(v1, 4);
oled.display();
delay(300);
}
Check DIN and DOUT are not swapped and that CS goes low during a read.
Set VREF to the measured supply; a separate 4.096 V reference improves accuracy.
Keep the 100 nF capacitor close to pin 8 and average more samples.
Use a resistor divider and multiply by its ratio; never put more than VDD on an input.
The ADS1115 has 16 bits and a PGA; the MCP3202 is cheaper, faster and shows how a raw SPI ADC works.
Yes, set the SGL bit to 0 to read CH0 minus CH1.
6 parts: Generic Nano CH340 Development Board (Soldered), MCP3202 12-Bit SPI ADC (2 Channel, DIP-8), 0.96" OLED Display 128x64, Ceramic Disc Capacitor, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (mcp3202_meter.ino).
About ₹584 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
How SPI ADCs are read bit by bit; Reference voltage and resolution; Averaging to reduce noise.
The most famous chip in electronics, blinking an LED about once a second.
Press once and the light stays on for about 11 seconds, then goes off by itself.
A running light like the one on Knight Rider, made from two classic chips.
Touch two wires with a fingertip and an LED lights: skin current switches a transistor pair.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.