element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum ATTiny 85
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 6 replies
  • Subscribers 392 subscribers
  • Views 851 views
  • Users 0 members are here
Related

ATTiny 85

morbee
morbee over 9 years ago

Hi Guy's,

 

I have a little alarm i am trying to put together that consists of a HC SRO4 distance sensor and a Piezo Buzzer. wiring this up to the arduino is straight forward and the code is fairly straight forward as can be seen below.

My Question is which pins would i connect to on an ATTiny 85 once i have programmed it with this code?

 

*/

 

 

#define trigPin 13

#define echoPin 12

#define buzzer 11

 

 

 

 

void setup() {

 

 

  pinMode(trigPin, OUTPUT);

  pinMode(echoPin, INPUT);

  pinMode(buzzer, OUTPUT);

 

 

}

 

 

void loop() {

  long duration, distance;

  digitalWrite(trigPin, LOW);

  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);

//  delayMicroseconds(1000);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = (duration/2) / 29.1;

  if (distance < 50) {  // This is where the buzzer On/Off happens

    digitalWrite(buzzer,HIGH);

}

  else {

    digitalWrite(buzzer,LOW);

   

   (distance >= 200 || distance <= 0);}

  }

  • Sign in to reply
  • Cancel

Top Replies

  • morbee
    morbee over 9 years ago +1
    Hi Guys, Thank you to Henry for putting me on the right track and i now understand the method for programming ATTiny. I have a little yorkshire terrier that insists on sneaking out the back courtyard gate…
Parents
  • snu
    snu over 9 years ago

    Use this instead:

     

    #define trigPin 2

    #define echoPin 1

    #define buzzer 0

     

    It will use pin 5 as pin 0, pin 6 as pin 1, and pin 7 as pin 2, although for pin 2 you may have to burn the fuses differently.52713d5b757b7fc0658b4567.png

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • snu
    snu over 9 years ago

    Use this instead:

     

    #define trigPin 2

    #define echoPin 1

    #define buzzer 0

     

    It will use pin 5 as pin 0, pin 6 as pin 1, and pin 7 as pin 2, although for pin 2 you may have to burn the fuses differently.52713d5b757b7fc0658b4567.png

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • morbee
    morbee over 9 years ago in reply to snu

    Hello Henry,

     

    Thank you very much for your reply and i will change my code to what you have suggested.

    I am newbie to the world of electronics and have started up with it as a hobby more than anything else. Please could you explain the meaning of burning the fuses for pin 2 differently. I am sure if i understand what you mean by this i can try and figure this out.

     

    Kind Regards

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • snu
    snu over 9 years ago in reply to morbee

    Use AVRdudess and the Arduino as ISP setup or your own AVR programmer. There's a fuse calculator in AVRdudess. I will gladly find the fuse setup for you if you want, but first try programming the chip and see if pin D2 works.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • morbee
    morbee over 9 years ago in reply to snu

    Hi Henry,

    Thanks for the feedback, I have used my arduino as the programmer using pins 2 (Trigg), 3 (Echo) and 0 for the buzzer. ATTiny is now programmed perfectly and working as i planned.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • snu
    snu over 9 years ago in reply to morbee

    Glad to hear it! Very creative project.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube