Lebah menghasilkan lilin dan madu yg sangat manfaat bagi kita. Lebah sangat disiplin, mengenal pembagian kerja, segala yang tidak berguna disingkirkan dari sarangnya.
Dalam satu hadis Rasul s.a.w. digambarkan dunia ini umpama kita mencelupkan jari ke dalam lautan yang luas, kemudian kita angkat jari, dan titisan yang masih tinggal di jari, cuma itu sahajalah nikmat dunia.
“Ya Tuhan kami, tidaklah Engkau menciptakan segala sesuatu di muka bumi dalam keadaan sia-sia, Maha Suci Engkau, maka selamatkanlah kami dari siksa neraka.” (Quran, Ali-Imran, 3:191)
Assalamualaikum wbt kepada pembaca blog saya yang saya hormati...
Setelah disibukkan dengan hal lain, Alhamdulillah hari ini saya diberi kesempatan untuk berkongsi projek arduino yang saya cuba hari ini. Pada entri
kali ini, saya ingin berkongsi cara untuk mengawal servo menggunakan keypad. Applikasi ini boleh digunakan untuk membuka atau mengunci pintu rumah.
Bahan yang diperlukan
1. Arduino board
2. Servo
3. Breadboard
4. Jumper atau wire
5. Keypad 3x4 atau 4x4
Software yang diperlukan
1. Arduino IDE
Step 1 (wiring keypad) Bermula dari kiri >> pin 9,8,7,6,5,4,3
Step 2 (wiring Servo) Kuning >> pin 11 Merah >> pin 5v Hitam (Coklat) >> pin GND
Assalamualaikum wbt kepada pembaca blog saya yang saya hormati...
Bersyukur kepadaNya kerana hari ini masih diberi ruang untuk memberikan dan berkongsi lagi sedikit ilmu yang dipinjamkan kepada saya. Pada entri kali ini, saya ingin berkongsi cara untuk ON/OFF LED menggunakan bluetooth module Arduino yang dikawal menggunakan handphone Android anda.
Bahan yang diperlukan
1. Arduino board
2. Bluetooth module (HC-06 for arduino)
3. Breadboard
4. Jumper atau wire
5. Handphone Android
Software yang diperlukan
1. Arduino IDE
2. AMR Voice Arduino (untuk android phone) Boleh download di sini
1. VCC>wire merah 2. GND>wire hitam 3. TXD> wire kuning 4. RXD>wire kelabu
Step 2 (wiring LED)
LED 1 To Pin 2
LED 2 To Pin 3
LED 3 To Pin 4
LED 4 To Pin 5
LED 5 To Pin 6
1. VCC>wire merah 2. GND>wire hitam 3. TXD> wire kuning 4. RXD>wire kelabu
Step 3 (ON/OFF LED guna Android) 1. Buka AMR Voice Arduino 2. "Connect Robot" Password untuk bluetooth module HC-06 (1234) 3. Tunggu sehingga "Connected to BT-Module (HC-06)" 4. Tap on the mic icon dan cakapkan command anda (arahan)
AMR Voice interface
Coding Arduino
//Voice Activated Arduino (Bluetooth + Android)//Feel free to modify it but remember to give creditString voice;
int
led1 = 2, //Connect LED 1 To Pin #2
led2 = 3, //Connect LED 2 To Pin #3
led3 = 4, //Connect LED 3 To Pin #4
led4 = 5, //Connect LED 4 To Pin #5
led5 = 6; //Connect LED 5 To Pin #6//--------------------------Call A Function-------------------------------// void allon(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
}
void alloff(){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
}
//-----------------------------------------------------------------------// voidsetup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
//-----------------------------------------------------------------------// voidloop() {
while (Serial.available()){ //Check if there is an available byte to readdelay(10); //Delay added to make thing stablechar c = Serial.read(); //Conduct a serial readif (c == '#') {break;} //Exit the loop when the # is detected after the word
voice += c; //Shorthand for voice = voice + c
}
if (voice.length() > 0) {
Serial.println(voice);
//-----------------------------------------------------------------------// //----------Control Multiple Pins/ LEDs----------// if(voice == "*all on") {allon();} //Turn Off All Pins (Call Function)elseif(voice == "*all off"){alloff();} //Turn On All Pins (Call Function)//----------Turn On One-By-One----------//elseif(voice == "*tv on") {digitalWrite(led1, HIGH);}
elseif(voice == "*fan on") {digitalWrite(led2, HIGH);}
elseif(voice == "*computer on") {digitalWrite(led3, HIGH);}
elseif(voice == "*bedroom lights on") {digitalWrite(led4, HIGH);}
elseif(voice == "*bathroom lights on") {digitalWrite(led5, HIGH);}
//----------Turn Off One-By-One----------//elseif(voice == "*tv off") {digitalWrite(led1, LOW);}
elseif(voice == "*fan off") {digitalWrite(led2, LOW);}
elseif(voice == "*computer off") {digitalWrite(led3, LOW);}
elseif(voice == "*bedroom lights off") {digitalWrite(led4, LOW);}
elseif(voice == "*bathroom lights off") {digitalWrite(led5, LOW);}
//-----------------------------------------------------------------------//
voice="";}} //Reset the variable after initiating
Video
* respon LED saya lambat sedikit kerana saya menggunakan handphone Android lama yang agak lambat sedikit.
Alhamdulillah, masih diberi kesempatan untuk bernafas
Pada entri kali ini saya ingin nebyambung entri sebelum ini bagaimana untuk menggunakan ultrasonic sensor pada Arduino anda. Berbeza sedikit pada projek kali ini, output daripada ultrasonic sensor kita akan dikeluarkan pada screen PC anda dalam bentuk bacaan. Pada entri sebslum ini, output ultrasonic sensor diterjemahkan dalam bentuk gelombang warna pada screen PC anda. Mari kita mulakan.
Bahan yang diperlukan
1. Arduino board
2. HC-Sr04 ultrasonic sensor
3. Breadboard
4. Jumper atau wire
Software yang diperlukan
1. Arduino IDE
Cara untuk keluarkan reading pada PC buka Arduino IDE > Tools > serial monitor
Wiring
* VCC connection of the sensor attached to +5V * GND connection of the sensor attached to ground
* TRIG connection of the sensor attached to digital pin 2
* ECHO connection of the sensor attached to digital pin 4
Lakaran daripada fritzing
nilai bacaan sensor di screen PC
Coding Arduino
/* HC-SR04 Sensorhttps://www.dealextreme.com/p/hc-sr04-ultrasonic-sensor-distance-measuring-module-133696This sketch reads a HC-SR04 ultrasonic rangefinder and returns thedistance to the closest object in range. To do this, it sends a pulseto the sensor to initiate a reading, then listens for a pulseto return. The length of the returning pulse is proportional tothe distance of the object from the sensor.The circuit:* VCC connection of the sensor attached to +5V* GND connection of the sensor attached to ground* TRIG connection of the sensor attached to digital pin 2* ECHO connection of the sensor attached to digital pin 4Original code for Ping))) example was created by David A. MellisAdapted for HC-SR04 by Tautvidas SipaviciusThis example code is in the public domain.*/constint trigPin = 2;
constint echoPin = 4;
voidsetup() {
// initialize serial communication:Serial.begin(9600);
}
voidloop()
{
// establish variables for duration of the ping,// and the distance result in inches and centimeters:long duration, inches, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose// duration is the time (in microseconds) from the sending// of the ping to the reception of its echo off of an object.pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per// second). This gives the distance travelled by the ping, outbound// and return, so we divide by 2 to get the distance of the obstacle.// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdfreturn microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.// The ping travels out and back, so to find the distance of the// object we take half of the distance travelled.return microseconds / 29 / 2;
}
Pada entri kali ini, saya akan menunjukkan bagaimana untuk menggunakan Ultrasonic sensor (HC-SR04) pada Arduino board. HC-SR04 ini pada umumnya banyak digunakan pada projek automasi dan robotik kerana ianya mudah digunakan. HC-SR04 merupakan proximity/distance sensor atau sensor jarak untuk menentukan jarak sesuatu objek. Salah satu contoh yang biasa digunakan adalah sensor undur kereta atau lebih dikenali dengan reverse sensor.
Pada projek kali ini, saya ingin menunjukkan bagaimana untuk menunjukkan output HC-SR04 pada screen monitor PC anda. Hasinya adalah seperti ini:
Merah menandakan jarah objek jauh manakala
biru menunjukkan jarak objek yg dekat
Bahan yang diperlukan
1. Arduino board
2. HC-Sr04 ultrasonic sensor
3. Breadboard
4. Jumper atau wire
Software yang diperlukan
1. Arduino IDE
2. Processing arduino software. Anda boleh dapatkan di sini
Siap penyambungan
Lukisan penyambungan
Video hasil kerja saya
Coding Arduino
/* HC-SR04 Ping distance sensor: VCC to arduino 5v GND to arduino GND Echo to Arduino pin 7 Trig to Arduino pin 8 */
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LEDint maximumRange = 200; // Maximum range neededint minimumRange = 0; // Minimum range neededlong duration, distance; // Duration used to calculate distancevoidsetup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}
voidloop() {
/* The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it. */digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
if (distance >= maximumRange || distance <= minimumRange){
/* Send a negative number to computer and Turn LED ON to indicate "out of range" */Serial.println("-1");
digitalWrite(LEDPin, HIGH);
}
else {
/* Send the distance to the computer using Serial protocol, and turn LED OFF to indicate successful reading. */Serial.println(distance);
digitalWrite(LEDPin, LOW);
}
//Delay 50ms before next reading.delay(50);
}
Coding Processing software
import processing.serial.*;
int numOfShapes = 60; // Number of squares to display on screen int shapeSpeed = 2; // Speed at which the shapes move to new position// 2 = Fastest, Larger numbers are slower//Global Variables
Square[] mySquares = new Square[numOfShapes];
int shapeSize, distance;
String comPortString;
Serial myPort;
/* -----------------------Setup ---------------------------*/voidsetup(){
size(displayWidth,displayHeight); //Use entire screen size.smooth(); // draws all shapes with smooth edges./* Calculate the size of the squares and initialise the Squares array */
shapeSize = (width/numOfShapes);
for(int i = 0; i<numOfShapes; i++){
mySquares[i]=new Square(int(shapeSize*i),height-40);
}
/*Open the serial port for communication with the Arduino Make sure the COM port is correct - I am using COM port 8 */
myPort = new Serial(this, "COM3", 9600);
myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
}
/* ------------------------Draw -----------------------------*/voiddraw(){
background(0); //Make the background BLACK
delay(50); //Delay used to refresh screen
drawSquares(); //Draw the pattern of squares
}
/* ---------------------serialEvent ---------------------------*/void serialEvent(Serial cPort){
comPortString = cPort.readStringUntil('\n');
if(comPortString != null) {
comPortString=trim(comPortString);
/* Use the distance received by the Arduino to modify the y position of the first square (others will follow). Should match the code settings on the Arduino. In this case 200 is the maximum distance expected. The distance is then mapped to a value between 1 and the height of your screen */
distance = int(map(Integer.parseInt(comPortString),1,200,1,height));
if(distance<0){
/*If computer receives a negative number (-1), then the sensor is reporting an "out of range" error. Convert all of these to a distance of 0. */
distance = 0;
}
}
}
/* ---------------------drawSquares ---------------------------*/void drawSquares(){
int oldY, newY, targetY, redVal, blueVal;
/* Set the Y position of the 1st square based on sensor value received */
mySquares[0].setY((height-shapeSize)-distance);
/* Update the position and colour of each of the squares */for(int i = numOfShapes-1; i>0; i--){
/* Use the previous square's position as a target */
targetY=mySquares[i-1].getY();
oldY=mySquares[i].getY();
if(abs(oldY-targetY)<2){
newY=targetY; //This helps to line them up
}else{
//calculate the new position of the square
newY=oldY-((oldY-targetY)/shapeSpeed);
}
//Set the new position of the square
mySquares[i].setY(newY);
/*Calculate the colour of the square based on its position on the screen */
blueVal = int(map(newY,0,height,0,255));
redVal = 255-blueVal;
fill(redVal,0,blueVal);
/* Draw the square on the screen */rect(mySquares[i].getX(), mySquares[i].getY(),shapeSize,shapeSize);
}
}
/* ---------------------sketchFullScreen---------------------------*/// This puts processing into Full Screen Modeboolean sketchFullScreen() {
returntrue;
}
/* ---------------------CLASS: Square ---------------------------*/class Square{
int xPosition, yPosition;
Square(int xPos, int yPos){
xPosition = xPos;
yPosition = yPos;
}
int getX(){
return xPosition;
}
int getY(){
return yPosition;
}
void setY(int yPos){
yPosition = yPos;
}
}