Nate
Published

Bicycle Safety System - Lane Tech PCL

A Particle photon 2 is used in order to add a motion activated electronic horn and a motion-activated light to my bicycle.

IntermediateFull instructions provided49
Bicycle Safety System - Lane Tech PCL

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Relay Breakout Module 5V
×1
iPhone
Apple iPhone
×1
Hornit dB140 Bike Horn V3
×1
1200 Lumen Bike Light - Red
×1
SG51R Micro Servo
×1
Photon 2
Particle Photon 2
×1

Software apps and online services

Pushover

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Diagram

Attached to the relay module is the bike horn. Attached to the servo is the bike light.

Code

Bike Light/Horn/Notifications

C/C++
#include "Particle.h"

SYSTEM_MODE(AUTOMATIC);
int echo = 1; //PWM pin needed?
int trig = 5;
int horn = 9;
long duration;
int distance;
int brightness;
Servo backServo;
SerialLogHandler logHandler(LOG_LEVEL_INFO);

void setup() {
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(horn, OUTPUT);
  Serial.begin(9600);
  pinMode(A2, OUTPUT);
  pinMode(0, INPUT);
  backServo.attach(A2);
  backServo.write(10);
  
}

void turnOnBack(){
    backServo.write(120);
    delay(250);
    backServo.write(10);
}

void turnOffBack()
{
    backServo.write(120);
    delay(2000);
    backServo.write(10);
}
void loop() {
    digitalWrite(trig, HIGH);
    delayMicroseconds(10);
    digitalWrite(trig, LOW);
    
    //read echo pin after triggering
    duration = pulseIn(echo, HIGH); //read up on pulsein
    distance = duration * 0.034 / 2; //speed of sound wave, then divide by 2
    
    Serial.println(String(distance) + "cm");
    
    if(distance < 2000) //some issues w/ longer distances
    {
        digitalWrite(horn, HIGH);
        turnOnBack();
        Particle.publish("notification", "CAR BEHIND YOU!!!!!!!");
        delay(4000);
        digitalWrite(horn, LOW);
        delay(2000);
        turnOffBack();
        delay(1000);
    }
    else{
        digitalWrite(horn, LOW);
        delay(250);
    }
  
  
}

Credits

Nate
2 projects • 0 followers

Comments