loading

ATtiny85 is one of the popular MCU from Atmel AVR family,this MCU is 8 pin only , small and Low cost chip,on the internet there are dozens of project based on ATtiny series.

The good thing about ATtiny85:

  • Have 5 pins I/O , 2 digital Pins can work as PWM
  • 3 analog pin
  • Support most of arduino commands like:
  1. pinMode()
  2. digitalWrite()
  3. digitalRead()
  4. analogRead()
  5. analogWrite()
  6. shiftOut()
  7. pulseIn()
  8. millis()
  9. micros()
  10. delay()
  11. delayMicroseconds()

In this short tutorial want to control Sugar device with AC Lamp using ATtiny directly as:

  • Control AC Lamp ON-OFF
  • Control AC dimmer Lamp .

Step 1: Hardware and Software

You need first to download the ATtiny boards folder and install it in arduino hardware path, to do so:

  1. Download the ATtiny folder.
  2. Unzip the folder and copy "attiny" folder and move it to your sketch book path "usually for Windows you could find it on "My document" - My document >> Arduino >>Hardware>>attiny -
  3. An alternative way, if you use arduino 1.6.2 version or newer , go to " tool>> boards>>boards manager and search attiny package and install it .

in both way,after you restart arduino IDE , you can see new board now on tool >> board >> attiny.

For this tutorial i will use ATtiny85 with 1MHz internal oscillator settings

For the hardware part we need:

  1. ATTINY85-20PU MCU
  2. Arduino Board as a programmer" I used Arduino UNO"
  3. Capacitor 10uF
  4. resistor 10K x 1pcs
  5. resistor 470R x 1pcs
  6. LED
  7. Button x 1pcs
  8. Potentiometer x 1pcs
  9. Sugar device.
  10. RJ12 Cable
  11. RJ Breakout
  12. Jumpers
  13. breadboard

Oscilloscope is optional ,but very important to see the PWM signal and AC Voltage output.

Step 2: Program ATtiny Using ARDUINO IDE

To program ATtiny , first we must prepare arduino Uno to act as a programmer.

  1. connect arduino Uno.
  2. Go to arduino IDE , File >> example >> arduino ISP.
  3. Upload this code to arduino board.
  4. connect ATtiny to arduino board as in the schematic."Just connect 10uF capacitor between arduino RST pin and GND".

Now we want to set the PWM frequency , in default the PWM frequency is about 62Hz and we will change the frequency to 490Hz to control Sugar device "Sugar device works on PWM frequency from 100Hz - 2KHz"

from ATtiny datasheet we can understand the Waveform generation mode and clock prescaler)(P 79 , 80)

so this code line will modify the frequency of PWM to become 490Hz

 TCCR0B = 0<<WGM02 | 1<<CS01

see the video in attachment to see the output PWM frequency


Step 3: First Code : Simple ON - OFF Switch

First this is a simple code to see if your code uploaded successfully.

The LED connected to pin 0 must blink for 1 sec

Blink Code :

<p>/*<br>  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin D0 on Attiny 85 
//Modified by Mohannad Rawashdeh</p><p>//http://genotronex.blogspot.com/
//...................................
int led = 0;</p><p>// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}</p><p>// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}</p>

Now after you check your code works successfully,You can connect the second circuit with Button to turn on the device for 3 Seconds each time you press the button

Simple Switch ON OFF

<p>#include <avr io.h="">       <br>#include <util delay.h="">    
int led = 0;          
int brightness = 12;   </util></avr></p><p>// the setup routine runs once when you press reset:
void setup()  { 
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
  pinMode(1, INPUT);  
  TCCR0B = 0<<wgm02 |="" 1<<cs01;=""  ="" tccr0b="TCCR0B" &="" 0b11111101="" 0x03;="" } <="" p=""></wgm02></p><p>// the loop routine runs over and over again forever:
void loop()  { 
boolean pot=digitalRead(1);
if(pot)
{
brightness=64;  
analogWrite(led, brightness);          
delay(3000);
}
else
{
brightness=12;  
analogWrite(led, brightness);            
}
delay(100);
}</p>

Step 4: You Love Sugar Device ? We Need Your Help

Sugar is a startup project , designed and Manufactured the Prototypes in Taipei - Taiwan and Now sugar need your help to become a real product in the market and bring a simple tools to control AC voltage.

Sugar comes in 2 different type:

  • Sugar300 : can Handle Up to 300 W
  • Sugar1000 : can Handle Up to 1000 W

and both type support AC output voltage control "For Dimmer applications" Hope you support us and become our backer Now on Indiegogo Campaign you can visit our campaign page https://igg.me/at/sugdev/x .

Keep in touch with us on:

Facebook: https://www.facebook.com/SugarWorld.net/

Twitter: https://www.facebook.com/SugarWorld.net/

Instagram: https://www.instagram.com/sugardevice/

Youtube official accounts: https://www.youtube.com/channel/UCDthbcEGR-r0NB49...

Visit Our website to see all features and tutorial and see the story behind sugar

http://www.sugarworld.net

http://www.sugarworld.net/story-behind-sugar

http://www.sugarworld.net/features

Step 5: AC Dimmer Code

Dimmer code is more useful for many application , here is the schematic for the connection, potentiometer used to control the dimming output.

the oscilloscope waveform show to you the AC output voltage controlled by sugar device.

code:

<p><avr io.h=""><util delay.h="">int led = 0;          
int brightness = 128;   </util></avr></p><p>// the setup routine runs once when you press reset:
void setup()  { 
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
  TCCR0B = 0<<WGM02 | 1 <<CS01<wgm02 |="" 1<<cs01;=""  ="" tccr0b="TCCR0B" &="" 0b11111101="" 0x03;="" } <="" p=""></wgm02></p><p>// the loop routine runs over and over again forever:
void loop()  { 
int pot=analogRead(3);
brightness=map(pot,0,1023,12,64);
brightness=constrain(brightness,12,64);
analogWrite(led, brightness);          
delay(1000);
}</p>
<p>Thankyou for condensing this process down so effectively. I find that when i explain something that i benefit as well because we achieve a clarity of thought.</p>

About This Instructable

1,099views

23favorites

License:

Bio: revolutionary device designed to control AC Loads working on 110V/220V allowing to control High voltage AC loads using Microcontrollers Like AVR,PIC,STM32 or ... More »
More by Sugar Device:IR remote and Arduino Control AC Voltage device Labview Meet Arduino ! Control AC dimmer lamp  ATTiny85 imazing and simple way to control AC Lamp 
Add instructable to: