Go Down

Topic: The cheapest line follower? (Read 513 times) previous topic - next topic

mart256

Aug 21, 2014, 02:37 am Last Edit: Aug 21, 2014, 09:29 pm by mart256 Reason: 1
I made this line follower using 2 CD's as wheels. 2 Hitec modified servos as gear dc motors, a 3 dollar microcontroller (PIC16F873A), 2 phototransistors and 2 IR leds and 1 small caster wheel.

https://www.youtube.com/watch?v=4Izx8Hb6DcA&feature=youtu.be

EDIT 1: Here I add the code (WARNING: The code is written on PIC C language, you can translate it to Arduino)

Code: [Select]
#include <16F873A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOCPD,NOWRT
#use delay(clock=20000000)
//#byte PORTA=0X05
#BYTE PORTB=0X06
//#use rs232(baud=56000, xmit=PIN_C6,rcv=PIN_C7)

//#ORG 0x0F00,0x0FFF {} //for the 4k 16F873/4  //bootloader space

VOID MAIN(){
//VARIABLES AUXILIARES
UNSIGNED INT CONTADOR;

SET_TRIS_B(0X03);                           //PIN B0 & B1 as inputs
//PORTB=0X00;

DELAY_MS(500);

   WHILE(TRUE){

       PORTB=0X0C;
                               //RUEDAS ENCENDIDAS (B3 Y B4)
           FOR(CONTADOR=0;CONTADOR<=5;CONTADOR++){
               DELAY_MS(10);
               //IF(INPUT(PIN_B0)==0 && INPUT(PIN_B1)==0){CONTADOR=0;}
               IF(PORTB==0X0C){CONTADOR=0;}
               }                                         //goes Foward if there is black line on both sensors

           IF(INPUT(PIN_B0)==1){PORTB=0X08;
               FOR(CONTADOR=0;CONTADOR<=3;CONTADOR++){
               DELAY_MS(10);
               IF(INPUT(PIN_B0)==1){CONTADOR=0;}
               }                                        //turns right until left sensor catches black line

               }
           ELSE {PORTB=0X04;
               FOR(CONTADOR=0;CONTADOR<=3;CONTADOR++){
               DELAY_MS(10);
               IF(INPUT(PIN_B1)==1){CONTADOR=0;}
               }                                       //turns left until right sensor catches black line

               }

   }

}

raschemmel

Very cool !  Are you going  to release the DIY documentation or is this SHOW & TELL without the TELL ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,
DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

mart256


Very cool !  Are you going  to release the DIY documentation or is this SHOW & TELL without the TELL ?


Thanks for the appretiation. I'll gladly share steps to DIY on weekend (short of time now) , and now I'm open to any question.

raschemmel

Questions ?
Yeah, I have one. Why a PIC instead of a $3 Pro-Mini from eBay ?
Also , did you write an algorythmn that could be used to write the arduino code or did you " skip" that step and codd it on the fly ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,
DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

mart256

#4
Aug 21, 2014, 06:06 am Last Edit: Aug 21, 2014, 06:07 am by mart256 Reason: 1
I did this proyect two years ago, when I knew little about electonics and only knew about pics (not heard about arduino yet back then). Today I'd use an Attiny45/85 or the minipro as you suggested.

I still have the code (which I did on the fly) and will share on weekend too. It is very short and easy to translate to arduino. (Just a main loop with some for loops inside, using digital input and output).

raschemmel

Ok. You're forgiven. I like the ATtiny85 idea.  I buy  em by the dozen. They're so usrful and I have a Kickstarter TinyISP.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,
DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

mart256

I'm looking for a good price for attiny85. Where do you buy them? Soic or dip?

raschemmel

Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,
DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Go Up