andyz1207
Published © GPL3+

Automated Bike Turning Light!

An automated turning detection and display system for bikes. Using this, we won The Conrad Challenge CYBER-TECH& SECURITY Silver Medal

IntermediateProtip10,247
Automated Bike Turning Light!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Speaker, Piezo
Speaker, Piezo
×1
Voltage Regulator Module
Digilent Voltage Regulator Module
×4
Arduino Wireless SD Shield
Arduino Wireless SD Shield
×1
Flash Memory Card, SD Card
Flash Memory Card, SD Card
×1
Programmable Soft LED Board
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×2
Rocker Switch, SPST
Rocker Switch, SPST
×2
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×2
synchronizing line
×1
Bike Holder
×3
Alligator clip & rope
×4

Software apps and online services

Arduino IDE
Arduino IDE
AutoCAD

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Solder Wire, Lead Free
Solder Wire, Lead Free
Soldering Station, 110 V
Soldering Station, 110 V
PCB Holder, Soldering Iron
PCB Holder, Soldering Iron
Laser cutter (generic)
Laser cutter (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

Holder of Turning Detection Part (In the front)

The outside of the Turning Detection part

Holder of the 3 positioned switched

Held the 3 positioned switch

Display part Holder

Held the Led Display Screen

Schematics

Display System Schematics

Display System Schematics #2

Code

Code for Turning Detection

C/C++
Code for Turning Detection
#include <SoftwareSerial.h> 
 
// Pin10RXHC05TXD
// Pin11TXHC05RXD
//
//const int M1 = 2; //define ENA Pin

const int KEY1 = 2;//
const int KEY2 = 3;//


SoftwareSerial BT(12, 13); 
char Indicator = 0;
char val;
char KEY_state = 0;
char prior = 0;// 01 

void Get_Command()
{
    int buttonState1 = digitalRead(KEY1);
    if(buttonState1 == HIGH)
    {
      buttonState1 = 1;
    } 
    else
    {
      buttonState1 = 0;
    }
    int buttonState2 = digitalRead(KEY2);
    if(buttonState2 == HIGH)
    {
      buttonState2 = 1;
    } 
    else
    {
      buttonState2 = 0;
    }
    if((buttonState1 == 1)&&(buttonState2 == 1))
    {
      Indicator = 0;
      prior = 0;
    }
    if((buttonState1 == 0)&&(buttonState2 == 1))
    {
      Indicator = 1;
      prior = 1;
    }
    if((buttonState1 == 1)&&(buttonState2 == 0))
    {
      Indicator = 2;
      prior = 1;
    }  
}
 
void setup() {
  Serial.begin(9600); 
  Serial.println("BT is ready!");
  // HC-0538400
  BT.begin(38400);

  pinMode(KEY1,INPUT_PULLUP );
  pinMode(KEY2,INPUT_PULLUP );
  
  
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);

  digitalWrite(12,LOW);
  digitalWrite(13,LOW); 

  
}
void Get_Position()
{
  //
  int Sensor_Resistence = 0;//1023
  int Sensor_Resistence_Raw = analogRead(A0);//
  //
  Sensor_Resistence = Sensor_Resistence_Raw;//    0-256

  Serial.print("Sensor_Resistence_Raw");
  Serial.println(Sensor_Resistence_Raw,DEC);
  if(prior == 0)
  {
    if((Sensor_Resistence >= 450)&&(Sensor_Resistence <= 550))
    {
      Indicator = 0;
    }
    else if(Sensor_Resistence <450)
    {
      Indicator = 2;
    }
    else if(Sensor_Resistence >550)
    {
      Indicator = 1;
    }
  }
}
void loop() {
  delay(200);
  Get_Command();// 
  Get_Position();//  
  BT.print(Indicator,DEC);//
  Serial.println(Indicator,DEC);//
  
//  if (Serial.available()) {
//    val = Serial.read();
//    BT.print(val);
//  }
// 
//  if (BT.available()) {
//    val = BT.read();
//    Serial.print(val);
//  }
}

Code for Display

C/C++
Code for Display on LED Board ( Control )
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <SoftwareSerial.h>

#define PIN1 6

const int MUSIC1 = 3;//
const int MUSIC2 = 4;//
const int MUSIC3 = 5;//

//const int MODECHANGE = 5;//

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(512, PIN1, NEO_GRB + NEO_KHZ800);
SoftwareSerial BT(8,9);   //8  rx,9  tx
//SoftwareSerial BT2(10,11);   //8  rx,9  tx
#define COLOR strip1.Color(5, 5, 0) 


char cmd,lastcmd;

void Music_Control(uint8_t state);
void second_part();
void first_part();
void Third_part();
void Fourth_part();
void forword();
void First_down();
void Second_down();
void First_up();
void Second_up();
void Front(){
  strip1.setBrightness(0);strip1.show();
  strip1.setBrightness(255);strip1.show();
    forword();
  }
void Left(){
  strip1.setBrightness(0);strip1.show();
  strip1.setBrightness(255);strip1.show();
  first_part();
  Second_up();
  }
