Showing posts with label LDR. Show all posts
Showing posts with label LDR. Show all posts

Monday, 15 December 2014

Tiny Bot

This has probably been done to death on the blogs but I was inspired by the born 2 craft site. Mine needs a bit of work in the code but I generally prefer to do something from scratch by myself after seeing an idea. Mine is also a bit larger as it is veroboard.


attiny85 robot

Design


The parts are all hacked off of other dead RC toys and boards, ATTiny85 is the only thing I paid for, makes me happy. The system uses a small LiPo striped from crashed mini RC helicopter, nice and light. The board layout was worked out in building, working around the socket as it was meant to be a 8 pin PIC proto-board. 

The wheels were made from ABS sheet, using a circle template at 23mm. Using the four centre marks on the diameter I drew between opposite ones to get the point to make a hole for the shaft, I used a dividers point and checked every now and then to see the fit, just push on with reasonable pressure. 
I used marine silicon to create a tread. This is done by running two strips along ABS sheet at the distance of the wheels, and roll back and forth.

The battery is charged by a full spec LiPo balance charger through the headers, the switch is moved towards the header toput in charge mode.


Some build pics, some:



Underside

Front View

Hardware

The design of the circuit is similar to the born 2 craft, but I made some modifications.
I added the flyback diodes to the two motors, I skimped on those to begin with as there was not enough space, but after changing the transistors for both motors I added them. The PCB layout is my design.


  • Transistors are BC817-40
  • Diodes are 1N4148
  • ATtiny85/45
  • Small model motors
  • 0805 resistors
  • LiPo 3.7v
  • Switch SPST
  • Wheels: ABS, 23mm dia.
  • Some copper wire, varying thickness
Schematic
PCB

Code


/*
Tiny Bot: an LDR based light following robot, or avoidance bot
 if you switch the drive function around.
 Hardware is based off the Light Bot by born 2 craft

 TODO:
 Add IR control
 Clean up code
 ##############################
 Written by:
 Reece May 
 rev1 12/15/14
 https://ziggyelectronics.blogspot.com

You may use the code and modify it as long as you keep the above
and make edit notes bellow and put it on github here:
https://github.com/ReeceM/Tiny-Bot.git
 */

#define Rmtr 1
#define Lmtr 0
#define Rsens 3
#define Lsens 2
#define drive_time 100

int Rav, Lav = 0;

void setup(){

  pinMode(Rmtr, OUTPUT); 
  pinMode(Lmtr, OUTPUT);
  pinMode(Rsens, INPUT);
  pinMode(Lsens, INPUT);

}

void ADread(){
  Rav, Lav = 0;   //clear the average to prevent errors

  for(int q = 0; q < 20; q++){ //loop to create average

    Rav += analogRead(Rsens);
    Lav += analogRead(Lsens);
  }

  Rav /= 19;
  Lav /= 19;
}

void drive_RIGHT(){
  digitalWrite(Lmtr, 0);

  digitalWrite(Rmtr, 1);
  delay(drive_time);
  digitalWrite(Rmtr, 0);
  delay(drive_time);
}

void drive_LEFT(){
  digitalWrite(Rmtr, 0);

  digitalWrite(Lmtr, 1);
  delay(drive_time);
  digitalWrite(Lmtr, 0);
  delay(drive_time);
}

void loop(){

  ADread();
  if(Rav < Lav){
    drive_RIGHT();
    //drive_LEFT();  //use this to avoid light
  }
  ADread();
  if(Lav < Rav){
    drive_LEFT();
    //drive_RIGHT();  //use this to avoid light
  }
}

Links

https://github.com/ReeceM/Tiny-Bot.git