diff --git a/Arduino/DistanceCalculator/DistanceCalculator.ino b/Arduino/DistanceCalculator/DistanceCalculator.ino new file mode 100644 index 0000000..8a6d57e --- /dev/null +++ b/Arduino/DistanceCalculator/DistanceCalculator.ino @@ -0,0 +1,27 @@ +const int trigPin = 9; +const int echoPin = 8; +// defines variables +long duration; +int distance; +void setup() { +pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output +pinMode(echoPin, INPUT); // Sets the echoPin as an Input +Serial.begin(9600); // Starts the serial communication +} +void loop() { +// Clears the trigPin +digitalWrite(trigPin, LOW); +delayMicroseconds(2); +// Sets the trigPin on HIGH state for 10 micro seconds +digitalWrite(trigPin, HIGH); +delayMicroseconds(10); +digitalWrite(trigPin, LOW); +// Reads the echoPin, returns the sound wave travel time in microseconds +duration = pulseIn(echoPin, HIGH); +// Calculating the distance +distance= duration*0.034/2; +// Prints the distance on the Serial Monitor +Serial.print("Distance: "); +Serial.println(distance); +delay(200); +} \ No newline at end of file diff --git a/Arduino/OhmMeter.ino b/Arduino/OhmMeter.ino new file mode 100644 index 0000000..c0c7519 --- /dev/null +++ b/Arduino/OhmMeter.ino @@ -0,0 +1,17 @@ +int v=5; +float r1=10000; +float r2=0.0f; +float input=0.0f; + +void setup() { + Serial.begin(9600); + pinMode(A0,INPUT); +} + +void loop() { + int sensorValue = analogRead(A0); + float voltage = sensorValue * (v / 1023.0); + r2=r1*(voltage/(v-voltage)); + Serial.println(r2); + delay(100); +} \ No newline at end of file diff --git a/Arduino/Smart street light.ino b/Arduino/Smart street light.ino new file mode 100644 index 0000000..0a19372 --- /dev/null +++ b/Arduino/Smart street light.ino @@ -0,0 +1,101 @@ +int ir1=2; +int ir2=3; +int ir3=4; +int ir4=5; + +int led1=6; +int led2=7; +int led3=8; +int led4=9; +int led5=10; +int led6=11; + +int proxy1=0; +int proxy2=0; +int proxy3=0; +int proxy4=0; +void setup() +{ + pinMode(ir1,INPUT); + pinMode(ir2,INPUT); + pinMode(ir3,INPUT); + pinMode(ir4,INPUT); + + pinMode(led1,OUTPUT); + pinMode(led2,OUTPUT); + pinMode(led3,OUTPUT); + pinMode(led4,OUTPUT); + pinMode(led5,OUTPUT); + pinMode(led6,OUTPUT); +} + + +void loop(){ + proxy1=digitalRead(ir1); + proxy2=digitalRead(ir2); + proxy3=digitalRead(ir3); + proxy4=digitalRead(ir4); + +if(proxy1==HIGH) +{ + digitalWrite(led1,HIGH); + digitalWrite(led2,HIGH); + delay(20); +} +else +{ + digitalWrite(led1,LOW); + digitalWrite(led2,LOW); +} + +if(proxy2==HIGH) +{ + digitalWrite(led2,HIGH); + digitalWrite(led3,HIGH); + delay(20); +} +else +{ + digitalWrite(led2,LOW); + digitalWrite(led3,LOW); + +} + +if(proxy3==HIGH) +{ + digitalWrite(led3,HIGH); + digitalWrite(led4,HIGH); + delay(20); +} +else +{ + digitalWrite(led3,LOW); + digitalWrite(led4,LOW); + digitalWrite(led5,LOW); +} + +if(proxy4==HIGH) +{ + digitalWrite(led4,HIGH); + digitalWrite(led5,HIGH); + digitalWrite(led6,HIGH); + delay(20); +} +else +{ + digitalWrite(led4,LOW); + digitalWrite(led5,LOW); + digitalWrite(led6,LOW); +} + } + + + else{ + digitalWrite(led1,LOW); + digitalWrite(led2,LOW); + digitalWrite(led3,LOW); + digitalWrite(led4,LOW); + digitalWrite(led5,LOW); + digitalWrite(led6,LOW); +} +} \ No newline at end of file diff --git a/Arduino/Smart_dustbin_arduino.ino b/Arduino/Smart_dustbin_arduino.ino new file mode 100644 index 0000000..7f03a1a --- /dev/null +++ b/Arduino/Smart_dustbin_arduino.ino @@ -0,0 +1,51 @@ +#include //servo library +Servo servo; +int trigPin = 5; +int echoPin = 6; +int servoPin = 7; +int led= 10; +long duration, dist, average; +long aver[3]; //array for average + + +void setup() { + Serial.begin(9600); + servo.attach(servoPin); + pinMode(trigPin, OUTPUT); + pinMode(echoPin, INPUT); + servo.write(0); //close cap on power on + delay(100); + servo.detach(); +} + +void measure() { + digitalWrite(10,HIGH); +digitalWrite(trigPin, LOW); +delayMicroseconds(5); +digitalWrite(trigPin, HIGH); +delayMicroseconds(15); +digitalWrite(trigPin, LOW); +pinMode(echoPin, INPUT); +duration = pulseIn(echoPin, HIGH); +dist = (duration/2) / 29.1; //obtain distance +} +void loop() { + for (int i=0;i<=2;i++) { //average distance + measure(); + aver[i]=dist; + delay(10); //delay between measurements + } + dist=(aver[0]+aver[1]+aver[2])/3; + +if ( dist<50 ) { +//Change distance as per your need + servo.attach(servoPin); + delay(1); + servo.write(0); + delay(3000); + servo.write(150); + delay(1000); + servo.detach(); +} +Serial.print(dist); +} \ No newline at end of file diff --git a/Arduino/two_wheel_motor_robot.ino b/Arduino/two_wheel_motor_robot.ino new file mode 100644 index 0000000..b9ab1b3 --- /dev/null +++ b/Arduino/two_wheel_motor_robot.ino @@ -0,0 +1,165 @@ +// This Robot/car generally has two wheels with motors at the back and 1 castor wheel in front working with L298n motor driver +// This robot code is basic for non-encoder motors(means we are not counting steps) , just moving the car using delay +//*****************************************************// +// IMPORTANT POINTS: + // mot1 , mot1b are direction pins means if LOW and HIGH move motor left forward then HIGH and LOW move backward. PS--According to circuit connections + // mot2 , mot2b are direction pins means if LOW and HIGH move motor right forward then HIGH and LOW move backward. PS--According to circuit connections + //mot1_pwm is speed of left motor + // mot2_pwm is speed of right motor + // You also need to check when the right turn aur circle path is completing, means in how many seconds. and set that time as delay. + //It depends on motor rpm, battery voltage etc. +//******************************************************// + + +// put below pin numbers according to your cicuit +int mot1_pwm=5; // left motor speedpwm pin number +int mot1=4; //left motor direction 1 +int mot1b=3; //left motor direction 2 + +int mot2_pwm=6; // right motor speedpwm pin number +int mot2=7; //right motor direction 1 +int mot2b=8; //right motor direction 2 + + +void setup() { + // putting all pins mode as output + pinMode(mot1,OUTPUT); + pinMode(mot1b,OUTPUT); + pinMode(mot1_pwm,OUTPUT); + + pinMode(mot2_pwm,OUTPUT); + pinMode(mot2,OUTPUT); + pinMode(mot2b,OUTPUT); + + +// initialize motors pwm as zero to stop in initial + digitalWrite(mot1,LOW); + digitalWrite(mot1b,LOW); + analogWrite(mot1_pwm,0); + + digitalWrite(mot2,LOW); + digitalWrite(mot2b,LOW); + analogWrite(mot2_pwm,0); + + +} + +void loop() { + // put your main code here, to run repeatedly: + + // there are many other ways also to make your bot turn left or right. Below is one of the way. + + // calling the above functions to move the bot + + move_forward(); + delay(6000); // move forward for 6 seconds + + move_backward(); + delay(6000); // move backward for 6 seconds + + stop_car(); + delay(2000); // stop the bot for 2 seconds + + left_turn(); //bot will rotate on left side on its position + delay(2000); // this will starts rotating it for 2 seconds + right_turn(); //bot will rotate on right side on its position + delay(2000); + + circle_clockwise(); + delay(9000); // moving clockwise in circular path for 9 seconds + circle_anticlockwise(); + delay(9000); // moving anticlockwise in circular path for 9 seconds + + stop_car(); + delay(2000); // stop the bot for 2 seconds + + + // similarly we can write any path using above functions + +} + +// Functions for the movement of car/robot + +int stop_car() +{ + digitalWrite(mot1,LOW); + digitalWrite(mot1b,HIGH); + analogWrite(mot1_pwm,0); + + digitalWrite(mot2,LOW); + digitalWrite(mot2b,HIGH); + analogWrite(mot2_pwm,0); + + } +int move_forward() +{ + digitalWrite(mot1,LOW); + digitalWrite(mot1b,HIGH); + analogWrite(mot1_pwm,250); + + digitalWrite(mot2,LOW); + digitalWrite(mot2b,HIGH); + analogWrite(mot2_pwm,250); + + } +int move_backward() +{ + digitalWrite(mot1,HIGH); + digitalWrite(mot1b,LOW); + analogWrite(mot1_pwm,250); + + digitalWrite(mot2,HIGH); + digitalWrite(mot2b,LOW); + analogWrite(mot2_pwm,250); + + } + int circle_clockwise() + { + + digitalWrite(mot1,LOW); + digitalWrite(mot1b,HIGH); + analogWrite(mot1_pwm,250); + + digitalWrite(mot2,LOW); + digitalWrite(mot2b,HIGH); + analogWrite(mot2_pwm,100); + + } + + int circle_anticlockwise() + { + + digitalWrite(mot1,LOW); + digitalWrite(mot1b,HIGH); + analogWrite(mot1_pwm,100); + + digitalWrite(mot2,LOW); + digitalWrite(mot2b,HIGH); + analogWrite(mot2_pwm,250); + + } + +int left_turn() + { + + digitalWrite(mot1,LOW); + digitalWrite(mot1b,HIGH); + analogWrite(mot1_pwm,0); + + digitalWrite(mot2,LOW); + digitalWrite(mot2b,HIGH); + analogWrite(mot2_pwm,250); + + } +int right_turn() + { + + digitalWrite(mot1,LOW); + digitalWrite(mot1b,HIGH); + analogWrite(mot1_pwm,250); + + digitalWrite(mot2,LOW); + digitalWrite(mot2b,HIGH); + analogWrite(mot2_pwm,0); + + }