Hello everyone, i'm trying to create a wireless blind spot detection system using :
- Arduino Uno x 2
- Ultrasonic sensor
- 315Mhz rf module (transmitter and receiver)
- Button
- 1 LED
- Buzzer
the idea is :
- ultrasonic sensor detects object and rf transmitter sends signal to the receiver
- the receiver receives the signal and turns on the led light.
- if a button is pressed (indicating a turn signal if the driver failed to notice the led light), a buzzer will give out sound.
the problem :
both the buzzer and led is giving outputs when the sensor detects an object. the button doesnt seem to have any effect at all.
components placement :
1)first arduino
ultrasonic sensor
vcc to 5v
trig to pin 9
echo to pin 8
gnd to gnd
315 rf transmitter
vcc to 5v
gnd to gnd
data to pin 12
- second arduino
receiver
vcc to 5v
gnd to gnd
data to pin 12
led
pin 6
gnd
button
pin 2
gnd
buzzer
pin 3
gnd
these are my
( first arduino code)
#include <VirtualWire.h>
#include <Ultrasonic.h>
Ultrasonic ultrasonic(9,8); // (Trig PIN,Echo PIN)
int d;// Initialize the variable distance
char*controller;
void setup() {
pinMode(6,OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
}
void loop(){
char b[3]; //declaring character array
String str; //declaring string
d=ultrasonic.Ranging(CM);//cm o inc
if(d<10){
controller="1" ;
}
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(6,1);
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(6,0);
}
second arduino code
#include <VirtualWire.h>
int button = 2; //Pin for button
int buzzer = 3; // Pin for buzzer
int led = 6; // Pin for LED
void setup()
{
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(6, OUTPUT);// led
pinMode(2, INPUT); //button is declared as input
pinMode(3, OUTPUT); //buzzer is declared as output
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if(buf[0]=='1')
{if (digitalRead(2)=='1');
{
digitalWrite(6,HIGH);
digitalWrite(3, HIGH);}
if(buf[0]=='1')
{if (digitalRead(2)=='0');
{
digitalWrite(6,HIGH);
digitalWrite(3, LOW);}
} else(buf[0]=='0');
{ digitalWrite(6,LOW);
digitalWrite(3, LOW); }}
}}
i would really appreciate any help and i hope you would have a nice day ![]()