Ads and other Queries.
1.Smart Dustbin
Circuit for smart Dustbin
Code
#include <Servo.h>
Servo servo;
int trig = 5;
int echo = 6;
int servoPin = 7;
long duration, distance, average;
long aver[3];
void setup () {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
servo.write(0);
delay(100);
servo.detach();
}
void measure () {
digitalWrite (trig,LOW);
delayMicroseconds(5);
digitalWrite (trig, HIGH);
delayMicroseconds (15);
digitalWrite (trig, LOW);
pinMode (echo, INPUT);
duration = pulseIn(echo, HIGH);
distance = (duration/2)/29.1;
}
void loop () {
Serial.println(distance);
for(int i= 0 ; i<=2 ; i++) {
measure ();
aver[i] = distance;
delayMicroseconds (10);
}
distance = (aver[0] + aver[1] + aver[2])/3;
if (distance <=20){
servo.attach(servoPin);
delayMicroseconds (1);
servo.write(0);
delayMicroseconds (3500);
servo.write(180);
delayMicroseconds (1500);
delayMicroseconds (1500);
} //Failure is a hit
} //and trial method of sucess
//This code is designed by Sumit Kumar
2.Remote Control Lights
Circuit for Remote control Lights
Code
char BluetoothData;
void setup () {
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
}
void loop () {
if (Serial.available()){
BluetoothData = Serial.read();
if (BluetoothData =='X'){
digitalWrite(5, 1);
}
if (BluetoothData =='Y'){
digitalWrite(6, 1);
}
if (BluetoothData =='Z'){
digitalWrite(7, 1);
}
if (BluetoothData =='x' || BluetoothData =='y' || BluetoothData =='z'){
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
}
}
delay (10);
} //For writing a whole code just try to make few changes in other's code
//Designed by Sumit Kumar
3.Joystick
Circuit for joystick
Code
#include <Servo.h>
Servo servo1;
Servo servo2;
int x_key = A1;
int y_key = A0;
int x_pos;
int y_pos;
int servo1_pin = 8;
int servo2_pin = 9;
int initial_position = 90;
int initial_position1 = 90;
int speed = 2;
void setup ( ) {
Serial.begin (9600) ;
servo1.attach (servo1_pin ) ;
servo2.attach (servo2_pin ) ;
servo1.write (initial_position);
servo2.write (initial_position1);
pinMode (x_key, INPUT) ;
pinMode (y_key, INPUT) ;
}
void loop ( ) {
x_pos = analogRead (x_key) ;
y_pos = analogRead (y_key) ;
if (x_pos < 300){
if (initial_position < 10) { }
else{ initial_position = initial_position - speed;
servo1.write ( initial_position ) ;
delay (100) ;
}
}
if (x_pos > 700){
if (initial_position > 180) { }
else{ initial_position = initial_position + speed;
servo1.write ( initial_position ) ;
delay (100) ;
}
}
if (y_pos < 300){
if (initial_position1 < 10) { }
else{ initial_position1 = initial_position1 - speed;
servo2.write ( initial_position1 ) ;
delay (100) ;
}
}
if (y_pos > 700){
if (initial_position1 > 180) { }
else{ initial_position1 = initial_position1 + speed;
servo2.write ( initial_position1 ) ;
delay (100) ;
}
}
}
//This code is written by Sumit Kumar
//Think, Try and Become Trand