Playing with Sensors, PCB with photoresistor and LED
Our LPKF Milling machines make the PCB board in following orders. For each steps we just need to press the button telling it to prepare proper tools and do the work.
After milling, I moved to soldering station, and soldered the small parts- Attiny44(It was really small as the name tells you explicitly), and even smaller parts(capacitor, resistors, photoresistor, led) to the PCB. Other than getting used to the concept of 'how soldering works' with your hands, things to consider in this part was getting right direction to capacitor(the arrow direction goes to the GND), and chips(you can find small dot from the bottom of the chip, and will be required to match it with your schematic). Also, including resistor value in your schematic might have helped me a lot, (and bother our instructor less :-)).
Here I followed steps described in here(Arduino as ISP)
and here(Attiny)
And you can find datasheet for Attiny chips(24/44/84) from here
Programming ATtiny44
int var = 0;
int thres = 160;
// the-setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(3, OUTPUT); //led
pinMode(2, INPUT_PULLUP); //photo-resistor
}
// the loop function runs over and over again forever
void loop() {
//digitalWrite(7, HIGH);
var = analogRead(2)/2; //read of voltage
if (var < thres){
digitalWrite(7, HIGH);
} else {
digitalWrite(7,LOW);
}
}
For Programming, I made a little bit of change from a 'blink' example which is already provided in
Arduino by adding right pin number for led(according to a schematic). I also declared input pullup
for photoresistor.
In the loop, Attiny44 reads a value from the designated pin(photoresistor).
Photoresistor changes resistance based on
the light, hence creating the voltage drop.
Specifically, in the dark, the resistance is high(several megohms (MΩ)), when it gets brighter,
resistance gets low(only to few hundred ohms).
'AnalogRead' will give values between 0
~ 1023 mapped from GND(0V) and 5V.
Using a multimeter, we found a kind of 'border' of voltage value for photoResistor is 1.4V; which we
set globally as 'thres=160'.
Hence the code does following: When the light coming to a photoresistor is smaller than
'thres'(threshold), led will blink, otherwise not.
Below is result from the assignment..