the idea of my project is Arduino Sunflower.
The assignment for This week is building and programing a circuit with an Arduino uno to read signals from multiple input components (ultra sonic sensor and LDR sensor)
to control multiple action components (LED and Servo motor)
i found similar idea on Arduino project hub.
the idea is when the LDR sensor sensing light the servomotor will rotate and the sunflower will rotate with it.
so i used an ultra sonic sensor to control on the LED and emit the light to rotate servo motor *.*
For this assignment i used:
1-Arduino uno
2-Breadbboard
3-Jumpers
4-LED
5-Resistor (220 ohm)
6-Servo motor
7-Ultra sonic sensor
8-LDR sensor
9-Arduino software
10-Tinkercad for wiring
LDR sensor
Arduino software
Servo motor
the idea is when the LDR sensor sensing light the servomotor will rotate and the sunflower will rotate with it.
so i used an ultra sonic sensor to control on the LED and emit the light to rotate servo motor *.*
using tinkercad for wiring
Firstly, connected the LED to the Breadboard ( the negative pin to the resistor(220 ohm) then to the gnd and the positive pin to pin 7.
connecting the ultra sonic sensor to the Breadboard, vcc with 5v, trig pin to pin6, echo pin to pin 5, and the last pin to the gnd.
connecting the other components, LDR sensor (vcc to 5v, and the the last pin to A0)
connecting the servo motor with Arduino (vcc with 5v, gnd with gnd pin and the last pin to pin9)
Firstly, connected the LED to the Breadboard ( the negative pin to the resistor(220 ohm) then to the gnd and the positive pin to pin7.
connecting the ultra sonic sensor to the Breadboard, vcc with 5v, trig pin to pin6, echo pin to pin 5, and the last pin to the gnd.
Then, I try to write the code for this circuit and make sure it works well.
connecting the other components, LDR sensor (vcc to 5v, gnd with the gnd and the the last pin to A0)
connecting the servo motor with Arduino (vcc with 5v, gnd with gnd pin and the last pin to pin9)
Then, writing the code for this circuit and make sure it works succesfully.
#define trigPin 6
#define echoPin 5
#define led 7
#include <Servo.h>
Servo servo1;
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
servo1.attach(9);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 10)
{ digitalWrite(led,HIGH);
}
else {
digitalWrite(led,LOW);
}
Serial.print(distance);
Serial.println(" cm");
delay(500);
int lightValue = analogRead(A0);
lightValue = map(lightValue,0,1023,0,180);
servo1.write (lightValue);
}
Trying to connect the led with the ultra sonic sensor
Final outcome with enclosure
In the offline session we're divided into groups, I worked with Aya to build smart home!!
Manual mode: push button to light the lamp, push button to make the DC (as a fan) motor rotate.
Automatic mode:
Microwave sensor with LDR sensor, if the microwave sensor detect motion the lamp will on butttt!
Before this step we must make sure that there is no lighting we make this step by LDR sensor, so if the microwave sense motion then check the LDR sensor to light the lamp.
DHT 11 sensor (sensing temp and humidity) to rotate the DC motor.
I helped Sara and Randa to know how to connect the LDR and Microwave sensor with Arduino.
Aya showed me how to write a code for the activity. I couldn't deal with it.
int pushMotor = 3;
int microwave = 13;
int ldr = 12;
void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
pinMode(pushMotor, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(ldr, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(9) == HIGH){
if (digitalRead(6) == LOW) {
digitalWrite(10, HIGH);
}
else {
digitalWrite(10, LOW);
}
if (digitalRead(pushMotor) == LOW) {
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
else {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
}
else{
//microwave reading
Serial.println( digitalRead(13));
if (digitalRead(microwave) == HIGH ) {
if (digitalRead(ldr) == HIGH) {
digitalWrite(10, HIGH);
}
delay(1000);
}
else {
digitalWrite(10, LOW);
}
For this assignment i found this idea in Arduino project hub but with (one input and one output) so I edited this circuit by using LED to emit the light.
After connecting i don't know how to write the code for the servo motor, I tried so much but it didn't work :"D
watching videos on YouTube to know how to write the code, and finally it works!
This week i know how to write a code in Arduino so it helps me in my final project.
when the lamp turn on automatically without push button
by LDR sensor :D
Title of Media