For this week's assignment, the idea is to Build and Program a smart device using an Arduino UNO to read signals from multiple input components to control multiple action components using text coding. I decided to focus on something that could be implemented in my final project, the Montessori busy board for kids. Mainly, i decided to make a fan that could rotate with different speeds using potentiometer, and LCD screen to write the speed .
Also, i wanted to use analog LDR Sensor to detect different colors(reflection) and make action according to the reflected light it sense.
We used Tinker CAD which is a free web app for electronics, coding and 3D design. On Tinker CAD we can create simulations of circuits in which we there is a dashboard that contains all the components needed to create any circuit, we can just drag and drop the component that we want to use, so we can design and test our ideas virtually, which helps us to experiment the circuit before physically doing it. https://www.tinkercad.com/
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino hardware to upload programs and communicate with them
Arduino UNO is a low-cost, flexible, and easy-to-use programmable open-source microcontroller board that can be integrated into a variety of electronic projects. It consists of various pins, which makes it more compatible and can be used to connect different electronic components.
A breadboard is a plastic board with tiny holes. These holes make it easily to insert electronic components to prototype, create electric circuits.
The USB port serves two purposes: First, it is the cable connection to a computer which allows you to program the board. The USB cord will also provide power for the Arduino if you're not using the power port
H-bridge motor driver allows you to control the speed and direction of two DC motors.
This yellow DC motor is ideal for robotics and model vehicles. It has a 1:48 gear ratio and maximum torque of 800g/cm at a minimum of 3V.
A potentiometer is fundamentally a variable resistor. Potentiometers function as voltage dividers that can be used to both adjust voltage output to a circuit
Servo motors are great devices that can turn to a specified position. Usually, they have a servo arm that can turn 180 degrees.
Push button is a simple switch mechanism to control some aspect of a machine or a process.
The LDR sensor Module is used to detect the presence of light and measure the intensity of light. The output of the module goes high in the presence of light and it becomes low in the absence of light.
A resistor is a two-terminal electrical component that provides electrical resistance, used to lower the flow of current, divide voltages
Jumper wires are used to connect components together and it has different types like Male-Male, Male-Female, and Female-Female.
The LCD (Liquid Crystal Display) is a type of display that uses the liquid crystals for its operation.
LED stands for light emitting diode. It converts electrical energy directly into light
Open TinkerCAD and create a circuit.
Drag and drop the needed components.
Assemble the components on the breadboard.
Connect 5V and GND of Arduino to breadboard.
The H-Bridge has 2-grounds connect one of them to the GND in Arduino, and the other one to the -ve terminal of power supply(9-volts Adaptor).
Connect power 1 terminal to the 5V connected to breadboard, Power 2 to the +ve terminal of power supply,
Connect Input 4 to Arduino pin (13), and output 4 to the motor, input 3 to Arduino pin (12), and output 3 to the motor.
Connect terminal 1 of potentiometer to the 5V of Arduino connected to the breadboard the wiper to Arduino analog Input pins(A1), the 3rd terminal to the GND connected to Arduino.
Test the circuit using code block and it works perfectly as shown in the video.
Build the same circuit physically.
Write text code on Arduino IDE to control the speed of rotation of the motor.
Connect Arduino, to the laptop and Upload the code.
The code shown in the picture works and speed of the motor changes using potentiometer.
Now, I decided to add the LCD with I2C module , to write (speed1 or speed 2 or speed3) according to the speed of the motor.
I connected the VCC terminal to the 5v of Arduino in breadboard, the GND terminal to Arduino GND in breadboard, and SCL terminal to pin(A5), and SDA terminal to pin (A4).
Then i edited on the code to add that if potentiometer value > 50 light up the LCD and if potentiometer value between 50 and 700 write speed 1, between 700 and 950 write speed 2, between 950 and 1023 write speed 3, These numbers came by trial and error. (I guess it would be better if controlled by the rpm of motor not potentiometer value)
I decide to use the LDR sensor on Analog mode, so i connected one terminal to the GND of Arduino and terminal to VCC of Arduino, and the A0 terminal to (A0) pin in Arduino. (On Tinker CAD i added PIR sensor instead of LDR, cause its not exist.
I add LED as an output to be controlled according to the reflected light that the LDR Sensor sense.
Connect the anode terminal of the LED to pin (10) in Arduino, and the other terminal connected to a resistor, connected to the GND of Arduino in the breadboard.
I decided to add Servo motor, that will be controlled by a push button.
Connect 3-terminals of servo motor to the GND of Arduino, VCC of Arduino, and Pin(6).
Connect a push button, terminal to the GND, and terminal to Pin (7).
Input(1): Potentiometer, Output(1): Dc Motor with different speed + LCD
Input(2): LDR Module, Output(2): LED
Input(3): Push button, Output(3): Servo Motor
#include <Servo.h>
Servo lock;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int potPin = A1; // Potentiometer connected at A0
int potVal = 0; // variable to store value of potentiomter
int motorspeed = 11;
int lightsensor = A0;
int reflection = 0; // variable to store reflection of light sensor
int LED = 10;
int pushButton = 7;
int buttonvalue = 0;
void setup() {
pinMode(motorspeed, OUTPUT);
pinMode(13, OUTPUT); //motor
pinMode(12, OUTPUT); //motor
pinMode(LED, OUTPUT);
pinMode(pushButton, INPUT_PULLUP); // switch to turn ON and OFF Servo
Serial.begin(9600);
lcd.init();
lcd.noBacklight();
lock.attach(6); //servo connected on pin 6
}
void loop() {
digitalWrite(13, HIGH); // Set motor to rotate in one direction.
digitalWrite(12, LOW);
potVal = analogRead(potPin); //Read potentiometer Value
analogWrite(motorspeed, (map(potVal, 0, 1023, 0, 200)));
Serial.println(potVal);
delay(100);
if (potVal > 50) {
lcd.backlight();
if (potVal > 50 & potVal < 700) {
lcd.setCursor(5, 0);
lcd.print("Speed 1");
}
if (potVal > 700 & potVal < 950) {
lcd.setCursor(5, 0);
lcd.print("Speed 2");
}
if (potVal > 950 & potVal < 1024) {
lcd.setCursor(5, 0);
lcd.print("Speed 3");
}
} else {
lcd.noBacklight();
lcd.clear();
}
reflection = analogRead(lightsensor);
if (reflection < 700) { // less than 600 means dark room
digitalWrite(LED, LOW); // Turn off LED
} else {
digitalWrite(LED, HIGH); // Turn On LED
}
buttonvalue = digitalRead(pushButton);
if (buttonvalue == LOW) { //make the servo rotate while the BUTTON is PUSHED
lock.write(170);
delay(500);
lock.write(10);
delay(500);
} else { //make the servo stop while the switch off
lock.write(10);
}
}
I re-build the circuit exactly the same way on Tinker-CAD, write the code on Arduino IDE App, and upload it on Arduino board
Pseudocode:
1) Set motor direction of rotation to rotate in one direction.
Set motor speed to map ( potentiometer value) as potentiometer varies from 0 to 1023 and speed of motor from 0 to 200 rpm.
If Potentiometer value greater than 50 turn on the LCD, If greater than 50 and less that 700, write speed 1, If greater than 700, and less than 950 write speed2, If greater than 950 and less than 1024 write speed 3, else turn off the LCD.
2) Make a variable(Reflection) to store and read the value of light sensor.
if reflection < 700 (Dark room), then turn on the LED, else turn off the lamp.
I used analog to read and reflected values and expect the needed value according to my project.
3) If push button is pressed, make servo motor rotate to 170 degrees to 10 degrees while the button is pressed, else stop motor at degree 10.
Video present working the 3-inputs, and 3-outputs.
1) Using this huge number of jumpers, was really complicated to enclosure it, also using crocodile wires, if soldering was allowed it would be easier.
2) Fixing the Dc motor on tissue roll as i have no idea how to fix it on the upper face of the box.
3) LCD display is unstable, i don't know if there is something that should be edited on the code, or that happens because of rapid change of potentiometer values.
4) I tried also to write in the second row of the LCD, the state of the LED when turned On or OFF, but it was totally unstable controlling the LCD with 2 different rabidly changed inputs, so i decided to use it only with the potentiometer and motor.
5) I wanted to use the LDR sensor as a color sensor using different condition according to the reflected light, but the instructor told me that there is a color sensor that i can use it instead of that.
It was a great choice that could be implemented in my final project idea, trying 3-different input with 4- different outputs was really hard but amazing, it makes me more confident with trying my final project idea, with larger number of inputs and outputs.