reference page:https://howtomechatronics.com/arduino-projects/

 

Arduino Projects with DIY Instructions - HowToMechatronics

A collection of cool Arduino Projects. Each of the following DIY Arduino projects is covered with detailed step by step tutorial on how to do it yourself...

howtomechatronics.com

 

Processing 

Code scripts => radar simulations

Receive data from COM3 port


더보기

 

/*   Arduino Radar Project

*

*   Updated version. Fits any screen resolution!

*   Just change the values in the size() function,

*   with your screen resolution.

*      

 *  by Dejan Nedelkovski,

 *  www.HowToMechatronics.com

*  

 */

import processing.serial.*; // imports library for serial communication

import java.awt.event.KeyEvent; // imports library for reading the data from the serial port

import java.io.IOException;

Serial myPort; // defines Object Serial

// defubes variables

String angle="";

String distance="";

String data="";

String noObject;

float pixsDistance;

int iAngle, iDistance;

int index1=0;

int index2=0;

PFont orcFont;

void setup() {

  

 size (1920, 1080); // ***CHANGE THIS TO YOUR SCREEN RESOLUTION***

smooth();

myPort = new Serial(this,"COM3", 9600); // starts the serial communication

myPort.bufferUntil('.'); // reads the data from the serial port up to the character '.'. So actually it reads this: angle,distance.

orcFont = loadFont("OCRAExtended-30.vlw");

}

void draw() {

  

  fill(98,245,31);

  textFont(orcFont);

  // simulating motion blur and slow fade of the moving line

  noStroke();

  fill(0,4); 

  rect(0, 0, width, height-height*0.065);

  

  fill(98,245,31); // green color

  // calls the functions for drawing the radar

  drawRadar(); 

  drawLine();

  drawObject();

  drawText();

}

void serialEvent (Serial myPort) { // starts reading data from the Serial Port

  // reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".

  data = myPort.readStringUntil('.');

  data = data.substring(0,data.length()-1);

  

  index1 = data.indexOf(","); // find the character ',' and puts it into the variable "index1"

  angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port

  distance= data.substring(index1+1, data.length()); // read the data from position "index1" to the end of the data pr thats the value of the distance

  

  // converts the String variables into Integer

  iAngle = int(angle);

  iDistance = int(distance);

}

void drawRadar() {

  pushMatrix();

  translate(width/2,height-height*0.074); // moves the starting coordinats to new location

  noFill();

  strokeWeight(2);

  stroke(98,245,31);

  // draws the arc lines

  arc(0,0,(width-width*0.0625),(width-width*0.0625),PI,TWO_PI);

  arc(0,0,(width-width*0.27),(width-width*0.27),PI,TWO_PI);

  arc(0,0,(width-width*0.479),(width-width*0.479),PI,TWO_PI);

  arc(0,0,(width-width*0.687),(width-width*0.687),PI,TWO_PI);

  // draws the angle lines

  line(-width/2,0,width/2,0);

  line(0,0,(-width/2)*cos(radians(30)),(-width/2)*sin(radians(30)));

  line(0,0,(-width/2)*cos(radians(60)),(-width/2)*sin(radians(60)));

  line(0,0,(-width/2)*cos(radians(90)),(-width/2)*sin(radians(90)));

  line(0,0,(-width/2)*cos(radians(120)),(-width/2)*sin(radians(120)));

  line(0,0,(-width/2)*cos(radians(150)),(-width/2)*sin(radians(150)));

  line((-width/2)*cos(radians(30)),0,width/2,0);

  popMatrix();

}

void drawObject() {

  pushMatrix();

  translate(width/2,height-height*0.074); // moves the starting coordinats to new location

  strokeWeight(9);

  stroke(255,10,10); // red color

  pixsDistance = iDistance*((height-height*0.1666)*0.025); // covers the distance from the sensor from cm to pixels

  // limiting the range to 40 cms

  if(iDistance<40){

    // draws the object according to the angle and the distance

  line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),(width-width*0.505)*cos(radians(iAngle)),-(width-width*0.505)*sin(radians(iAngle)));

  }

  popMatrix();

}

