This is pretty straight forward, a photosensor on flying leads
to a small box with a ATTINY85 board + regulator + buzzer +
1 cap + battery + push button (unless machine turn off extinguishes
led).
Basic code, use mBlock to generate code :
Note the photosensor is a classic : (connect that to gnd and in series with a R to Vdd, junction to
analog pin 0. R value 1/2 the range photocell experiences when LED off then on. Note you can also
get these in various packages, so look around for what best fits your need. You could also print
a 3D bracket to hold sensor. Lean toward sensor with lower R range values, say into the 1K to 10K
range, as that lowers the value of R needed, which makes the pin lower Z hence less subject to
stray pickup, eg. noise.
You will have to adjust PhotoSensorTripV to accommodate the R you use in the divider.
You do this prior to programming in mBlock. Or add a pot, read it on a second analog
pin, and use its value to set the trip V so you can adjust in circuit. Not I did not add code
for Hysteresis in mBlock to eliminate small variances and noise, that would be advisable.
The code mBlock produces from above to cut and paste in Arduino IDE :
Code:
// generated by mBlock5 for <your product>
// codes make you happy
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
float PhotoSensorTripV = 0;
float PhotoSensorV = 0;
void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}
void setup() {
pinMode(5,OUTPUT);
pinMode(A0+0,INPUT);
PhotoSensorTripV = 500;
// Initialize Buzzer to Off
digitalWrite(5,0);
while(1) {
if(analogRead(A0+0) < PhotoSensorTripV){
// Buzzer On
digitalWrite(5,1);
}else{
// Buzzer Off
digitalWrite(5,0);
}
_loop();
}
}
void _loop() {
}
void loop() {
_loop();
}
Note the analog read yields a reading corresponding to V on the pin as follows -
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
Then use Arduino to program ATTINY85 board :
Find many great new & used options and get the best deals for Digispark Kickstarter Attiny85 Micro USB Development Board for Arduino US Stock at the best online prices at eBay! Free shipping for many products!
www.ebay.com
Note there are cheaper versions of this board, shop it.
To setup Arduino to use / program digispark board -
How to set up the Arduino IDE to program a Digispark board in Windows 10.
Use a 5V piezo buzzer to connect to pin 5
Note I am showing use of dip package, but small board has regulator and bypass
cap for its ATTINY85.
Regards, Dana.