ข้ามไปที่เนื้อหาหลัก

ส่งงานครั้งที่ 15

Arduino Solar Tracker

อุปกรณ์
  • Servo Motor (sg90)
  • Solar panel
  • Arduino Uno
  • LDR’s X 2 (Light Dependent Resistor)
  • 10K resistors X 2
  • Battery (6 to 12V)
Diagram


Code
#include <Servo.h>      //ประกาศเมื่อมีการใช้Servo
Servo sg90;             //ตั้งค่าServoด้วยตัวแปรsg90
int initial_position = 90;   //ประกาศตัวแปรไว้ที่ค่า 90
int LDR1 = A0;          //ขาที่LDRต่อไว้
int LDR2 = A1;          //ขาที่LDR2ต่อไว้
int error = 5;          //ตั้งค่าเริ่มต้นของ error ที่ 5
int servopin=9;
void setup()
{ 
  sg90.attach(servopin);  // ให้ servo ที่ขา 9
  pinMode(LDR1, INPUT);   //ให้ขาที่ต่อกับLDRเป็นInput
  pinMode(LDR2, INPUT);
  sg90.write(initial_position);   //ขยับServoไว้ที่90องศา
  delay(2000);            // กำหนดdelay2วินาที
}

void loop()
{
  int R1 = analogRead(LDR1); // อ่านค่า LDR 1
  int R2 = analogRead(LDR2); // อ่านค่า LDR 2
  int diff1= abs(R1 - R2);   // คำนวณค่าการเปลี่ยนแปลงของ LDR's
  int diff2= abs(R2 - R1);

  if((diff1 <= error) || (diff2 <= error)) {
    //ถ้าค่าการเปลี่ยนแปลงน้อยกว่า error ไม่ต้องทำอะไร
  } else {  
    if(R1 > R2)
    {
      initial_position = --initial_position;  //ขยับServoไปที่0องศา
    }
    if(R1 < R2)
    {
      initial_position = ++initial_position; //ขยับServoไปที่180องศา
    }
  }
  sg90.write(initial_position); // เปลี่ยนค่าของServo
  delay(100);
}

Credit By : https://circuitdigest.com/microcontroller-projects/arduino-solar-panel-tracker

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

ส่งงานครั้งที่ 16

Smoke Detector Using MQ2 อุปกรณ์ Arduino UNO Smoke Detector Arduino Shield (Self Designed) Power Supply Smoke Sensor (MQ2) Resistors (10K and 1K) Buzzer 16x2 LCD 10k POT LED LM358 Burg strips Diagram Code #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define buzzer 9 #define sensor A0   #define load_Res 10   #define air_factor 9.83                                                   float SmokeCurve[3] ={2.3,0.53,-0.44};    // (x, y, slope) x,y พิกัดของจุดหนึ่งและความลาดชันระหว่างสองจุด                                                                                     ...

ส่งงานครั้งที่ 14

Earthquake Detector Alarm อุปกรณ์ Arduino UNO Accelerometer ADXL335 16x2 LCD Buzzer BC547 transistor 1k Resistors 10K POT LED Power Supply 9v/12v Berg sticks male/female Diagram Code #include<LiquidCrystal.h>      // ประกาศเมื่อใช้LCD LiquidCrystal lcd(9,8,7,6,5,4);   // กำหนดขาที่ต่อกับจอ #define buzzer 12 // ขาที่ต่อลำโพง #define led 13  //ขาที่ต่อกับLED #define x A0  // ขาOutputของแกนx #define y A1  // ขาOutputของแกนy #define z A2  // ขาOutputของแกนz /*variables*/ int xsample=0; int ysample=0; int zsample=0; long start; int buz=0; /*Macros*/ #define samples 50 #define maxVal 20   // ค่าที่เปลี่ยนแปลงทาง+มากที่สุด #define minVal -20    // ค่าที่เปลี่ยนแปลงทาง-มากที่สุด #define buzTime 5000  // เวลาที่ลำโพงดัง void setup() {   lcd.begin(16,2);  //ตำแหน่งlcd   Serial.begin(9600); // ค่าการรับส่งข้อมูลserial   delay(1000);   lcd.print("E...

ส่งงานครั้งที่ 10

Digital Thermometer อุปกรณ์ 8051 development board ADC0804 board 16*2 LCD display LM35 sensor Potentiometer Jumper wires Diagram Code /*this program is for displaying the temperature on 16*2 lcd display using 8051 microcontroller , LM35 sensor and ADC0804*/ #include<reg51.h> sbit rs=P2^7; //Register Select(RS) pin of 16*2 lcd sbit rw=P2^6; //Read/Write(RW) pin of 16*2 lcd sbit en=P2^5; //Enable(E) pin of 16*2 lcd sbit rd_adc=P3^0; //Read(RD) pin of ADC0804 sbit wr_adc=P3^1; //Write(WR) pin of ADC0804 sbit intr_adc=P3^2; //Interrupt(INTR) pin of ADC0804 void delay(unsigned int)  ; //function for creating delay void cmdwrt(unsigned char); //function for sending commands to 16*2 lcd display void datawrt(unsigned char); //function for sending data to 16*2 lcd display void convert_display(unsigned char); //function for converting ADC value to temperature and display it on 16*2 lcd display void main(void) //main fu...