void drawLine() {

  pushMatrix();

  strokeWeight(9);

  stroke(30,250,60);

  translate(width/2,height-height*0.074); // moves the starting coordinats to new location

  line(0,0,(height-height*0.12)*cos(radians(iAngle)),-(height-height*0.12)*sin(radians(iAngle))); // draws the line according to the angle

  popMatrix();

}

void drawText() { // draws the texts on the screen

  

  pushMatrix();

  if(iDistance>40) {

  noObject = "Out of Range";

  }

  else {

  noObject = "In Range";

  }

  fill(0,0,0);

  noStroke();

  rect(0, height-height*0.0648, width, height);

  fill(98,245,31);

  textSize(25);

  

  text("10cm",width-width*0.3854,height-height*0.0833);

  text("20cm",width-width*0.281,height-height*0.0833);

  text("30cm",width-width*0.177,height-height*0.0833);

  text("40cm",width-width*0.0729,height-height*0.0833);

  textSize(40);

  text("Object: " + noObject, width-width*0.875, height-height*0.0277);

  text("Angle: " + iAngle +" °", width-width*0.48, height-height*0.0277);

  text("Distance: ", width-width*0.26, height-height*0.0277);

  if(iDistance<40) {

  text("        " + iDistance +" cm", width-width*0.225, height-height*0.0277);

  }

  textSize(25);

  fill(98,245,60);

  translate((width-width*0.4994)+width/2*cos(radians(30)),(height-height*0.0907)-width/2*sin(radians(30)));

  rotate(-radians(-60));

  text("30°",0,0);

  resetMatrix();

  translate((width-width*0.503)+width/2*cos(radians(60)),(height-height*0.0888)-width/2*sin(radians(60)));

  rotate(-radians(-30));

  text("60°",0,0);

  resetMatrix();

  translate((width-width*0.507)+width/2*cos(radians(90)),(height-height*0.0833)-width/2*sin(radians(90)));

  rotate(radians(0));

  text("90°",0,0);

  resetMatrix();

  translate(width-width*0.513+width/2*cos(radians(120)),(height-height*0.07129)-width/2*sin(radians(120)));

  rotate(radians(-30));

  text("120°",0,0);

  resetMatrix();

  translate((width-width*0.5104)+width/2*cos(radians(150)),(height-height*0.0574)-width/2*sin(radians(150)));

  rotate(radians(-60));

  text("150°",0,0);

  popMatrix(); 

}

 

 

Arduino sketch code scripts

:::

“Ulreasonic sensor” and “Servo motor” controls

Send data to COM3 port


 

더보기

// Includes the Servo library

#include <Servo.h>

// Defines Tirg and Echo pins of the Ultrasonic Sensor

const int trigPin = 10;

const int echoPin = 11;

// Variables for the duration and the distance

long duration;

int distance;

Servo myServo; // Creates a servo object for controlling the servo motor

void setup() {

  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

  pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  Serial.begin(9600);

  myServo.attach(12); // Defines on which pin is the servo motor attached

}

void loop() {

  // rotates the servo motor from 15 to 165 degrees

  for(int i=15;i<=165;i++){ 

  myServo.write(i);

  delay(30);

  distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree

  

  Serial.print(i); // Sends the current degree into the Serial Port

  Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing

  Serial.print(distance); // Sends the distance value into the Serial Port

  Serial.print("."); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing

  }

  // Repeats the previous lines from 165 to 15 degrees

  for(int i=165;i>15;i--){ 

  myServo.write(i);

  delay(30);

  distance = calculateDistance();

  Serial.print(i);

  Serial.print(",");

  Serial.print(distance);

  Serial.print(".");

  }

}

// Function for calculating the distance measured by the Ultrasonic sensor

int calculateDistance(){

  

  digitalWrite(trigPin, LOW);

  delayMicroseconds(2);

  // Sets the trigPin on HIGH state for 10 micro seconds

  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds

  distance= duration*0.034/2;

  return distance;

 

}

'IOT > 아듀이노' 카테고리의 다른 글

아듀이노 dc모터제어 4 wheel  (0) 2019.09.07
back light  (0) 2019.03.02
크리스마스 트리 만들기(led strip (네오픽셀))  (0) 2018.12.23
미세먼지 센서(GP2Y1010AU0F) 로 측정하기  (3) 2018.06.11
DIY-공기청정기  (0) 2018.06.01

