3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Door Activated LED Lighting using Hall Effect Sensors

Step 5Moving from Arduino to AVR

Moving from Arduino to AVR
«
  • DSC08774.JPG
  • IMG_0648.JPG
The next step is to take our circuit and code from an arduino and transfer them to a standalone AVR chip. The reason I'm using an Attiny85 is because its the smallest AVR I have and I only needed 2 pins.
The fuses are set to an 8Mhz internal RC timer since timing isn't critical. Once done with the code, go right ahead and solder the circuit together.

Below is the code I used for the AVR. If you aren't familiar with AVR programming, most of what you need can be found here:http://iamsuhasm.wordpress.com/tutsproj/avr-gcc-tutorial/ and the tutorials here: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewforum&f=11&sid=f899212b86e2e0de2b660c0999f95fd7

#include <avr/io.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
#define lights PB0
#define magSense PB1

void initPorts();

int main(void)
{
volatile uint16_t val; // variable for reading the pin status
//volatile uint16_t lightMode = 0; // variable to keep the light's state
initPorts();
while(1){
val = bit_is_set(PINB, magSense); // read input value and store it in val
if (val) // make sure we got a 1
PORTB |= (1 << lights);
else
PORTB &= ~(1 << lights);
}
return 0;
}

void initPorts(){
PORTB = 0b000010; // enable pull up on sensor pin
DDRB = 0b000001; // set PB0 as output and rest as input
}

main.c729 bytes
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
8
Followers
1
Author:woody1189