Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hesam Moshiri
Published © CC BY-NC-SA

Non Contact Hand Sanitizer Dispenser [Pro Version]

Free and Open-Source Hand Sanitizer Dispenser with Laser-Cut Acrylic Enclosure [Pro Version]

BeginnerFull instructions provided2 hours3,274
Non Contact Hand Sanitizer Dispenser [Pro Version]

Things used in this project

Hardware components

ATTiny13
×1
2N7000
×1
TSOP1738 (HS0038)
×1
BD139
×1
5mm IR-T Diode
×1
2-Pin XH MaConnectors
×1

Story

Read more

Custom parts and enclosures

CAD

Schematics

Sch-1

Code

Code

C/C++
#include <tiny13.h>
#include "delay.h"

unsigned char activated = 0;
unsigned int counter = 0;

// Declare your global variables here

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Place your code here

if (PINB.3 == 0 && activated == 0)
activated = 1;


if (activated == 1)
counter ++;

switch (counter)
{
case 15:
PORTB.1 = 1;
break;

case 23:
PORTB.1 = 0;
break;

case 372:
counter = 0;
activated = 0;
break;
}
}


void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=(1<<CLKPCE);
CLKPR=(0<<CLKPCE) | (0<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0);
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Function: Bit5=In Bit4=Out Bit3=In Bit2=In Bit1=Out Bit0=In
DDRB=(0<<DDB5) | (1<<DDB4) | (0<<DDB3) | (0<<DDB2) | (1<<DDB1) | (0<<DDB0);
// State: Bit5=T Bit4=0 Bit3=T Bit2=T Bit1=0 Bit0=T
PORTB=(0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 9.375 kHz
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
// Timer Period: 27.307 ms
TCCR0A=(0<<COM0A1) | (0<<COM0A0) | (0<<COM0B1) | (0<<COM0B0) | (0<<WGM01) | (0<<WGM00);
TCCR0B=(0<<WGM02) | (1<<CS02) | (0<<CS01) | (1<<CS00);
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=(0<<OCIE0B) | (0<<OCIE0A) | (1<<TOIE0);

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=(0<<INT0) | (0<<PCIE);
MCUCR=(0<<ISC01) | (0<<ISC00);

// Analog Comparator initialization
// Analog Comparator: Off
// The Analog Comparator's positive input is
// connected to the AIN0 pin
// The Analog Comparator's negative input is
// connected to the AIN1 pin
ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIS1) | (0<<ACIS0);
ADCSRB=(0<<ACME);
// Digital input buffer on AIN0: On
// Digital input buffer on AIN1: On
DIDR0=(0<<AIN0D) | (0<<AIN1D);

// ADC initialization
// ADC disabled
ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);


// Global enable interrupts
#asm("sei")

while (1)
{

PORTB.4 = ~ PORTB.4;
delay_us(12);

}
}
No preview (download only).

Credits

Hesam Moshiri
51 projects • 36 followers
https://www.youtube.com/c/MyVanitar/videos
Contact

Comments

Please log in or sign up to comment.