아두이노 모터 드라이버 쉴드 L293D
가격대비 제어되는 모터 수가 많아 처음 모터제어하는 사람이 사용하기 좋음

장비는 메카솔루션에서 사고, 

사용방법은 에듀이노 내용을 참고함
참고) http://eduino.kr/product/detail.html?product_no=126&cate_no=25&display_group=1

위 url 샘플 예제를 참고해서
프로그래밍함)

#include <SoftwareSerial.h> 
#include <AFMotor.h>       // L293D 모터 드라이브 라이브러리
 
AF_DCMotor motor_1(1);     // 모터 1 객체         
AF_DCMotor motor_2(2);     // 모터 2 객체 
AF_DCMotor motor_3(3);     // 모터 3 객체
AF_DCMotor motor_4(4);     // 모터 4 객체
 
void setup() {
  motor_1.setSpeed(150);    // 모터 1 속도 설정          
  motor_1.run(RELEASE);     // 모터 1 돌리지 않는 상태
  motor_2.setSpeed(150);    // 모터 2 속도 설정          
  motor_2.run(RELEASE);     // 모터 2 돌리지 않는 상태
  motor_3.setSpeed(150);    // 모터 3 속도 설정          
  motor_3.run(RELEASE);     // 모터 3 돌리지 않는 상태
  motor_4.setSpeed(150);    // 모터 4 속도 설정          
  motor_4.run(RELEASE);     // 모터 4 돌리지 않는 상태
}
 
void loop() {
 // 모터 1
 motor_1.run(FORWARD);    // 정방향으로 회전
 motor_2.run(FORWARD);    // 정방향으로 회전
 motor_3.run(FORWARD);    // 정방향으로 회전
 motor_4.run(FORWARD);    // 정방향으로 회전
 delay(3000);
 
 motor_1.run(RELEASE);    // 쉬기
 motor_2.run(RELEASE);    // 쉬기
 motor_3.run(RELEASE);    // 쉬기
 motor_4.run(RELEASE);    // 쉬기
  delay(1000);
  motor_1.run(BACKWARD);   // 역방향 회전
 motor_4.run(BACKWARD);   // 역방향 회전
  delay(3000);
  motor_2.run(BACKWARD);   // 역방향 회전
 motor_3.run(BACKWARD);   // 역방향 회전
 delay(3000);
 motor_1.run(BACKWARD);   // 역방향 회전
 motor_2.run(BACKWARD);   // 역방향 회전
 motor_3.run(BACKWARD);   // 역방향 회전
 motor_4.run(BACKWARD);   // 역방향 회전
 delay(3000);
 motor_1.run(RELEASE);    // 쉬기
 motor_2.run(RELEASE);    // 쉬기
 motor_3.run(RELEASE);    // 쉬기
 motor_4.run(RELEASE);    // 쉬기
  delay(1000);
 motor_1.run(FORWARD);   // 정방향 회전
 motor_4.run(FORWARD);   // 정방향 회전
  delay(3000);
 motor_2.run(FORWARD);   // 정방향 회전
 motor_3.run(FORWARD);   // 정방향 회전
 delay(3000);
 
}

차후, 초음파센서와 블루투스 or wifi로 rc카 조정가능하길

 

 

 

 

'IOT > 아듀이노' 카테고리의 다른 글

Arduino with Processing  (0) 2020.08.31
back light  (0) 2019.03.02
크리스마스 트리 만들기(led strip (네오픽셀))  (0) 2018.12.23
미세먼지 센서(GP2Y1010AU0F) 로 측정하기  (3) 2018.06.11
DIY-공기청정기  (0) 2018.06.01

아이 그림 그리기 위한 백라이트

Led strip.
아두이노.
샤오미 보조 베터리.
박스.
0.5mm 두께 아크릴 30cm*40cm.

led strip(네오픽셀)로 크리스마스 트리 만들기

준비물 : 아두이노, Adafruit Neopixel, 종이, 납땜기, 전선



