Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Prateek Choudhary
Published © GPL3+

Helmet for a life (using arduino and bolt)

We all have seen someone losing life in a road accident, So "helmet for a life" is trying to stop people riding two wheeler without helmet.

IntermediateFull instructions provided4 hours4,185
Helmet for a life (using arduino and bolt)

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Arduino UNO
Arduino UNO
×2
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Transmitter + Receiver
×1
5V Relay One Channel Module
×1
9V battery (generic)
9V battery (generic)
×2

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Arduino Web Editor
Arduino Web Editor
You can use Arduino IDLE it's one and the same.

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Only used for opening the part of activa where the battery was placed.

Story

Read more

Schematics

Placed on helmet

Placed with vehicle battery

Helmet for life

Code

Python Code

Python
import json, time, requests
from boltiot import Sms, Bolt

api_key = "Your api key"                                #Add your API key 
device_id  = "Your device ID"                           #Add your device ID
mybolt = Bolt(api_key, device_id)                       #Module ready

SID = 'Your SID'                                      #From your twilio dashboard
AUTH_TOKEN = 'Your authentication token'              #From your twilio dashboard
FROM_NUMBER = 'Phone number'                          #Twilio number
TO_NUMBER = 'Phone number'                            #To the number you want to send SMS

mybolt = Bolt(api_key, device_id)
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)
response = mybolt.serialRead('10')                  #Take response from arduino

while True:
  print ("\nReading")                               #reading value form arduino
  response = mybolt.serialRead('10')
  data = json.loads(response)
  val=data['value'].rstrip()                        #readings from arduino converted to string type
  time.sleep(5)
  
  #If arduino gives value 0 that is it sensor is in connected with object that means, person is wearing helmet we need to perform our task
  if val=="0":
    print("Wearing helmet\n")
  
    try:
      print("Making request to Twilio to send a SMS")
      response = sms.send_sms("It seems like you started your vehicle, do wear a helmet and mask. Have a safe ride!")
      print("Response received from Twilio is: " + str(response))
      time.sleep(600)
      print("Status of SMS at Twilio is :" + str(response.status) + "\n")
    except Exception as e:
      print ("Error occured: Below are the details")
      print (e)
      print("\n")
      time.sleep(5)
  else:
    None

Code for the circuit present on helmet

C/C++
#include <VirtualWire.h>        //Including library

//Initialise pins
int led_pin = 6;
int transmit_pin = 12;
int ir_sensor = 2;
int val = 0;

void setup()
{
  Serial.begin(9600);
  vw_set_tx_pin(transmit_pin);
  vw_setup(4000);                 // Transmission rate
  pinMode(led_pin, OUTPUT);       // Led is an output device
  pinMode(ir_sensor, INPUT);       // Led is an input device
}

void loop()
{
  char msg[1] = {'0'};
  val = digitalRead(ir_sensor);               // Get sensor value
  Serial.println(val);                        // Print value  
  
  //Check if motion is detected
  if (val == 1)
  {
    msg[0] = '1';
    digitalWrite(led_pin, 1);       //Led flashing to show transmitting
    vw_send((uint8_t *)msg, 1);     //send message
    vw_wait_tx();                   // Wait until the whole message is gone
    delay(500);
  }
  else
  {
    msg[0] = '0';
    digitalWrite(led_pin, 0);       //led off when not detecting
    vw_send((uint8_t *)msg, 1);     //send message
    vw_wait_tx();                   // Wait until the whole message is gone
    delay(500);
  }
}

Code for the circuit attached with vehicle battery

C/C++
#include <VirtualWire.h>            //Including library

//Initialise pins
int relay=7;      
int receive_pin=4;

void setup()
{
   Serial.begin(9600); 
   vw_set_rx_pin(receive_pin);
   vw_setup(4000);                              // Transmission rate same as in transmitter
   vw_rx_start();                               // Start the receiver
   pinMode(relay, OUTPUT);
}

void loop()
{
   uint8_t buf[VW_MAX_MESSAGE_LEN];
   uint8_t buflen = VW_MAX_MESSAGE_LEN;
 
   // Checking if a message was received or not
    if (vw_get_message(buf, &buflen)) 
    {
      if(buf[0]=='1')
      {
      digitalWrite(relay,HIGH);                 //Connect relay and complete circuit
      delay(500);
      }
     else
     {
     digitalWrite(relay,LOW);                     //Disconnect the circuit
     delay(500); 
     }
   }
}

Helmet for life

Credits

Prateek Choudhary

Prateek Choudhary

3 projects • 2 followers
To know more about me catch me on Linkedin: https://www.linkedin.com/in/itsprateekchoudhary/ Just email: contactprateekchoudhary@gmail.com

Comments