ATtiny 45 has 4K flash, 6 I/O's, 256 bytes of RAM and 256 bytes of EEPROM. It has an internal oscillator which runs 8 or 16MHz. ATtiny 45 when compared to an Arduino Uno, it is so much cheaper. It is a suitable choice for small projects.
I used Eagle software to design my pcb. As I do not have enough time, I decided to make the ultimate lazy board. I have included pins so that I can re-use this board to try on different inputs. How to use eagle is already covered in Electronics production. I will not repeat the steps again.
Photo resistor or light dependent resistor, is a light controlled variable resistor, The resistance decreases with incresing incident light intensity. We are going to connect up the circuit as below. I will read in the value of the ldr and program it such that when we cover the ldr, the led will turn on. This is to simulate a night light circuit.
I am trying to pogram it such that when the surround is bright, the LED is off. When it is dim, it will be on.
const int ledPin = 3; //physical pin 2When the two detectors “see” different values, the sensor indicates it as movement of an object, such as a person or an animal.
Sensor need to warm up for 20 to 60 seconds after first applying power to stabilize else sensor output is not reliable.
We are going connect the input pin to pin 0(which is physical pin 5) The Vcc and gnd to the arduino's vcc and gnd.
int inputPin = 0; //pin 5
int LEDPin = 1; //pin 6
int val = 0;
int pirState = LOW;
void setup()
{
pinMode(LEDPin, OUTPUT);
pinMode(inputPin, INPUT);
}
void loop()
{
val = digitalRead(inputPin);
// read the input pin
if(val ==HIGH)
{
digitalWrite(LEDPin,HIGH);
pirState = HIGH;
}
else
{
digitalWrite(LEDPin,LOW);
pirState= LOW;
}
}
Ultrasonic is a high frequency sound (typically 40KHz is used). A short burst of wave ( often 8 cycles) is sent out by the speaker. The microphone listens for an echo. The time taken is recorded. Using calculation L = C X T/2
Put the "NewPing" folder in "libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sktech->Import Library->NewPing".
Download Putty for serial monitor
#include <NewPing.h>
#include <SoftwareSerial.h>
#define TRIGGER_PIN 0 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 4 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
// NewPing setup of pins and maximum distance.
int ledPin=3;
int rx=2;
int tx=1;
SoftwareSerial mySerial(rx,tx);
void setup() {
mySerial.begin(9600);
pinMode(ledPin,OUTPUT);
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
mySerial.print(sonar.ping_cm());
mySerial.println("cm");
if(sonar.ping_cm() <= 15){digitalWrite(ledPin,HIGH);}
else {digitalWrite(ledPin,LOW);}
}
1. Load the sketch
2. Plug in FTDI and check com port for Putty
3. Set up communication for putty
I began to appreciate the importance of documentation. I sometimes need to refer my pass documentation because i cannot remember the exact steps,for example, the steps in using the milling machine.
With China offering cheap ATtiny boards, we might not need to fabricate since they are so cheap.
With my lazy board, I will be able to test my laser gun project and evaluate if I need a more powerful processor.
I should have designed my board smaller and the jumper pins in sequence.
ATtiny ldr program
ATtiny pir program
ATtiny ultrasonic program
ATtiny eagle board
ATtiny eagle schematic
Check the documentation of Bootstrap here.