Design and program a smart device that perform a certain function or solve a problem: program Arduino UNO to read signals from multiple input components (Sensor, Switch, or variable resistor) to control multiple action components (Motor, Buzzer, LED...etc) using Arduino C (Text Code).
Description:
Find any exciting idea to do for the assignment: you may find cool ideas on Instructables and Arduino Project Hub or try to implement your final project idea 😉
Google your idea and see how other people have wrote their code, and provide links to other codes that you've tweaked or reused in your assignment
Use Arduino C Text PRIMARILY to write your code in Arduino IDE
Technical Requirements:
The smart device utilizes the Arduino UNO board to control the inputs and outputs
The smart device includes two input components (at least) and two action components (at least) (DON'T repeat any of the input and output combinations that were provided in the tutorials and exercises, you are encouraged to try new ones, you may also use new input and output components from your electronics kit)
The smart device is programmed using Arduino C (Text Code) (Provide a screenshot of your Arduino C code, *.ino code file, and wiring diagram)
The smart device is wired and tested with an actual Arduino board and electronic components on a breadboard (Provide a video recording of the final outcome)
The smart device has an enclosure from cardboard and the non-electric parts are prototyped from cardboard or any scrap material (You are not required to use any CAD or digital fabrication)
The smart device is functional and does its intended objective.
Inspired gradient of colors during sunset https://logosbynick.com/beach-sunset-color-palettes/
Inspiration
I am inspired by the colors of the sunset throughout the day as the sun angles change and the shadows vary. This would difinetly contribute to the psychological factors in which you would feel pleased by the gradients of the following colors such as Red, Yellow, Green, Orange, Blue, and Violette. These colors will be my output colors using RGB LED to emitate the real sunset colors. Currently, I will connect LDR Sesnsor (Input Component) to control the RGB LED( output component), in order to produce green, yellow, orange, red, Blue, and Violette colors in response to the intensity of the sunlight during daytime. While the microwave sensor input (input component) will be used in order to feel any motion inside the room, and the DC Motor (output component) will rotate to open the curtains.
Final Output of a LDR sensor input controls RGB LED light output and the Microwave sensor input component controls the DC Motor motor output via Arduino Uno.
I used Tinker Cad to simulate the circuit design of the Microwave sensor, RGB LED, and DC motor
Arduino UNO
microwave sensor to feel the motion inside the room and it will be responsible for the action output of the dc motor
DC Motor will be used to cause the curtains movement
The RGB LED used as an output component to change its color based on the intensity of light/sunlight
Jumpers are the wires type used for connections
220 ohm resistors are used to protect the LED from excessive voltage.
LDR Sensor to feel the intensity of light/ sunlight or changes in color and change the color of the RGB LED
Tinker Cad simulation of RGB LED, PIR Sensor (instead of Microwave) and DCMotor with L2930 Driver and Photoresistor (instead of LDR sensor)
The wiring of the output and input components
The Tinker Cad Simulation
First:
The connection of the DC motor (output 1) is in response to the microwave sensor input (PIR sensor in simulation) and the RGB LED is in response to the LDR sensor input (photoresistor in simulation). Here are the steps for wiring:
Power supply from the laptop connected to the Arduino
A 9-volt adapter is powering the DC motor, and the Arduino is responsible for the signal only through a driver L2930.
The Microwave Sensor ( GND: OUT: VIN) is connected to
( GND : PIN ~6 :+VE 5v ) respectively.
The RGB LED has red, green, and blue pins, which are connected to the Arduino through (pin~9, pin 10, and pin 11) respectively. while the GND pin is connected to the -ve common ground in the Arduino. Three 220 ohm resistors are connected to the Red, Green, and Blue pins to protect the RGB LED from burning up as it consumes only 2 volts while the circuit has 5 volts, so the Ohm can withstand the rest of the volts in the circuit.
The LDR sensor pins (D0, GND, and VCC) are connected to (Arduino analogue pin A0 (i,e: since we will control analogue values in the code to control the RGB led),, -ve common ground, and +ve in the breadboard conducted from the Arduino respectively.
Text Code idea:
When a moving physical object (motion) passes beside the microwave sensor, it will move the DC motor in speed 90 and in both the clockwise and anticlockwise directions. While the LDR sensor will respond to the changes of the intensity of light which represents the sunlight different shades and angles , and cause the action on RGB to change its color into green, blue, red, yellow, orange, and viollete.
Second : Arduino IDE
#define ldr A0 //input LDR Sensor
#define Rpin 9 // Red Pin in RGB LED
#define Gpin 10 // Green Pin in RGB LED
#define Bpin 11 // Blue Pin in RGB LED
int Rvalue;
int Gvalue;
int Bvalue;
void setup() {
Serial.begin(9600);
pinMode(6, INPUT); //MICROWAVE INPUT
pinMode(5, OUTPUT); // Control Motor Speed
pinMode(4, OUTPUT); // Control Motor Direction
pinMode(2, OUTPUT); // Control Motor Direction
}
void loop() {
int x = analogRead(ldr);
x = map(x, 0, 1023, 0, 100);
if (x <= 17) //if the light is less than 17%, turn purple
{ Serial.println("ARDUINO LDR SENSOR RGB ");
analogWrite(Rpin, 100);
analogWrite(Bpin, 50);
analogWrite(Gpin, 0);
Serial.print("COLOR PURPLE "); Serial.println(x);
delay(150);
}
if (x > 17 && x <= 34) // if the light is between 17-34%, the blue color will shine
{ Serial.println("ARDUINO LDR SENSOR RGB ");
analogWrite(Bpin, 50);
analogWrite(Rpin, 0);
analogWrite(Gpin, 0);
Serial.print("COLOR BLUE"); Serial.println(x);
delay(50);
}
if (x > 34 && x <= 50) //Green pin between 34-50%
{ Serial.println("ARDUINO LDR SENSOR RGB ");
analogWrite(Gpin, 50);
analogWrite(Rpin, 0);
analogWrite(Bpin, 0);
Serial.print("COLOR GREEN"); Serial.println(x);
delay(150);
}
if (x > 50 && x <= 67) //light up yellow
{ Serial.println("ARDUINO LDR SENSOR RGBB ");
analogWrite(Rpin, 150);
analogWrite(Gpin, 70);
analogWrite(Bpin, 0);
Serial.print("COLOR YELLOW"); Serial.println(x);
delay(150);
}
if (x > 67 && x <= 84) //glow orange
{ Serial.println("ARDUINO LDR SENSOR RGB ");
analogWrite(Rpin, 120);
analogWrite(Gpin, 30);
analogWrite(Bpin, 0);
Serial.print("COLOR ORANGE"); Serial.println(x);
delay(150);
}
if (x > 84) //glow red
{ Serial.println("ARDUINO LDR SENSOR RGB ");
analogWrite(Rpin, 150);
analogWrite(Gpin, 0);
analogWrite(Bpin, 0);
Serial.println("COLOR RED"); Serial.println(x);
delay(1500);
}
if (digitalRead(6) == HIGH)
{ Serial.println("MICROWAVE SENSOR ");
analogWrite(5,90 );
digitalWrite(2, HIGH);
digitalWrite(4, LOW);
Serial.println("ROTATE CLOCKWISE");
delay(1000); //Wait for 1000 milliseconds
analogWrite(5, 90);
digitalWrite(2, LOW);
digitalWrite(4, HIGH);
Serial.println("ROTATE ANTICLOCKWISE");
delay(1000); //Wait for 1000 milliseconds
} else {
analogWrite(5, 0);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
Serial.println("NO MOVEMENT");
delay(1000); //Wait for 1000 milliseconds
}
// IN CASE I AM USING SERVO HERE IS THE FOLLOWING CODE FOR IT
// if (digitalRead(6) == HIGH) {
// // for example digitalWrite(9, HIGH); you will include here the RGB Led action
// digitalWrite(5,HIGH);
// delay(1000); // Wait for 100 millisecond(s)
// } else {
// digitalWrite(5,LOW);
// // for example digitalWrite(9, LOW); you will include here the RGB Led action
}
Description in text for each coding part :
defining the LDR sensor (ldr) that it is connected to A0 as an analogue input.
defining the red pin (Rpin) in the RGB LED that it is connected to pin 9.
defining the green pin (Gpin) in the RGB LED that it is connected to pin 9.
defining the blue pin (Bpin) in the RGB LED that it is connected to pin 9.
The three values of the red, green, and blue will use integers (int) with no decimals.
in void setup
the serial begin is used for serial monitor to check any bugs and errors in readings.
the Microwave is defined as 6 (since this is the number of its pin in arduino) and it is input components, it means that it will be used in digital read to digital write on the output pins of the DC motor.
The digital pins of the DC motor, (which is connected to a driver and the output pins will be connected from driver to arduino), will be 5, 4, and 2. Pin 5 is controling the motor speed so it will take analogue value. Pin 4 is controling the motor direction so it will take digital value, Pin 2 is controling the motor direction so it will take a digital value. (Both pins 4 and 2 will be used in case i would like to have clockwise and anticlock wise directions).
in Void loop (Commands that will be repeated)
x is an integer value to store the readings of the ldr sensor (analog read) and it is analogue because we will recieve different number of light intensity values to lighten the RGB LED (Not Digital which means HIGH OR LOW , YES LIGHT IT OR NO DO NOT LIGHT IT).
the mapping here will scale the readings of the values produced from the ldr sensor from (0-1023) which is the default range of readings to ( 0-100).
The formula is as follows:
1) If the LDR readings (light intensity) are less than or equal to 17 then turn the purple color of the RGB LED so analog write on the red and green pins with values (100 and 50 respectively).
serial print that LDR had received the light intensity values correctly.
serial print that the RGB led has produced the right values on each pin as the equation.
2) If the LDR readings (light intensity) are more than 17 and less than or equal to 34 then turn the blue color of the RGB LED so analog write on the blue pin with values ( 50 ).
serial print that LDR had received the light intensity values correctly.
serial print that the RGB led has produced the right values on each pin as the equation.
3) If the LDR readings (light intensity) are more than 34 and less than or equal to 50 then turn the green color of the RGB LED so analog write on the green pin with values ( 50 ).
serial print that LDR had received the light intensity values correctly.
serial print that the RGB led has produced the right values on each pin as the equation.
3) If the LDR readings (light intensity) are more than 50 and less than or equal to 67, then turn the yellow color of the RGB LED so analog values are written on the Red and Green pin with values ( 150 and 70 respictevly ).
serial print that LDR had received the light intensity values correctly.
serial print that the RGB led has produced the right values on each pin as the equation.
4) If the LDR readings (light intensity) are more than 67 and less than or equal to 84 then turn the orange color of the RGB LED so analog write on the Red and Green pin with values ( 120 and 30 respectively).
serial print that LDR had received the light intensity values correctly.
serial print that the RGB led has produced the right values on each pin as the equation.
4) If the LDR readings (light intensity) are more than 84 then turn the red color of the RGB LED so analog write on the red pin with value ( 150 ).
serial print that LDR had received the light intensity values correctly.
serial print that the RGB led has produced the right values on each pin as the equation.
4) To read the microwave sensor readings on pin 6, i wrote digital read pin 6 and if it reads a movement (High) please move the dc on pin 5 to a speed of 90 in a clockwise direction (so activate pin 2 and deactivate pin 4.
And then wait for 1000 seconds, and rotate anticlockwise direction by activating pin 4 and deactivating pin 2 (But it didn't work well in real ).
5) if the latter didn't happen, make the DC Motor stop on pin 5 and make the speed zero and no direction recieved make it low on both pins which means it will stop .
Implementation
The process :
Whe a moving physical object (motion) passes beside the microwave sensor, it will move the DC motor in speed 90 and in both the clockwise and anticlockwise directions. While the LDR sensor will respond to the changes of the intensity of light which represents the sunlight different shades and angles , and cause the action on RGB to change its color into green, blue, red, yellow, orange, and viollete.
1st ) The RGB LED in response to the changes of the intensity of the light/sunlight through ldr sensor
2nd) The DC Motor clockwise movement in response to the movement detected by the microwave sensor
1) The circuit did not work at first and i kept checking the serial monitor to detect if there any errors with readings or output actions and the readings of the rotation was read well but it was not happening in real. Then i realised that i was powering wrong i didnot respect the common ground rule for all the components to be the same as arduino while the positive will only be seprated from arduino to empower the dc motor. But unortunately, it didn't work well, so i kept changing pins, and used the avometer to check each jumper on seperate circuit then i realised the faulty jumber. Then it works well,
Both serial monitors are showing that both sensors are working well, and the colors are indicated well beside the DC rotation which means that the coding and the input components are working well but there is a fault in either the output components or the wiring or the jumpers.
1) I have learnt how to use the arduino in managing several outputs and inputs.
2) I will use this connection in my final project as i will use the blooming effect in moving the parts of the lighting element in response to the user motion in the room.
3) I learned how to overcome challenges through trials and errors and resolve the issue by using serial monitors and the avometers along with resolving some bugs related to a missing syntax in the code with some faith that I can do it.
Our robotic arm was the master piece of this week. we tried to make it fish and write and it worked well. I liked the part of how we inserted each servo in its place in the 3d printed object in respect to the dimensions of each servo and how by simple coding the directions of the servo could be controllable through a wireless android application on mobiles through a HC Module 05.