아두이노에서 "Adafruit Neopixel" 라이브러리 다운로드 하기 =>  스케치 > 라이브러리 포함하기 > 라이브러리 관리




생각했던 것 보다 예쁨(*________________*)


'IOT > 아듀이노' 카테고리의 다른 글

아듀이노 dc모터제어 4 wheel  (0) 2019.09.07
back light  (0) 2019.03.02
미세먼지 센서(GP2Y1010AU0F) 로 측정하기  (3) 2018.06.11
DIY-공기청정기  (0) 2018.06.01
[DIY : 센서등]인체감지센서,LED로 센서등 만들기  (0) 2018.03.31

dustsensor.ino

dustsensorv2.ino



첨부된 2 가지  케이스로 코딩됨.

미세먼지 측정센서로 측정된 미세먼지 농도를 
16x2 LCD 에 표현하기.


아두이노 코딩도 계속하다 보니 자연스럽게 되는것 같다. 전자회로도 또한 친숙해지는것 같고.
연습이 완벽하게 만든다고 했나? 생각보다 쉽게 만들어짐에 놀라웠다.

Practice makes perfect, thanks.


#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int Vo = A0;
int V_LED = 2;

float Vo_value = 0;
float Voltage = 0;
float dustDensity = 0;
float dustCleanVoltage = 0.44;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;

void setup(){
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("dust");
Serial.begin(9600);

/*digital output:*/
pinMode(V_LED, OUTPUT);

/*analog input:*/
pinMode(Vo, INPUT);
}

/** references :
* http://blog.naver.com/PostView.nhn?blogId=darknisia&logNo=221222455928
* http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
* */
// 미세먼지 센서(GP2Y1010AU0F)
// : 적외선 발광 다이오드(IRED)와 포토다이오드가 대각선으로 배치되어 공기 중 먼지의 반사광을 감지
void loop(){
digitalWrite(V_LED,LOW); //ired 'on'
delayMicroseconds(samplingTime);
Vo_value = analogRead(Vo); //read the dust value
delayMicroseconds(deltaTime);// pulse width 0.32 - 0.28 = 0.04 msec
//0.32 msec의 펄스폭을 유지하기 위해 필요한 코드입니다

digitalWrite(V_LED,HIGH); //ired 'off'
delayMicroseconds(sleepTime);


/*
이 센서의 출력전압(Vo)는 먼지가 없을 때의 출력전압(Voc)과 먼지 농도(ΔV)에 비례하여 출력됩니다.
다시 표현하면 ΔV = Vo – Voc
미세먼지 농도[µg/m³] = (Vo – Voc) / 0.005
*/
Voltage = Vo_value * (5.0 / 1024.0);

dustDensity = (Voltage - dustCleanVoltage)/0.005;

Serial.print(" Raw Signal Value (0-1023):");
Serial.print(Vo_value);
Serial.print(" | Volatage:");
Serial.print(Voltage);
Serial.print(" | Dust Density:");
Serial.print(dustDensity);
Serial.print("[ug/m3]");
if(dustDensity<31){
Serial.println(" => [Great(~30)]");
} else if(dustDensity>30 && dustDensity<81){
Serial.println(" => [Good(31~80)]");
} else if(dustDensity>81 && dustDensity<151){
Serial.println(" => [Bad(81~150)]");
} else{
Serial.println(" => [Too Bad(151~)]");
}


// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print(dustDensity);
lcd.setCursor(0, 1);
if(dustDensity<31){
lcd.print(": Great(~30)");
} else if(dustDensity>30 && dustDensity<81){
lcd.print(": Good(31~80)");
} else if(dustDensity>81 && dustDensity<151){
lcd.print(": Bad(81~150)");
} else{
lcd.print(": Too Bad(151~)");
}
delay(5000);
}


 

DIY-공기청정기

저렴하게 만들수 있다는 장점이 있지만 뭔가 허접. 저처럼 3D프린트기가 없다면.

 

장비 : 자동차 에어컨필터(6천원~15천원), 테이프(1천원), 쿨러팬(죽어버린데스크탑의 팬 재사용), 샤오미보조베터리, 아두이노

 

여기서 아두이노를 사용하는건 계속적으로 전력을 공급하기 위해서 그냥 사용할뿐.

