My latest project is making a hat with proximity sensors and haptic feedback for the blind. While waiting for parts to come in the mail i wanted to make something for fun with the parts i do have. I got some inspiration from Helios handle bars and put proximity sensors on a bike with led feedback. 

When bicycling on the road it is important to know if there is a car behind you or beside you. You could always just turn your head, but that can  cause you to turn into the direction you are looking, which could be bad. Another option would be to mount a mirror to see behind you. I wanted something different, mostly just because why not. So I decided to mount some ultrasonic proximity sensors and LED lights instead. I threw this together with the parts I had and next to no planning, so there are probably betters ways to do things.

 

 undefined

 

BOM 

1 Bicycle

1 Under the seat style bicycle bag

3 hc-sr04 proximity sensor/ or which ever you want to use

1 arduino or microcontroller of your choice

3 LEDs

3 transistors (I used tip120s. I recommend that you use something better I just had some laying around from the 70's) Please do not go out and buy this part there are better choices. 

3 1k resistors

3 33 ohm resistors

3 diodes (rectifier of some type) Note:Diodes are optional. 

1 a small board to solder on

some ethernet cable

a handful Jumper wires

some wire wrap wire and tool

some solder and an iron

zip ties

shrink tube

electrical tape

rubber bands

5 volt battery pack (get a rechargeable usb one for phones)

usb cable

1 multimeter

 

Instructions

1. Make a driver for the LEDs. I originally made this for vibration motors but it works fine for LEDs

Get the board you have for soldering. Solder on a usb connection for power. Just cut the head off a usb and hook it up, see which have power with a multimeter. Put the usb connection on the board. Use another wire to hold down the connector so the connections to the wires don't get pulled on. Attach the third pin of each tip120 to ground. Attach the first pin of each tip120 to a 1k resistor. Attach a jumper cable or wire to the other end of the resistor, this will hook up to a gpio pin on the microcontroller. The 33 ohm resistors attach to the second pins of the tip120s (the other end of that goes to the anode of the LED). I recommend not putting the resistor on the board so you can use it for other things later if you want. I put the resistor on the LED. If you added the resistor to the board add a wire to that resistor and let it hang for a bit, if you didn't just add the wire to the second pin then add the resistor to the wire and use some shrink tube. Now split the voltage up from the usb into three spaces, attach a diode from positive to the second pin (before the resistor) to protect your micro controller if you want to use this to drive a motor later on). If you are just going to use this for the LEDs you dont need the diodes because LEDs are diodes. Also add three a wire from positive to hang off. For each tip120 we should have three wires. To GPIO, transistor controlled ground, and +. Add jumper wire from ground and a jumper wire from + for powering the arduino/microcontroller. 

Test your circuit: Add the LED to the + and transistor controlled ground, add power. Tap the wire for the gpio to power, the LED should light up. Test each one.  

2. Make the cable: I use an Ethernet cable because it has lots of wires inside, it is durable, and I have spools of it. Cut it to a decent length for going from your seat to the handle bars along the bar. Leave slack so you can turn and such. Hook up the six wires for the LED to wires inside the Ethernet cable. On the other end of the cable add the LEDs. Use shrink wrap and tape to cover the LED's wires. I taped up each LED then zip tied it to my handle bars. Zip tie the rest of the Ethernet cable to the frame of the bicycle.

undefined

3. Get the proximity sensors: They have 4 pins. Make a wire that splits ground from the Arduino 3 ways, do the same for 5v. Attach the proximity sensors to 5V, ground, and then the other 2 pins of each proximity sensor to whatever digital GPIO pins you want (I used 8-13).

4. Connect things: Attach the three wires from the circuit you made to GPIO pins with the ~ symbol on the Arduino. I used 3, 5, and 6. Attach the + and - wires from the circuit to the Arduino's ground and to Vin. 

5. Program the thing: It isn't pretty but it works. Adjust the sensitivity and stuff how you want.

 

const int distthresh =1500;

const int pingPin1 = 9;
const int echoPin1 = 8;
const int motorPin1 = 3;
long distance1;
long duration1;
  
const int pingPin2 = 11;
const int echoPin2 = 10;
const int motorPin2 = 5;  
long distance2;
long duration2;

const int pingPin3 = 13;
const int echoPin3 = 12;
const int motorPin3 = 6;
long distance3;
long duration3;
  

  
void ping();
void convert_to_PWM();

void setup()
{

    pinMode(pingPin1,OUTPUT);
    pinMode(echoPin1,INPUT);
    pinMode(motorPin1,OUTPUT);
    
    pinMode(pingPin2,OUTPUT);
    pinMode(echoPin2,INPUT);
    pinMode(motorPin2,OUTPUT);
  
    pinMode(pingPin3,OUTPUT);
    pinMode(echoPin3,INPUT);
    pinMode(motorPin3,OUTPUT);
}

void loop()
{
  //read sensors
  ping();
  convert_to_PWM();
}

void ping()
{
    //activate sensor
    digitalWrite(pingPin1, LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin1, HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin1, LOW);
    //reads signal that bounces back
    duration1= pulseIn(echoPin1,HIGH);
    distance1 = duration1/ 29 / 2;
    
        //activate sensor
    digitalWrite(pingPin2, LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin2, HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin2, LOW);
    //reads signal that bounces back
    duration2= pulseIn(echoPin2,HIGH);
    distance2 = duration2/ 29 / 2;
    
        //activate sensor
    digitalWrite(pingPin3, LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin3, HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin3, LOW);
    //reads signal that bounces back
    duration3= pulseIn(echoPin3,HIGH);
    distance3 = duration3/ 29 / 2;
 }

  
void convert_to_PWM()
{
 
  if (distance1<distthresh )
  {
      digitalWrite(motorPin1, HIGH);
  }
  else
  {
     digitalWrite(motorPin1, LOW);
  }

  if (distance2<distthresh )
  {
      digitalWrite(motorPin2, HIGH);
   }   
     else
  {
     digitalWrite(motorPin2, LOW);
  }

  if (distance3<distthresh )
  {
      digitalWrite(motorPin3, HIGH);
   }   
   else
  {
     digitalWrite(motorPin3, LOW);
  }  

}

 

6. Stick all of the things into the bicycle bag and put it under your seat. Plug the usb connection on the circuit into the battery pack. It should work.

7. Rubber band the proximity sensors to the bag. I recommend that you stick something under the side ones to angle them backwards some. 

 undefined

 If something compelled you to do this too let me know about it in the comments. 

 For best results have the side sensors angled back like this:

 

undefined