Bajdi electronics

Hobby electronics website

Browse: Page 32

TCRT5000 sensor

By Bajdi on March 2, 2012

TCRT5000 connected to Arduino Uno

TCRT5000 connected to Arduino Uno

I nearly forgot I bought these little sensors. The TCRT5000 is a reflective infrared sensor, it’s a small plastic holder with an IR led and a photo transistor. The IR led emits invisible IR light, when an object is placed in front of it the light is bounced back to the phototransistor. The TCRT5000 has 4 pins and is very easy to connect to an Arduino. You can download the datasheet here to see the pinout.

The collector (C) of the phototransistor is connected to the digital pin on the Arduino, the emitter (E) is connected to ground. The anode (A) of the IR led is connected to a 100ohm resistor, the other end of the resistor goes to 5V. The cathode of the led goes to ground. The range of these little sensors is not big and from testing I learned that they are very sensitive to the light present in the room. The range is only a couple of centimetres. The best thing about them is that they are very cheap, I bought 5 of these from Yourduino for 2$. They can be used to make an encoder or to sense objects that are really close 🙂

Here is the sketch that I used to try them out:

/* http://www.bajdi.com
   TCRT5000 sensor connected to Arduino Uno
   TCRT5000 pins: (see datasheet http://www.vishay.com/docs/83760/tcrt5000.pdf )
     C = Arduino digital pin 2
     E = GND
     A = 100 ohm resistor, other end of resistor to 5V
     C = GND
*/
const int tcrtPin = 2;     // connected to the TCRT5000 C pin
const int led =  13;      // the number of the LED pin

// variables will change:
int tcrtState = 0;         // variable for reading the TCRT5000 status

void setup() {
  // initialize the LED pin as an output:
  pinMode(led, OUTPUT);      
  // initialize the tcrt5000 pin as an input, and turn on the internal pullup resistors:
  pinMode(tcrtPin, INPUT); 
  digitalWrite(tcrtPin, HIGH);  
}

void loop(){
  // read the state of the tcrt5000:
  tcrtState = digitalRead(tcrtPin);

  // check if the tcrt5000 sensor detects something.
  // if it is, the tcrtState is LOW:
  if (tcrtState == LOW) {     
    // turn LED on:    
    digitalWrite(led, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(led, LOW); 
  }
}

Posted in Arduino sketches | Tagged TCRT5000 | 3 Responses

My rover 5: now with sensors

By Bajdi on February 24, 2012

Found some time today to add some servos and sensors to my Rover 5. I started by drilling some more holes in the plexi glass to mount the servos and my little power PCB. I used nylon M2 nuts and bolts to fix the servos to the plexi glass, found these on ebay. To mount the SRF06 ultrasonic sensor to the micro 9G servo I bought a small ABS box on ebay. I made some holes in it to mount the SRF06 sensor, quite happy with the result. On the front I mounted a sensor pan / tilt kit with the Dagu IR compound eye mounted on top of it. I have not written any code for the IR compound eye but I’ve found a test sketch on letsmakerobots, so that gives me something to experiment with.

Posted in Dagu Rover 5 | Tagged robot, ultrasonic | Leave a response

Arduino servo sweep

By Bajdi on February 23, 2012

Now that I have my Rover 5 working I want to add a couple of servos with SRF06 ultrasonic sensors mounted on top of them. So I can let the SRF06 sensors detect an obstacle. The Arduino IDE comes with a simple servo library. One of the examples that comes with this library is a sweep example. It’s a very simple sketch that lets the servo move from 0 to 180 degrees. It uses the delay function to wait for the servo to reach it’s position. The library does not have any function to set the speed of the servo. Of course with some programming magic and making use of the millis function you can make a speed adjustable sweep sketch. But this is a bit to complex for a newbie like me.

After some searching on the Arduino forum I stumbled on the VarSpeedServo library. This library has a function to set the speed of the servo. Unfortunately it doesn’t come with any examples. But there was a sketch posted on the forum to sweep 4 servos. I copied the sketch and simplified it to just sweep 1 servo. You have to watch out with the speed settings. You can set the speed between 1 and 255, but no servo will be able to handle a speed of 255. After some testing I found that a speed of 30 was fast enough to let a servo sweep with the SRF06 on top of it. I wonder if this library will work with a continuous rotation servo. Would be very handy to control the speed of such a servo. Something that I will have to try out.

Here is the sketch to sweep one servo:

// speed controlled Servo Sweep
// see: http://arduino.cc/forum/index.php/topic,61586.0.html
//
// Michael Margolis 4 August 2011
// edited by http://www.bajdi.com

#include <VarSpeedServo.h>

VarSpeedServo MyServo;        // servo objects

int servoSpeeds = 30; // sweep speed, 1 is slowest, 255 fastest)
int servoMinPosition = 0; // the minumum servo angle
int servoMaxPosition = 180; // the maximum servo angle

void setup()
{

  MyServo.attach(9);       
  MyServo.slowmove(servoMinPosition,servoSpeeds) ; // start sweeping from min position

}

void loop()
{
  // sweep the servos

  if( MyServo.read() == servoMinPosition)
  {
    MyServo.slowmove(servoMaxPosition,servoSpeeds) ; 
  }       
  else if( MyServo.read() == servoMaxPosition)
  {
    MyServo.slowmove(servoMinPosition,servoSpeeds) ; 
  }       

}

Posted in Arduino sketches | Tagged servo | 2 Responses

« PreviousNext »

Recent Posts

  • 3D Printer extruders
  • Mearm forked
  • Arduino time lapse – camera pan device
  • Bought a 199$* Prusa I3 3D printer
  • Simple DIY lab power supply
  • Bajduino
    • Bajduino 1284
    • Bajduino 328
  • Stepper robot arm

Recent Comments

  1. 200+ Arduino Projects List For Final Year Students - He Loves Math on Obstacle avoiding robot made from cheap parts
  2. MP3 Alarm Clock: Crafting Customized wake-Up tunes with Arduino on Arduino MP3 alarm clock
  3. Bas on L9110 H-bridge module
  4. Victor on L9110 H-bridge module
  5. WAQAR AHMED on Dimming led with IR remote control

Archives

  • June 2016
  • August 2015
  • May 2015
  • January 2015
  • December 2014
  • November 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011

Categories

  • 3D printing
  • Arduino
  • Arduino sketches
  • Bajdupod 996R
  • Bajdupod 9G
  • Bob the biped
  • Buying parts
  • Dagu Rover 5
  • Dagu service droid
  • Gentoo
  • Insectbot
  • Line following robot
  • Raspberry Pi
  • Self balancing bot
  • Bajduino
    • Bajduino 1284
    • Bajduino 328
  • Stepper robot arm

Copyright © 2026 Bajdi electronics.

Powered by WordPress and Hybrid by Bajdi.