이것 사용안하면 10초후에 보조베터리에서 전력이 끊어짐.

추가로 미세먼지 센서나 led로 측정값에 대한 이벤트를 주는것도 가능하겠음

미세먼지 센서로 측정하게되면 업데이트하는걸로.


데스크탑에서 뺀 쿨러 4pin이다.

노란색선(+), 그 옆 검정색선(-)



그럭저럭^^ 그런데 바람이 좀 많이 약하다.  DIY는 자기 만족이니까. 난 만족한다.

이것 선풍기로 만드는것도 좋겠는데^^.


인체감지센서,LED로 센서등 만들기

 

LED를 멀티로 5개까지 on/off처리함

불 밝기를 위해서. 현관문 앞에 달고 싶은데 선이 지저분하다. 사진처럼

선 처리를 좀 깔끔하게 할 방법은 없을까?

 

 

아두이노 인체감지센서와 LED제어 프로그램 소스

소스보다 LED를 멀티로 on 시켜보자 하여 아래 led09~led12까지 추가함.

 

HsensorLed.ino

	
int led09 = 9;       // ledPin 출력을 09번
int led10 = 10;      // ledPin 출력을 10번
int led11 = 11;      // ledPin 출력을 11번
int led12 = 12;      // ledPin 출력을 12번
int led13 = 13;      // ledPin 출력을 13번
int sensorInput = 2;     // PIR센서 입력을 inputPin 2번에 연결
int pirState = LOW;   // 초기값은 PIR 센서값이 없다고 가정
int val = 0;          // 핀의 상태를 판독하기 위한 변수를 선언
int itime = 0;

void setup() {

  pinMode(led09, OUTPUT);     //led 포트를 출력모드로
  pinMode(led10, OUTPUT);     //led 포트를 출력모드로
  pinMode(led11, OUTPUT);     //led 포트를 출력모드로
  pinMode(led12, OUTPUT);     //led 포트를 출력모드로
  pinMode(led13, OUTPUT);     //led 포트를 출력모드로
  pinMode(sensorInput, INPUT);    //센서입력 포트를 입력모드로
  Serial.begin(9600);         // 9600속도로 시리얼 통신 시작 
}


void loop(){
  val = digitalRead(sensorInput);   

  if (val == HIGH)
  {            
      digitalWrite(led09, HIGH);   
      digitalWrite(led10, HIGH);   
      digitalWrite(led11, HIGH);   
      digitalWrite(led12, HIGH);   
      digitalWrite(led13, HIGH);   
      
      if(pirState == LOW){
         pirState = HIGH;
         itime ++;
         
      Serial.println("Somebody detected~! : ");
      delay(10000);           // 10초 지연
      } 
  }
  else {
      if(pirState == HIGH){
        digitalWrite(led09, LOW);        
        digitalWrite(led10, LOW);        
        digitalWrite(led11, LOW);                        
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);

        pirState = LOW;      
        Serial.println("Nobody detected~!");
        }
    }
}


회도로는 검색엔진에서 “아두이노 인체감지센서 led” 이렇게 검색하면 여러blog내용이 나옴.

회로도 작성툴, “fritzing”가 있는데 다음엔 이걸로 작성해보는걸로..




고장난 센서등의 안쪽 부속품들을 모두 들어내고 그 안에 회로판LED를 넣어 아래처럼 만듦




=================

선정리로 고민하다. 기존 무선센서의 led와 센서를 이용하고 건전지 전력을 집전기로 바꾸기만 해서 간단해 해봤음

전력을 use용 얇은 선으로 대체함

use는 [ 5V(+) | Data(+) | Data(-) | GND ] 4개의 선으로 되어있어 여기서 5V(+)/GND를 사용해서 연결 납땜하면 된다.



 






'IOT > 아듀이노' 카테고리의 다른 글

아듀이노 dc모터제어 4 wheel  (0) 2019.09.07
back light  (0) 2019.03.02
크리스마스 트리 만들기(led strip (네오픽셀))  (0) 2018.12.23
미세먼지 센서(GP2Y1010AU0F) 로 측정하기  (3) 2018.06.11
DIY-공기청정기  (0) 2018.06.01

+ Recent posts