Compact ATTINY85 development board with Micro-USB programming and power. Small, low-power and perfect for embedded automation tasks. The example below demonstrates a typical small automation: an automatic night light that turns a relay on when ambient light is low, with a manual override button. The example is written for the Arduino environment (ATTiny cores) and is intentionally simple to adapt.
Board pin mapping (common ATTiny85 boards): PB0 -> Arduino D0 / A0 PB1 -> Arduino D1 PB2 -> Arduino D2 / A2 (ADC) PB3 -> Arduino D3 PB4 -> Arduino D4 PB5 -> RESET (do not use for I/O) Example wiring: LDR (voltage divider) -> A2 (PB2) Manual button (momentary) -> D0 (PB0) with INPUT_PULLUP Relay module IN -> D1 (PB1) (use a relay module with proper transistor / optocoupler) VCC -> 5V (from Micro-USB) GND -> GND Important: - Use a relay module rated for your load; isolate mains wiring and follow safety rules. - Many ATTiny boards run at 8MHz internal clock; set this in the Arduino board settings.
The sketch reads an analog LDR value and switches a relay ON when ambient light falls below a configurable threshold. A manual button provides an override (toggle). Basic hysteresis prevents relay chatter near the threshold. This demonstrates a practical small automation task suitable for hallways, cupboards, garden lights, or equipment cabinets.
/*
ATTINY85 Night Light + Manual Override
- LDR (voltage divider) connected to A2 (PB2)
- Manual button to PB0 (D0) using INPUT_PULLUP
- Relay module IN to PB1 (D1) (logic HIGH turns relay ON; invert if your module is active LOW)
Notes:
- Confirm pin mapping for your ATTiny85 board variant.
- Compile with ATTiny85 core (e.g., SpenceKonde / AttinyCore) and set correct clock/source.
*/
const uint8_t PIN_LDR = A2; // PB2 (analog)
const uint8_t PIN_BUTTON = 0; // PB0 (digital, INPUT_PULLUP)
const uint8_t PIN_RELAY = 1; // PB1 (digital output)
const int LIGHT_THRESHOLD = 450; // 0..1023 - lower = darker
const int HYSTERESIS = 30; // prevents chatter
bool relayState = false;
int lastLdr = 0;
unsigned long lastDebounce = 0;
const unsigned long BUTTON_DEBOUNCE_MS = 50;
void setup() {
pinMode(PIN_RELAY, OUTPUT);
digitalWrite(PIN_RELAY, LOW); // ensure relay off at boot (adjust if active LOW)
pinMode(PIN_BUTTON, INPUT_PULLUP);
analogReference(DEFAULT); // use default reference; some builds may differ
}
void toggleRelay() {
relayState = !relayState;
digitalWrite(PIN_RELAY, relayState ? HIGH : LOW);
}
void loop() {
// Read LDR
int ldr = analogRead(PIN_LDR);
// Simple hysteresis logic
if (!relayState && ldr < (LIGHT_THRESHOLD - HYSTERESIS)) {
// it's dark -> turn ON
relayState = true;
digitalWrite(PIN_RELAY, HIGH);
} else if (relayState && ldr > (LIGHT_THRESHOLD + HYSTERESIS)) {
// it's bright -> turn OFF
relayState = false;
digitalWrite(PIN_RELAY, LOW);
}
// Button handling (debounced)
int buttonRead = digitalRead(PIN_BUTTON);
if (buttonRead == LOW) { // pressed (INPUT_PULLUP)
if (millis() - lastDebounce > BUTTON_DEBOUNCE_MS) {
toggleRelay();
lastDebounce = millis();
// simple delay to avoid multiple toggles; acceptable in tiny automation
delay(200);
}
}
// (Optional) small delay to reduce CPU usage
delay(200);
}
digitalWrite logic accordingly.Fast Shipping • Secure Checkout