void Right(){
  strip1.setBrightness(0);strip1.show();
  strip1.setBrightness(255);strip1.show();  
  First_up(); 
  second_part();
  }

void setup() {
  
  BT.begin(38400);
  Wire.begin();

  strip1.begin();
  strip1.show(); // Initialize all pixels to 'off'  

  pinMode(MUSIC1,OUTPUT);
  pinMode(MUSIC2,OUTPUT);
  pinMode(MUSIC3,OUTPUT);
  digitalWrite(MUSIC1,HIGH);
  digitalWrite(MUSIC2,HIGH);
  digitalWrite(MUSIC3,HIGH);
//  pinMode(MODECHANGE,OUTPUT);
}

void loop() {
  if(BT.available()>0)
  {
    cmd=BT.read();
    if(cmd!=lastcmd){
        if(cmd=='0') {cmdTx(cmd);Front();Music_Control(0);}
        if(cmd=='1') {cmdTx(cmd);Left();Music_Control(1);}
        if(cmd=='2') {cmdTx(cmd);Right();Music_Control(2);}
        lastcmd=cmd;
       }  
    }
delay(10);
}

void cmdTx(char cmd){
  Wire.beginTransmission(1);
  Wire.write(cmd);
  Wire.endTransmission(); 
  }

Code for Display #2

C/C++
Code for Display ("Graphic Decoding")
void Music_Control(uint8_t state)
{
  if(state == 0)
  {
    digitalWrite(MUSIC1,LOW);
    delay(1000);
    digitalWrite(MUSIC1,HIGH);
    digitalWrite(MUSIC2,HIGH);
    digitalWrite(MUSIC3,HIGH);
  }
  else if(state == 1)
  {
    digitalWrite(MUSIC2,LOW);
    delay(1000);
    digitalWrite(MUSIC1,HIGH);
    digitalWrite(MUSIC2,HIGH);
    digitalWrite(MUSIC3,HIGH);
  }
  else if(state == 2)
  {
    digitalWrite(MUSIC3,LOW);
    delay(1000);
    digitalWrite(MUSIC1,HIGH);
    digitalWrite(MUSIC2,HIGH);
    digitalWrite(MUSIC3,HIGH);
  }
}

void first_part(){   
      strip1.setPixelColor(0, COLOR);
//      strip1.show();
     for(int i=30;i<=34;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=60;i<=68;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=90;i<=102 ;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=120;i<=136;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=150;i<=170;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=180;i<=204;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=210;i<=238;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=240;i<=255;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
     strip1.show();               
  }
void second_part(){

      for(int i=256;i<=271;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=273;i<=301;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=307;i<=331;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=341;i<=361;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=375;i<=391;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
          for(int i=409;i<=421;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
          for(int i=443;i<=451;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
          for(int i=477;i<=481;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }

      strip1.setPixelColor(511, COLOR);
//      strip1.show();
    strip1.show();
  }
void Third_part(){   
     for(int i=15;i<=17;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=45;i<=51;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=75;i<=85 ;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=105;i<=119;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=135;i<=153;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=165;i<=187;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=195;i<=221;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=225;i<=255;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     strip1.show();                
  }

 void Fourth_part(){   
     for(int i=256;i<=286;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=290;i<=316;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=324;i<=346 ;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=358;i<=376;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=392;i<=406;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=426;i<=436;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=460;i<=466;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=494;i<=496;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }  
     strip1.show();              
  }

void forword()
{
  for(int i=128;i<=383;i++){
      strip1.setPixelColor(i, COLOR);     
     } 
  strip1.show();
  }
void First_down(){   
      for(int i=8;i<=23;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=40;i<=55;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=72;i<=87;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=104;i<=119;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=136;i<=151;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=168;i<=183;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=200;i<=215;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=232;i<=247;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     strip1.show();              
  }
void First_up(){   
      for(int i=0;i<=7;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=24;i<=39;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=56;i<=71;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=88;i<=103;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=120;i<=135;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=152;i<=167;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=184;i<=199;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=216;i<=231;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=248;i<=255;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     strip1.show();              
  }
void Second_down(){   
      for(int i=264;i<=279;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=296;i<=311;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=328;i<=343;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=360;i<=375;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=392;i<=407;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=424;i<=439;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=456;i<=471;i++){
      strip1.setPixelColor(i, COLOR);
      strip1.show();
     } 
    for(int i=488;i<=503;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     strip1.show();              
  }
void Second_up(){   
     for(int i=256;i<=263;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=280;i<=295;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     for(int i=312;i<=327;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=344;i<=359;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=376;i<=391;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=408;i<=423;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
      for(int i=440;i<=455;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     } 
    for(int i=472;i<=487;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
    for(int i=504;i<=511;i++){
      strip1.setPixelColor(i, COLOR);
//      strip1.show();
     }
     strip1.show();
  }

Credits

andyz1207

andyz1207

0 projects • 3 followers

Comments